阿里云k8s 亲和性调度【指定服务器部署】

1.depoly.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    deployment.kubernetes.io/revision: '3'
  creationTimestamp: '2020-06-11T08:55:28Z'
  generation: 3
  labels:
    app: test-nginx
  name: test-nginx
  namespace: beta-es
  resourceVersion: '11865675'
  selfLink: /apis/apps/v1/namespaces/beta-es/deployments/test-nginx
  uid: c9a00fe6-df53-4532-b0a5-748b750bbf03
spec:
  progressDeadlineSeconds: 600
  replicas: 10
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      app: test-nginx
  strategy:
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: test-nginx
    spec:
      affinity:
        nodeAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
            - preference:
                matchExpressions:
                  - key: env-beta
                    operator: In
                    values:
                      - beta
              weight: 80
            - preference:
                matchExpressions:
                  - key: env-dev
                    operator: In
                    values:
                      - dev
              weight: 20
      containers:
        - env:
            - name: PKG_RELEASE
              value: 1~buster
          image: 'registry-vpc.cn-beijing.aliyuncs.com/wx-k8s/nginx:v4'
          imagePullPolicy: IfNotPresent
          name: test-nginx
          ports:
            - containerPort: 80
              name: http
              protocol: TCP
          resources:
            limits:
              cpu: 100m
              memory: 128Mi
            requests:
              cpu: 1m
              memory: 128Mi
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
          volumeMounts:
            - mountPath: /etc/localtime
              name: volume-localtime
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 30
      volumes:
        - hostPath:
            path: /etc/localtime
            type: ''
          name: volume-localtime
status:
  availableReplicas: 10
  conditions:
    - lastTransitionTime: '2020-06-11T08:55:36Z'
      lastUpdateTime: '2020-06-11T08:55:36Z'
      message: Deployment has minimum availability.
      reason: MinimumReplicasAvailable
      status: 'True'
      type: Available
    - lastTransitionTime: '2020-06-11T08:55:28Z'
      lastUpdateTime: '2020-06-11T09:02:08Z'
      message: ReplicaSet "test-nginx-5dd7848887" has successfully progressed.
      reason: NewReplicaSetAvailable
      status: 'True'
      type: Progressing
  observedGeneration: 3
  readyReplicas: 10
  replicas: 10
  updatedReplicas: 10

2.详解

deploy.yaml文件中绿色部分代码含义:

有80%的权限 将 服务部署到
k8s-node服务器标签含kye为env-beta value值为beta的节点

当服务器挂掉的时候
走有20%的权限 将 服务部署到
k8s-node服务器标签含key为env-dev value值为dev的节点

服务器恢复时,重新部署服务时会再次部署到含有key为enc-beta value值为beta的k8s-node服务器

猜你喜欢

转载自www.cnblogs.com/faithH/p/13398697.html