我正在尝试在具有一个头节点和两个工作节点的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

最佳答案

您的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: "127.0.0.1"在放置将解析为该IP的主机名之后。

您的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/的更多信息

关于kubernetes - 验证数据时出错:ValidationError(Deployment.spec.template.spec.volumes [0]):io.k8s.api.core.v1.Volume中的未知字段 “hostAliases”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/55563985/

10-16 06:34