无法使用 hostAliases 更新 kubernetes 容器 /etc/hosts 文件

无法使用 hostAliases 更新 kubernetes 容器 /etc/hosts 文件

我正在尝试通过具有 Deployment 类型的 hostAliases 更新 k8s 容器 /etc/hosts 文件,但是这不会更新 /etc/hosts 但部署成功。

这是我正在使用的deployment.yml文件,感谢您的帮助

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: test-services
  namespace: dev
  labels:
    app: test-services
spec:
  replicas: 1
  revisionHistoryLimit: 0
  selector:
    matchLabels:
      app: test-services
  template:
    metadata:
      labels:
        app: test-services
    spec:   
      containers:
      - name: test-services
        image: test-services:latest
        imagePullPolicy: Always
        ports:
        - containerPort: 8080
        readinessProbe:
          httpGet:
            path: /health
            port: 8080
          initialDelaySeconds: 30
          periodSeconds: 5
        livenessProbe:
          httpGet:
            path: /health
            port: 8080
          initialDelaySeconds: 60
          periodSeconds: 5
        env:
        - name: JAVA_OPTS
          value: "-Dspring.profiles.active=dev"
        - name: DB_USER
          valueFrom:
            secretKeyRef:
              name: db-credentials
              key: username
        - name: DB_PASS
          valueFrom:
            secretKeyRef:
              name: db-credentials
              key: password
      restartPolicy: Always
      hostAliases:
      - ip: "127.0.0.1"
        hostnames:
        - "foo.local"
        - "bar.local"
      - ip: "10.1.2.3"
        hostnames:
        - "foo.remote"
        - "bar.remote" 
      imagePullSecrets:  
      - name: registry-secret

以下是 hosts 文件的输出:

# Kubernetes-managed hosts file.
127.0.0.1       localhost
::1     localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
fe00::0 ip6-mcastprefix
fe00::1 ip6-allnodes
fe00::2 ip6-allrouters
10.45.3.28      test-services-7799d8d9-vrwd2

相关内容