-2

Getting an error for the following deployment.yaml:

admin@ip-172-20-58-79:~/kubernetes-prometheus/kube-state-metrics-configs$ kubectl apply -f deployment.yaml

error: error converting YAML to JSON: yaml: line 21: found a tab character that violate indentation

admin@ip-172-20-58-79:~/kubernetes-prometheus/kube-state-metrics-configs$ cat deployment.yaml

apiVersion: apps/v1beta1
kind: Deployment
metadata:
  labels:
    app.kubernetes.io/name: kube-state-metrics
    app.kubernetes.io/version: v1.8.0
  name: kube-state-metrics
  namespace: kube-system
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: kube-state-metrics
  template:
    metadata:
      labels:
        app.kubernetes.io/name: kube-state-metrics
        app.kubernetes.io/version: v1.8.0
    spec:
      containers:
      - image: quay.io/coreos/kube-state-metrics:v1.8.0
        imagePullPolicy: Always
        name: kube-state-metrics
        args:
        - --kubelet-insecure-tls
        - --kubelet-preferred-address-types=InternalIP,ExternalIP,Hostname
        livenessProbe:
          httpGet:
            path: /healthz
            port: 8080
          initialDelaySeconds: 5
          timeoutSeconds: 5
        name: kube-state-metrics
        ports:
        - containerPort: 8080
          name: http-metrics
        - containerPort: 8081
          name: telemetry
        readinessProbe:
          httpGet:
            path: /
            port: 8081
          initialDelaySeconds: 5
          timeoutSeconds: 5
      nodeSelector:
        kubernetes.io/os: linux
      serviceAccountName: kube-state-metrics

Update 1 : admin@ip-172-20-58-79:~$ kubectl describe nodes

https://pastebin.com/bectdNes

Update 2 : As per suggested by Arghya Sadhu added nodeSelector

