Skip to main content
Version: V6.0

高级属性设置

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

设置 Kubernetes 高级属性

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

  • nodeSelector 调度到指定的节点上
  • labels 标签
  • volumes 存储卷,示例如下
    - name: config-vol
    configMap:
    name: log-config
    items:
    - key: log_level
    path: log_level
  • volumeMounts 存储卷挂载,示例如下
    - mountPath: /data
    name: redis-data
  • affinity 亲和性,示例如下
    nodeAffinity:
    requiredDuringSchedulingIgnoredDuringExecution:
    nodeSelectorTerms:
    - matchExpressions:
    - key: kubernetes.io/hostname
    operator: NotIn
    values:
    - node3
  • tolerations 容忍度,示例如下:
    - key: "key1"
    operator: "Equal"
    value: "value1"
    effect: "NoSchedule"
    tolerationSeconds
  • 设置 serviceAccountName 服务账户
  • privileged 特权模式
  • env 环境变量,示例如下:
    - name: Version
    value: v5.8
    - name: NGINX_USERNAEM
    valueFrom:
    secretKeyRef:
    name: nginx-secret
    key: username
    optional: false
    - name: NGINX_PASSWORD
    valueFrom:
    secretKeyRef:
    name: nginx-secret
    key: password
    optional: false
    - name: MY_POD_IP
    valueFrom:
    fieldRef:
    fieldPath: status.podIP
  • shareProcessNamespace 共享进程命名空间
  • dnsPolicy DNS策略,示例如下:
    nameservers:
    - 1.2.3.4
    searches:
    - ns1.svc.cluster-domain.example
    - my.dns.search.suffix
    options:
    - name: ndots
    value: "2"
    - name: edns0
  • resources 资源限制,示例如下:
    requests:
    memory: "1024Mi"
    cpu: "500m"
    limits:
    memory: "512Mi"
    cpu: "100m"
  • hostIPC 控制容器是否可以共享主机的 IPC 名称空间
  • lifecycle 容器的生命周期事件设置处理函数,示例如下:
    postStart:
    exec:
    command: ["/bin/sh", "-c", "echo Hello from the postStart handler > /usr/share/message"]
    preStop:
    exec:
    command: ["/bin/sh","-c","nginx -s quit; while killall -0 nginx; do sleep 1; done"]
  • hostAliases 允许在容器的 /etc/hosts 文件中添加自定义的主机名和对应的IP地址。示例如下:
    - ip: "192.168.1.1"
    hostnames:
    - "alias1.example.com"
    - "alias2.example.com"
    - ip: "192.168.1.2"
    hostnames:
    - "alias3.example.com"