当前位置:   article > 正文

kubernetes|云原生|Deployment does not have minimum availability 的解决方案(资源隐藏的由来)_deployment does not have minimum availability.

deployment does not have minimum availability.

前言:

最近在部署prometheus的过程中遇到的这个问题,感觉比较的经典,有必要记录一下。

现象是部署prometheus主服务的时候,看不到pod,只能看到deployment,由于慌乱,一度以为是集群有毛病了,然后重新做了集群,具体情况如下图:

注:up-to-date表示没有部署,available表示无可用pod

  1. [root@node4 yaml]# k get deployments.apps -n monitor-sa
  2. NAME READY UP-TO-DATE AVAILABLE AGE
  3. prometheus-server 0/2 0 0 2m5s
  4. [root@node4 yaml]# k get po -n monitor-sa
  5. NAME READY STATUS RESTARTS AGE
  6. node-exporter-6ttbl 1/1 Running 0 23h
  7. node-exporter-7ls5t 1/1 Running 0 23h
  8. node-exporter-r287q 1/1 Running 0 23h
  9. node-exporter-z85dm 1/1 Running 0 23h

部署文件如下;

注意注意,有一个sa的引用哦  serviceAccountName: monitor

  1. [root@node4 yaml]# cat prometheus-deploy.yaml
  2. ---
  3. apiVersion: apps/v1
  4. kind: Deployment
  5. metadata:
  6. name: prometheus-server
  7. namespace: monitor-sa
  8. labels:
  9. app: prometheus
  10. spec:
  11. replicas: 2
  12. selector:
  13. matchLabels:
  14. app: prometheus
  15. component: server
  16. #matchExpressions:
  17. #- {key: app, operator: In, values: [prometheus]}
  18. #- {key: component, operator: In, values: [server]}
  19. template:
  20. metadata:
  21. labels:
  22. app: prometheus
  23. component: server
  24. annotations:
  25. prometheus.io/scrape: 'false'
  26. spec:
  27. nodeName: node4
  28. serviceAccountName: monitor
  29. containers:
  30. - name: prometheus
  31. image: prom/prometheus:v2.2.1
  32. imagePullPolicy: IfNotPresent
  33. command:
  34. - prometheus
  35. - --config.file=/etc/prometheus/prometheus.yml
  36. - --storage.tsdb.path=/prometheus
  37. - --storage.tsdb.retention=720h
  38. ports:
  39. - containerPort: 9090
  40. protocol: TCP
  41. volumeMounts:
  42. - mountPath: /etc/prometheus/prometheus.yml
  43. name: prometheus-config
  44. subPath: prometheus.yml
  45. - mountPath: /prometheus/
  46. name: prometheus-storage-volume
  47. volumes:
  48. - name: prometheus-config
  49. configMap:
  50. name: prometheus-config
  51. items:
  52. - key: prometheus.yml
  53. path: prometheus.yml
  54. mode: 0644
  55. - name: prometheus-storage-volume
  56. hostPath:
  57. path: /data
  58. type: Directory

 

解决方案:

那么,遇到这种情况,我们应该怎么做呢?当然了,第一点就是不要慌,其次deployment控制器有一个比较不让人注意的地方,就是编辑deployment可以看到该deployment的当前状态详情,会有非常详细的信息给我们看,也就是status字段

具体的命令是 kubectl edit deployment -n 命名空间  deployment名称,在本例中是这样的:

  1. 。。。。。。略略略
  2. path: prometheus.yml
  3. name: prometheus-config
  4. name: prometheus-config
  5. - hostPath:
  6. path: /data
  7. type: Directory
  8. name: prometheus-storage-volume
  9. status:
  10. conditions:
  11. - lastTransitionTime: "2023-11-22T15:21:06Z"
  12. lastUpdateTime: "2023-11-22T15:21:06Z"
  13. message: Deployment does not have minimum availability.
  14. reason: MinimumReplicasUnavailable
  15. status: "False"
  16. type: Available
  17. - lastTransitionTime: "2023-11-22T15:21:06Z"
  18. lastUpdateTime: "2023-11-22T15:21:06Z"
  19. message: 'pods "prometheus-server-78bbb77dd7-" is forbidden: error looking up
  20. service account monitor-sa/monitor: serviceaccount "monitor" not found'
  21. reason: FailedCreate
  22. status: "True"
  23. type: ReplicaFailure
  24. - lastTransitionTime: "2023-11-22T15:31:07Z"
  25. lastUpdateTime: "2023-11-22T15:31:07Z"
  26. message: ReplicaSet "prometheus-server-78bbb77dd7" has timed out progressing.
  27. reason: ProgressDeadlineExceeded
  28. status: "False"
  29. type: Progressing
  30. observedGeneration: 1
  31. unavailableReplicas: 2

可以看到有三个message,第一个是标题里提到的报错信息,在dashboard里这个信息会优先显示,如果是报错的时候,第二个message是进一步解释错误问题在哪,本例里是说有个名叫 monitor的sa没有找到,第三个信息说的是这个deployment控制的rs部署失败,此信息无关紧要了,那么,重要的是第二个信息,这个信息是解决问题的关键。

附:一个正常的deployment 的status:

这个status告诉我们,他是一个副本,部署成功的,因此,第一个message是Deployment has minimum availability

  1. serviceAccount: kube-state-metrics
  2. serviceAccountName: kube-state-metrics
  3. terminationGracePeriodSeconds: 30
  4. status:
  5. availableReplicas: 1
  6. conditions:
  7. - lastTransitionTime: "2023-11-21T14:56:14Z"
  8. lastUpdateTime: "2023-11-21T14:56:14Z"
  9. message: Deployment has minimum availability.
  10. reason: MinimumReplicasAvailable
  11. status: "True"
  12. type: Available
  13. - lastTransitionTime: "2023-11-21T14:56:13Z"
  14. lastUpdateTime: "2023-11-21T14:56:14Z"
  15. message: ReplicaSet "kube-state-metrics-57794dcf65" has successfully progressed.
  16. reason: NewReplicaSetAvailable
  17. status: "True"
  18. type: Progressing
  19. observedGeneration: 1
  20. readyReplicas: 1
  21. replicas: 1
  22. updatedReplicas: 1

具体的解决方案:

根据以上报错信息,那么,我们就需要一个sa,当然了,如果不想给太高的权限,就需要自己编写权限文件了,这里我偷懒 使用cluster-admin,具体的命令如下:

  1. [root@node4 yaml]# k create sa -n monitor-sa monitor
  2. serviceaccount/monitor created
  3. [root@node4 yaml]# k create clusterrolebinding monitor-clusterrolebinding -n monitor-sa --clusterrole=cluster-admin --serviceaccount=monitor-sa:monitor

再次部署就成功了:

  1. [root@node4 yaml]# k get po -n monitor-sa -owide
  2. NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
  3. node-exporter-6ttbl 1/1 Running 0 24h 192.168.123.12 node2 <none> <none>
  4. node-exporter-7ls5t 1/1 Running 0 24h 192.168.123.11 node1 <none> <none>
  5. node-exporter-r287q 1/1 Running 1 (2m57s ago) 24h 192.168.123.14 node4 <none> <none>
  6. node-exporter-z85dm 1/1 Running 0 24h 192.168.123.13 node3 <none> <none>
  7. prometheus-server-78bbb77dd7-6smlt 1/1 Running 0 20s 10.244.41.19 node4 <none> <none>
  8. prometheus-server-78bbb77dd7-fhf5k 1/1 Running 0 20s 10.244.41.18 node4 <none> <none>

总结来了:

那么,其实缺少sa可能会导致pod被隐藏,可以得出,sa是这个deployment的必要非显性依赖,同样的,如果部署文件内有写configmap,但configmap并没有提前创建也会出现这种错误,就是创建了deployment,但pod创建不出来,不像namespace没有提前创建的情况,namespace是必要显性依赖,没有会直接不让创建。

配额设置也是和sa一样的必要非显性依赖。

例如,下面创建一个针对default这个命名空间的配额文件,此文件定义如下:

定义的内容为规定default命名空间下最多4个pods,最多20个services,只能使用10G的内存,5.5的CPU

  1. [root@node4 yaml]# cat quota-nginx.yaml
  2. apiVersion: v1
  3. kind: ResourceQuota
  4. metadata:
  5. name: quota
  6. namespace: default
  7. spec:
  8. hard:
  9. requests.cpu: "5.5"
  10. limits.cpu: "5.5"
  11. requests.memory: 10Gi
  12. limits.memory: 10Gi
  13. pods: "4"
  14. services: "20"

下面创建一个deployment,副本是6个的nginx:

  1. [root@node4 yaml]# cat nginx.yaml
  2. apiVersion: apps/v1
  3. kind: Deployment
  4. metadata:
  5. annotations:
  6. deployment.kubernetes.io/revision: "1"
  7. creationTimestamp: "2023-11-22T16:13:33Z"
  8. generation: 1
  9. labels:
  10. app: nginx
  11. name: nginx
  12. namespace: default
  13. resourceVersion: "16411"
  14. uid: e9a5cdc5-c6f0-45fb-a001-fcdd695eb925
  15. spec:
  16. progressDeadlineSeconds: 600
  17. replicas: 6
  18. revisionHistoryLimit: 10
  19. selector:
  20. matchLabels:
  21. app: nginx
  22. strategy:
  23. rollingUpdate:
  24. maxSurge: 25%
  25. maxUnavailable: 25%
  26. type: RollingUpdate
  27. template:
  28. metadata:
  29. creationTimestamp: null
  30. labels:
  31. app: nginx
  32. spec:
  33. containers:
  34. - image: nginx:1.18
  35. imagePullPolicy: IfNotPresent
  36. name: nginx
  37. resources: {}
  38. terminationMessagePath: /dev/termination-log
  39. terminationMessagePolicy: File
  40. resources:
  41. limits:
  42. cpu: 1
  43. memory: 1Gi
  44. requests:
  45. cpu: 500m
  46. memory: 512Mi
  47. dnsPolicy: ClusterFirst
  48. restartPolicy: Always
  49. schedulerName: default-scheduler
  50. securityContext: {}
  51. terminationGracePeriodSeconds: 30

创建完毕后,发现只有四个pod,配额有效:

  1. [root@node4 yaml]# k get po
  2. NAME READY STATUS RESTARTS AGE
  3. nginx-54f9858f64-g65pk 1/1 Running 0 4m50s
  4. nginx-54f9858f64-h42vf 1/1 Running 0 4m50s
  5. nginx-54f9858f64-s776t 1/1 Running 0 4m50s
  6. nginx-54f9858f64-wl7wz 1/1 Running 0 4m50s

那么,还有两个pod呢?

  1. [root@node4 yaml]# k get deployments.apps nginx -oyaml |grep message
  2. message: Deployment does not have minimum availability.
  3. message: 'pods "nginx-54f9858f64-p8rxf" is forbidden: exceeded quota: quota, requested:
  4. message: ReplicaSet "nginx-54f9858f64" is progressing.

那么解决的方法也很简单,也就是调整quota啦,怎么调整就不在这里废话了吧!!!!!!!!!~~~~~~

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/菜鸟追梦旅行/article/detail/348234
推荐阅读
相关标签
  

闽ICP备14008679号