k8s的pod的hosts写法hostAliases

k8s的pod的hosts写法hostAliases

1 示例

      hostAliases:
        - hostnames:
            - "rm-1231.mysql.com"
          ip: "122.27.6.2"

2 实际添加位置

cat > ${docker_name}.yaml << EOF
apiVersion: apps/v1
kind: Deployment                #控制器
metadata:
  name: ${123_name}
  labels:
  namespace: ${k8s_123}  #空间名
spec:
  replicas: 1                   #启动副本数
  selector:                     #设置标签
    matchLabels:
      app: ${123}         
  template:
    metadata:
      labels:
        app: ${123}        #这个标签需要selector定义的标签一个,划分在同一个组
    spec:
      containers:
      - name: ${123}
        image: ${docker_repository}
        imagePullPolicy: Always #拉取镜像(选择方式——直接使用本地拥有的镜像)
        env:
        - name: TZ
          value: "Asia/Shanghai"
        ports:
        - containerPort: ${app_port}  #容器开放的监听端口
          protocol: TCP
        resources: {}
      hostAliases:
        - hostnames:
            - "rm-121.mysql.com"
          ip: "122.27.6.2"
      imagePullSecrets:
      - name: ${6666}     
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 30