【发布时间】:2019-12-01 12:31:05
【问题描述】:
我们使用 helm 来管理 k8s 集群中的所有资源。最近我们发生了一个事件,其中一些 k8s 资源在 helm 之外被修改(有关根本原因的详细信息,请参见下文)。
然而,最终结果是,我们的集群中有一些 k8s 资源与发布的 helm 图表中指定的资源不匹配。
例子:
我们有一个包含HorizontalPodAutoscaler 的舵图。如果我这样做:
helm get myservice-release
我会看到这样的:
---
# Source: myservice/charts/default-deployment/templates/default_deployment.yaml
apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
name: myservice-autoscaler
labels:
app: myservice
spec:
minReplicas: 2
maxReplicas: 10
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: myservice-deployment
metrics:
- type: Resource
resource:
name: cpu
targetAverageUtilization: 85
但是,如果我这样做:
kubectl get hpa myservice-autoscaler -o yaml
spec.{max,min}Replicas 与图表不符:
apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
annotations:
autoscaling.alpha.kubernetes.io/conditions: '{REDACTED}'
autoscaling.alpha.kubernetes.io/current-metrics: '{REDACTED}'
creationTimestamp: "{REDACTED}"
labels:
app: myservice
name: myservice-autoscaler
namespace: default
resourceVersion: "174526833"
selfLink: /apis/autoscaling/v1/namespaces/default/horizontalpodautoscalers/myservice-autoscaler
uid: {REDACTED}
spec:
maxReplicas: 1
minReplicas: 1
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: myservice-deployment
targetCPUUtilizationPercentage: 85
status:
currentCPUUtilizationPercentage: 9
currentReplicas: 1
desiredReplicas: 1
lastScaleTime: "{REACTED}"
我怀疑,k8s 资源中出现的漂移不止一次。
- 如何验证哪些资源发生了偏移?
- 我如何通知 helm 这种偏差,以便下一次部署在应用版本差异时可以考虑到它?
编辑:
对于那些感兴趣的人,这是由管理相同资源(自动缩放)的两个 helm 图表设置不同的值造成的。
发生这种情况是因为两个用于不同命名空间的 helm 版本最终都在同一个版本中,并且更新为 --force。
【问题讨论】:
标签: kubernetes kubernetes-helm