admin@ip-172-20-58-79:~/kubernetes-prometheus/kube-state-metrics-configs$ kubectl edit deploy kube-state-metrics -n kube-system

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  annotations:
    deployment.kubernetes.io/revision: "6"
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"apps/v1","kind":"Deployment","metadata":{"annotations":{},"labels":{"app.kubernetes.io/name":"kube-state-metrics","app.kubernetes.io/version":"v1.8.0"},"name":"kube-state-metrics","namespace":"kube-system"},"spec":{"replicas":1,"selector":{"matchLabels":{"app.kubernetes.io/name":"kube-state-metrics"}},"template":{"metadata":{"labels":{"app.kubernetes.io/name":"kube-state-metrics","app.kubernetes.io/version":"v1.8.0"}},"spec":{"containers":[{"args":["--kubelet-insecure-tls","--kubelet-preferred-address-types=InternalIP,ExternalIP,Hostname"],"image":"quay.io/coreos/kube-state-metrics:v1.8.0","imagePullPolicy":"Always","livenessProbe":{"httpGet":{"path":"/healthz","port":8080},"initialDelaySeconds":5,"timeoutSeconds":5},"name":"kube-state-metrics","ports":[{"containerPort":8080,"name":"http-metrics"},{"containerPort":8081,"name":"telemetry"}],"readinessProbe":{"httpGet":{"path":"/","port":8081},"initialDelaySeconds":5,"timeoutSeconds":5}}],"nodeSelector":{"kubernetes.io/os":"linux"},"hostNetwork":true,"nodeSelector":{"node-role.kubernetes.io/master":""},"tolerations":[{"effect":"NoSchedule","key":"node-role.kubernetes.io/master","serviceAccountName":"kube-state-metrics"}}}}
  creationTimestamp: 2020-01-10T05:33:13Z
  generation: 12
  labels:
    app.kubernetes.io/name: kube-state-metrics
    app.kubernetes.io/version: v1.9.2
  name: kube-state-metrics
  namespace: kube-system
  resourceVersion: "178997153"
  selfLink: /apis/extensions/v1beta1/namespaces/kube-system/deployments/kube-state-metrics
  uid: b20aa645-336a-11ea-9618-0607d7cb72ed
spec:
  progressDeadlineSeconds: 600
  replicas: 1
  revisionHistoryLimit: 2
  selector:
    matchLabels:
      app.kubernetes.io/name: kube-state-metrics
  strategy:
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
    type: RollingUpdate
  template:
    metadata:
      creationTimestamp: null
      labels:
        app.kubernetes.io/name: kube-state-metrics
        app.kubernetes.io/version: v1.8.0
    spec:
      containers:
      - args:
        - --kubelet-insecure-tls
        - --kubelet-preferred-address-types=InternalIP
        image: quay.io/coreos/kube-state-metrics:v1.8.0
        imagePullPolicy: Always
        livenessProbe:
          failureThreshold: 3
          httpGet:
            path: /healthz
            port: 8080
            scheme: HTTP
          initialDelaySeconds: 5
          periodSeconds: 10
          successThreshold: 1
          timeoutSeconds: 5
        name: kube-state-metrics
        ports:
        - containerPort: 8080
          hostPort: 8080
          name: http-metrics
          protocol: TCP
        - containerPort: 8081
          hostPort: 8081
          name: telemetry
          protocol: TCP
        readinessProbe:
          failureThreshold: 3
          httpGet:
            path: /
            port: 8081
            scheme: HTTP
          initialDelaySeconds: 5
          periodSeconds: 10
          successThreshold: 1
          timeoutSeconds: 5
        resources: {}
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
      dnsPolicy: ClusterFirst
      hostNetwork: true
      nodeName: ip-172-20-58-72.us-west-1.compute.internal
      nodeSelector:
        node-role.kubernetes.io/master: ""
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      serviceAccount: kube-state-metrics
      serviceAccountName: kube-state-metrics
      terminationGracePeriodSeconds: 30
status:
  conditions:
  - lastTransitionTime: 2020-01-16T03:07:35Z
    lastUpdateTime: 2020-01-16T03:07:35Z
    message: Deployment does not have minimum availability.
    reason: MinimumReplicasUnavailable
    status: "False"
    type: Available
  - lastTransitionTime: 2020-01-15T07:41:48Z
    lastUpdateTime: 2020-01-16T04:15:14Z
    message: ReplicaSet "kube-state-metrics-5fdf7fb4fc" is progressing.
    reason: ReplicaSetUpdated
    status: "True"
    type: Progressing
  observedGeneration: 12
  replicas: 2
  unavailableReplicas: 2
  updatedReplicas: 1

Getting following error:

Events:
  Type     Reason            Age   From                                                 Message
  ----     ------            ----  ----                                                 -------
  Warning  PodFitsHostPorts  21s   kubelet, ip-172-20-58-72.us-west-1.compute.internal  Predicate PodFitsHostPorts failed

After changing ports now getting:

Events:
  Type     Reason             Age   From                                                 Message
  ----     ------             ----  ----                                                 -------
  Warning  MatchNodeSelector  11s   kubelet, ip-172-20-58-72.us-west-1.compute.internal  Predicate MatchNodeSelector failed
Ashish Karpe
  • 5,087
  • 7
  • 41
  • 66
  • 2
    then you have to make sure that no tab characters are in your file, just like the error says. yaml does not allow tabs for indentation. – Markus Dresch Jan 15 '20 at 06:04
  • I cannot see any issue with the yaml given. Best thing is the yaml code to a text editor and make sure no tabs been used in the line 21. And re-deploy. I have tried it and working fine. – Anuradha Fernando Jan 15 '20 at 06:25

2 Answers2

2

I tried the the yaml and it gave me this error

error: unable to recognize "kube-state-metrics.yaml": no matches for kind "Deployment" in version "apps/v1beta1"

I changed apps/v1beta1 to apps/v1 to solve it but I did not get the error that you reported.

Here is the yaml I used

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app.kubernetes.io/name: kube-state-metrics
    app.kubernetes.io/version: v1.8.0
  name: kube-state-metrics
  namespace: kube-system
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: kube-state-metrics
  template:
    metadata:
      labels:
        app.kubernetes.io/name: kube-state-metrics
        app.kubernetes.io/version: v1.8.0
    spec:
      containers:
      - image: quay.io/coreos/kube-state-metrics:v1.8.0
        imagePullPolicy: Always
        name: kube-state-metrics
        args:
        - --kubelet-insecure-tls
        - --kubelet-preferred-address-types=InternalIP,ExternalIP,Hostname
        livenessProbe:
          httpGet:
            path: /healthz
            port: 8080
          initialDelaySeconds: 5
          timeoutSeconds: 5
        name: kube-state-metrics
        ports:
        - containerPort: 8080
          name: http-metrics
        - containerPort: 8081
          name: telemetry
        readinessProbe:
          httpGet:
            path: /
            port: 8081
          initialDelaySeconds: 5
          timeoutSeconds: 5
      nodeSelector:
        kubernetes.io/os: linux
      serviceAccountName: kube-state-metrics
Arghya Sadhu
  • 41,002
  • 9
  • 78
  • 107
  • can you please paste deployment.yaml which you used – Ashish Karpe Jan 15 '20 at 07:16
  • This yaml now worked for me! But now Pod for kube-state-matrics is in Pending state with follwoing event in pod describtion : Events: Type Reason Age From Message ---- ------ ---- ---- ------- Warning FailedScheduling 2m (x107 over 33m) default-scheduler No nodes are available that match all of the predicates: MatchNodeSelector (7), PodToleratesNodeTaints (1). – Ashish Karpe Jan 15 '20 at 10:06
  • 1
    output of kubectl describe nodes? – Arghya Sadhu Jan 15 '20 at 10:11
  • 1
    Your nodes have some taints...you need to add toleration for those taints in the pod's yaml – Arghya Sadhu Jan 15 '20 at 10:22
  • the output of kubectl describe nodes https://pastebin.com/bectdNes – Ashish Karpe Jan 15 '20 at 10:50
  • is kube-state-matrics pod necessary to run on master as I have a lot of nodes available? How to find exactly what is the taint in my case had what tolerance to add and how to add? – Ashish Karpe Jan 15 '20 at 10:54
  • 1
    can you add nodeSelector: kubernetes.io/role=node under the pod spec. Check example here https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#step-two-add-a-nodeselector-field-to-your-pod-configuration – Arghya Sadhu Jan 15 '20 at 10:58
  • Where is it recommended to run kube-state-metrics pod on master or randomly on any node? – Ashish Karpe Jan 16 '20 at 02:02
  • Please check above question after update 2: getting Warning MatchNodeSelector 14s kubelet, ip-172-20-58-72.us-west-1.compute.internal Predicate MatchNodeSelector failed – Ashish Karpe Jan 16 '20 at 04:27
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/206036/discussion-between-ashish-karpe-and-arghya-sadhu). – Ashish Karpe Jan 16 '20 at 04:27
1

