如何基於k8s快速搭建TeamCity(YAML分享)

前言

最近有朋友基於以前的博客《Docker最全教程之使用TeamCity來完成內部CI、CD流程(十七)》搭建TeamCity時出現了一些問題,因爲日常比較忙,沒有及時答覆,很是抱歉。node

這裏分享下基於本地k8s集羣(雲端k8s服務注意使用雲盤或者其餘存儲)搭建TeamCity的相關Yaml的配置文件,注意使用「kubectl apply -f <路徑>」命令執行。docker

 

服務端YAML定義

apiVersion: apps/v1beta1
kind: Deployment
metadata:
  labels:
    app: teamcity
  name: teamcity
spec:
  replicas: 1 #實例數量
  revisionHistoryLimit: 2 #保留的歷史記錄數,設置爲0將清理部署的全部歷史記錄,沒法回滾
  strategy:
    type: Recreate   #更新策略爲快速更新,即關閉全部實例從新建立
  template: #pod模板
    metadata:
      labels:
        app: teamcity
    spec:
      containers:
      - image: jetbrains/teamcity-server  #鏡像
        imagePullPolicy: Always  #拉取策略
        name: teamcity
        ports:  #端口列表
          - containerPort: 8111  #端口
        resources:
          limits:
            cpu: 1000m #最大CPU,這裏爲1核
            memory: 4184Mi  #最大內存
          requests:
            cpu: 97m  #預分配CPU,這裏爲0.097核
            memory: 2092Mi #預分配內存
        volumeMounts:
        - mountPath: /data/teamcity_server/datadir
          name: data-vol
        - mountPath: /opt/teamcity/logs
          name: log-vol
      nodeName: k8s-node1 #強制約束將Pod調度到指定的Node節點上
      restartPolicy: Always #重啓策略
      terminationGracePeriodSeconds: 30 #刪除須要時間
      volumes:
      - name: data-vol
        hostPath:   #使用主機目錄
          path: /var/teamcity
      - name: log-vol
        emptyDir: {} #臨時目錄
      hostNetwork: true
---
kind: Service
apiVersion: v1
metadata:
  name: teamcity-service
spec:
  type: NodePort #經過節點端口提供對外訪問
  ports:
    - port: 8111
      nodePort: 30001
  selector:
    app: teamcity
 

代理端YAML定義

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  labels:
    app: tc-agent
  name: tc-agent
spec:
  replicas: 3
  revisionHistoryLimit: 2 #保留的歷史記錄數,設置爲0將清理部署的全部歷史記錄,沒法回滾
  strategy:
    rollingUpdate: #滾動更新配置
      maxSurge: 1
      maxUnavailable: 0
    type: RollingUpdate #使用滾動更新策略
  template:
    metadata:
      labels:
        app: tc-agent
    spec:
      containers:
      - env:
        - name: AGENT_NAME #代理名稱
          value: Agent1
        - name: SERVER_URL #服務端訪問地址
          value: http://172.16.2.202:30001
        - name: DOCKER_IN_DOCKER
          value: start
        image: jetbrains/teamcity-agent
        imagePullPolicy: Always
        name: tc-agent
        resources: #資源限制
          limits:
            cpu: 4
            memory: 10024Mi
          requests: #代理構建時消耗比較大,儘可能分配多點資源
            cpu: 1
            memory: 4096Mi
        securityContext:
          privileged: true #特級權限
        volumeMounts:
        - mountPath: /data/teamcity_agent/conf
          name: vol
        - mountPath: /var/lib/docker
          name: vol
      dnsPolicy: ClusterFirst
      nodeName: k8s-node3 #強制約束將Pod調度到指定的Node節點上
      restartPolicy: Always
      terminationGracePeriodSeconds: 30
      volumes:
      - name: vol
        emptyDir: {} #臨時目錄
      hostNetwork: true
---
apiVersion: v1
kind: Service
metadata:
  labels:
    app: tc-agent
  name: tc-agent
spec:
  ports:
  - name: tcp-9090-9090
    nodePort: 0
    port: 9090
    protocol: TCP
    targetPort: 9090
  selector:
    app: tc-agent
  sessionAffinity: None
  type: ClusterIP
相關文章
相關標籤/搜索