pod亲和性(Affinity)清单

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-deployment
  namespace: test
spec:
  replicas: 1
  selector:
    matchLabels:
      environment: stg
  template:
    metadata:
      labels:
        environment: stg
    spec:
      containers:
      - name: nginx-container
        image: nginx:latest
        imagePullPolicy: IfNotPresent
        ports:
        - name: nginx-port
          containerPort: 80
          protocol: TCP
        lifecycle:
          postStart:
            exec:
              command: ["/bin/sh","-c","echo jiayouba!!!!!>/usr/share/nginx/html/index.html"]
      affinity:  #亲和性设置
        podAffinity: #设置pod亲和性
          requiredDuringSchedulingIgnoredDuringExecution: #硬限制
          - labelSelector:
              matchExpressions: # 匹配env的值在["xxx","yyy"]中的标签
              - key: podenv
                operator: In
                values: ["xxx","yyy"]
            topologyKey: kubernetes.io/hostname
apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-deployment
  namespace: test
spec:
  replicas: 1
  selector:
    matchLabels:
      environment: stg
  template:
    metadata:
      labels:
        environment: stg
    spec:
      containers:
      - name: nginx-container
        image: nginx:latest
        imagePullPolicy: IfNotPresent
        ports:
        - name: nginx-port
          containerPort: 80
          protocol: TCP
        lifecycle:
          postStart:
            exec:
              command: ["/bin/sh","-c","echo jiayouba!!!!!>/usr/share/nginx/html/index.html"]
      affinity:  #亲和性设置
        podAffinity: #设置pod亲和性
          preferredDuringSchedulingIgnoredDuringExecution: #软限制
          - weight: 1
            podAffinityTerm:
              labelSelector:
                matchExpressions: # 匹配env的值在["xxx","yyy"]中的标签
                - key: podenv
                  operator: In
                  values: ["xxx","yyy"]
              topologyKey: kubernetes.io/hostname
posted @ 2022-11-02 17:47  弩哥++  阅读(65)  评论(0编辑  收藏  举报