I cannot see an issue with the yaml given. I checked and deployed successfully. However double check no tab been used for indentation at line 21 and re-deploy the same yaml.

Also try deploying the yaml in the v1.9.2

 apiVersion: apps/v1
 kind: Deployment
 metadata:
   labels:
     app.kubernetes.io/name: kube-state-metrics
     app.kubernetes.io/version: v1.9.2
   name: kube-state-metrics
   namespace: kube-system
 spec:
   replicas: 1
   selector:
     matchLabels:
       app.kubernetes.io/name: kube-state-metrics
   template:
     metadata:
       labels:
         app.kubernetes.io/name: kube-state-metrics
         app.kubernetes.io/version: v1.9.2
     spec:
       containers:
       - image: quay.io/coreos/kube-state-metrics:v1.9.2
         livenessProbe:
           httpGet:
             path: /healthz
             port: 8080
           initialDelaySeconds: 5
           timeoutSeconds: 5
         name: kube-state-metrics
         ports:
         - containerPort: 8080
           name: http-metrics
         - containerPort: 8081
           name: telemetry
         readinessProbe:
           httpGet:
             path: /
             port: 8081
           initialDelaySeconds: 5
           timeoutSeconds: 5
       nodeSelector:
         kubernetes.io/os: linux
       serviceAccountName: kube-state-metrics
Anuradha Fernando
  • 1,063
  • 12
  • 17
  • try adding adding to deployment.yaml command: - /metrics-server - --kubelet-insecure-tls - --kubelet-preferred-address-types=InternalIP – Ashish Karpe Jan 15 '20 at 07:18