k8s deploy示例

demo1

  • 简单deploy配置介绍
  • http探活
  • 内存cpu配置

demo2

  • 环境变量
  • tcp探活
  • 镜像下载密钥
  • 目录挂载

demo3

  • 启动参数

附 demo1

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
 name: lykops-dpm
 labels:
   software: apache
   project: lykops
   app: lykops-dpm
   version: v1
spec:
 replicas: 3 #副本数量
 minReadySeconds: 30 #滚动升级时,容器准备就绪时间最少为30s
 strategy:
   type: recreate #升级方式
   #rollingUpdate:##由于replicas为3,则整个升级,pod个数在2-4个之间
   #  maxSurge: 3 #滚动升级时会先启动3个pod
   #  maxUnavailable: 1 #滚动升级时允许的最大Unavailable的pod个数
 selector:
   matchLabels:
     name: lykops-dpm
     software: apache
     project: lykops
     app: lykops-dpm
     version: v1
 template:
    metadata:
     labels:
       name: lykops-dpm
       software: apache
       project: lykops
       app: lykops-dpm
       version: v1
   spec:
     terminationGracePeriodSeconds: 60 ##k8s将会给应用发送SIGTERM信号,可以用来正确、优雅地关闭应用,默认为30秒
     containers:
     - name: lykops-dpm
       image: web:apache
       command: [ "sh", "/etc/run.sh" ]
       ports:
       - containerPort: 80
         name: http
         protocol: TCP
       resources: # 内存cpu配置
         requests:
           cpu: 0.05
           memory: 16Mi
         limits:
           cpu: 0.1
           memory: 32Mi
       livenessProbe:#livenessProbe是K8S认为该pod是存活的,不存在则需要kill掉,然后再新启动一个,以达到RS指定的个数。
         httpGet:
           path: /
           port: 80
           scheme: HTTP
         initialDelaySeconds: 30
         timeoutSeconds: 5
         successThreshold: 1
         failureThreshold: 5
       readinessProbe:#readinessProbe是K8S认为该pod是启动成功的,这里根据每个应用的特性,自己去判断,可以执行command,也可以进行httpGet。
         httpGet:
           path: /
           port: 80
           scheme: HTTP
         initialDelaySeconds: 30
         timeoutSeconds: 5
         successThreshold: 1
         failureThreshold: 5

附 demo2

apiVersion: extensions/v1beta1
 kind: Deployment
 metadata:
   annotations:
     cloud.tencent.com/volume-configmap-info: '[]'
     deployment.changecourse: Updating
     deployment.kubernetes.io/revision: "32"
   creationTimestamp: 2019-08-13T08:44:47Z
   generation: 32
   labels:
     qcloud-app: service-im-xxx
   name: service-im-xxx
   namespace: default
   resourceVersion: "5292210196"
   selfLink: /apis/extensions/v1beta1/namespaces/default/deployments/service-im-xxx
   uid: 9ae8619e-bda6-11e9-857a-faf23059c574
 spec:
   replicas: 2
   revisionHistoryLimit: 5
   selector:
     matchLabels:
       qcloud-app: service-im-xxx
   strategy:
     rollingUpdate:
       maxSurge: 1
       maxUnavailable: 0
     type: RollingUpdate
   template:
     metadata:
       annotations:
         cloud.tencent.com/volume-configmap-info: '[]'
       creationTimestamp: null
       labels:
         qcloud-app: service-im-xxx
         qcloud-redeploy-timestamp: "1591596532"
     spec:
       containers:
       - env: # 环境变量
         - name: USE_CONFIG_SERVER
           value: "false"
         - name: CONFIG_SERVER_ADDRESS
           value: config:8080
         - name: APPLICATION_NAME
           value: service-im-xxx
         - name: TAG
           value: prod
         image: ccr.ccs.tencentyun.com/xxx/service-im-xxx:1.0.107-test
         imagePullPolicy: Always
         livenessProbe:
           failureThreshold: 1
           initialDelaySeconds: 30
           periodSeconds: 30
           successThreshold: 1
           tcpSocket:
             port: 8080
           timeoutSeconds: 5
         name: service-im-xxx
         readinessProbe:# tcp探活
           failureThreshold: 1
           initialDelaySeconds: 30
           periodSeconds: 30
           successThreshold: 1
           tcpSocket:
             port: 8080
           timeoutSeconds: 5
         resources: # 内存cpu配置
           limits:
             cpu: "2"
             memory: 2Gi
           requests:
             cpu: 200m
             memory: 1Gi
         securityContext:
           privileged: false
         terminationMessagePath: /dev/termination-log
         terminationMessagePolicy: File
         volumeMounts: # mount
         - mountPath: /opt/pinpoint-agent/logs
           name: logs
       dnsPolicy: ClusterFirst
       imagePullSecrets: # 下载镜像密钥
       - name: hub-di5a3rd1
       - name: hub-dj6cxtgv
       - name: qcloudregistrykey
       - name: tencenthubkey
       restartPolicy: Always
       schedulerName: default-scheduler
       securityContext: {}
       terminationGracePeriodSeconds: 30
       volumes: # volume
       - hostPath:
           path: /data1/logs/service-im-xxx
         name: logs

demo 3

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  annotations:
    deployment.changecourse: Updating
    deployment.kubernetes.io/revision: "5"
  creationTimestamp: 2018-12-06T00:57:57Z
  generation: 7
  labels:
    qcloud-app: consul-client
  name: consul-client
  namespace: default
  resourceVersion: "2774907615"
  selfLink: /apis/extensions/v1beta1/namespaces/default/deployments/consul-client
  uid: f8c818f0-f8f1-11e8-8bf6-0a587f80369e
spec:
  minReadySeconds: 10
  replicas: 2
  revisionHistoryLimit: 5
  selector:
    matchLabels:
      qcloud-app: consul-client
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0
    type: RollingUpdate
  template:
    metadata:
      creationTimestamp: null
      labels:
        qcloud-app: consul-client
    spec:
      containers: # 启动参数
      - args:
        - agent
        - -ui
        - -client=0.0.0.0
        - -join=10.3.1.11
        env:
        - name: APPLICATION_NAME
          value: consul-client
        image: consul:1.3.0
        imagePullPolicy: Always
        name: consul-client
        resources:
          limits:
            cpu: 500m
            memory: 1Gi
          requests:
            cpu: 250m
            memory: 256Mi
        securityContext:
          privileged: false
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
      dnsPolicy: ClusterFirst
      imagePullSecrets:
      - name: hub-di5a3rd1
      - name: hub-dj6cxtgv
      - name: qcloudregistrykey
      - name: tencenthubkey
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 30