错误验证数据:ValidationError(Deployment.spec.template.spec.volumes [0]):io.k8s.api.core.v1.Volume中的未知字段“hostAliases”

问题描述 投票:1回答:1

我试图在kubeadm上使用一个头节点和两个工作节点的度量服务器,但我不断收到一个未知的hostAliases错误

.........................................................................

apiVersion: extensions/v1beta1
kind: Deployment
metadata: 
  labels: 
    k8s-app: metrics-server
  name: metrics-server
  namespace: kube-system
spec: 
  selector: 
    matchLabels: 
      k8s-app: metrics-server
  template: 
    metadata: 
      labels: 
        k8s-app: metrics-server
      name: metrics-server
    spec: 
      containers: 
        - 
          command: 
            - /metrics-server
            - "--kubelet-insecure-tls"
            - "--kubelet-preferred-address-types=InternalDNS,InternalIPExternalDNS,ExternalIP,Hostname"
          image: "k8s.gcr.io/metrics-server-amd64:v0.3.1"
          imagePullPolicy: Always
          name: metrics-server
          volumeMounts: 
            - 
              mountPath: /tmp
              name: tmp-dir
      serviceAccountName: metrics-server
      volumes: 
        - 
          emptyDir: {}
          hostAliases: 
            - 
              hostnames: 
                - k8s-head
              ip: "192.168.205.10"
            - 
              hostnames: 
                - k8s-node-1
              ip: "192.168.205.11"
            - 
              hostnames: 
                - k8s-node-2
              ip: "192.168.205.12"
          name: tmp-dir
kubernetes monitoring
1个回答
1
投票

您的YAML文件结构似乎有误,HostAliases应该是这样的结构

apiVersion: v1
kind: Pod
metadata:
  name: hostaliases-pod
spec:
  restartPolicy: Never
  hostAliases:
  - ip: "127.0.0.1"
    hostnames:
    - "foo.local"
    - "bar.local"
  - ip: "10.1.2.3"
    hostnames:
    - "foo.remote"
    - "bar.remote"

请注意,在hostAliases条目之后,您应该在将要解析的主机名放到此ip之后立即放置- ip: "127.0.0.1"

你的YAML是

hostAliases: 
  - hostnames: 
    - k8s-head 
  ip: "192.168.205.10" 
    - hostnames: 
      - k8s-node-1 
  ip: "192.168.205.11" 
    - hostnames: 
      - k8s-node-2 
  ip: "192.168.205.12" 

在这里您可以找到更多关于https://kubernetes.io/docs/concepts/services-networking/add-entries-to-pod-etc-hosts-with-host-aliases/的信息

© www.soinside.com 2019 - 2024. All rights reserved.