验证数据时出错:ValidationError(Deployment.spec.template.spec.volumes [0]):io.k8s.api.core.v1.Volume

时间:2019-04-07 21:50:10

标签: kubernetes monitoring

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

1 个答案:

答案 0 :(得分: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: "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/

的更多信息