高级属性设置

本文介绍如何给组件设置 Kubernetes 高级属性,例如: privileged、affinity 等等。

设置 Kubernetes 高级属性

在组件的其他设置中,可以设置 Kubernetes 的高级属性。所有属性添加时不需要在开头定义属性名称,直接添加属性即可。

  • nodeSelector 调度到指定的节点上
  • labels 标签
  • volumes 存储卷,示例如下

    1. - name: config-vol
    2. configMap:
    3. name: log-config
    4. items:
    5. - key: log_level
    6. path: log_level
  • volumeMounts 存储卷挂载,示例如下

    1. - mountPath: /data
    2. name: redis-data
  • affinity 亲和性,示例如下

    1. nodeAffinity:
    2. requiredDuringSchedulingIgnoredDuringExecution:
    3. nodeSelectorTerms:
    4. - matchExpressions:
    5. - key: kubernetes.io/hostname
    6. operator: NotIn
    7. values:
    8. - node3
  • tolerations 容忍度,示例如下:

    1. - key: "key1"
    2. operator: "Equal"
    3. value: "value1"
    4. effect: "NoSchedule"
    5. tolerationSeconds
  • 设置 serviceAccountName 服务账户

  • privileged 特权模式
  • env 环境变量,示例如下:

    1. - name: Version
    2. value: v5.8
    3. - name: NGINX_USERNAEM
    4. valueFrom:
    5. secretKeyRef:
    6. name: nginx-secret
    7. key: username
    8. optional: false
    9. - name: NGINX_PASSWORD
    10. valueFrom:
    11. secretKeyRef:
    12. name: nginx-secret
    13. key: password
    14. optional: false
    15. - name: MY_POD_IP
    16. valueFrom:
    17. fieldRef:
    18. fieldPath: status.podIP
  • shareProcessNamespace 共享进程命名空间

  • dnsPolicy DNS策略,示例如下:

    1. nameservers:
    2. - 1.2.3.4
    3. searches:
    4. - ns1.svc.cluster-domain.example
    5. - my.dns.search.suffix
    6. options:
    7. - name: ndots
    8. value: "2"
    9. - name: edns0
  • resources 资源限制,示例如下:

    1. requests:
    2. memory: "1024Mi"
    3. cpu: "500m"
    4. limits:
    5. memory: "512Mi"
    6. cpu: "100m"
  • hostIPC 控制容器是否可以共享主机的 IPC 名称空间

  • lifecycle 容器的生命周期事件设置处理函数,示例如下:

    1. postStart:
    2. exec:
    3. command: ["/bin/sh", "-c", "echo Hello from the postStart handler > /usr/share/message"]
    4. preStop:
    5. exec:
    6. command: ["/bin/sh","-c","nginx -s quit; while killall -0 nginx; do sleep 1; done"]
  • hostAliases 允许在容器的 /etc/hosts 文件中添加自定义的主机名和对应的IP地址。示例如下:

    1. - ip: "192.168.1.1"
    2. hostnames:
    3. - "alias1.example.com"
    4. - "alias2.example.com"
    5. - ip: "192.168.1.2"
    6. hostnames:
    7. - "alias3.example.com"