我们使用掌舵来管理k8s集群中的所有资源。最近,我们发生了一起事故,其中一些k8s资源在掌舵之外被修改(目前尚不清楚确切发生了什么)。
但是最终结果是,集群中有一些k8s资源与该版本的掌舵图中指定的资源不匹配。
示例:
我们有一个包含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资源中不止一次发生漂移。
答案 0 :(得分:0)
您可以检查当前版本有多少个修订版本,然后从每个修订版本中获取值。
执行helm get values --revision int32 RELEASE_NAME
以估算差异。
请告诉我是否有帮助。
答案 1 :(得分:0)
我们找到了一种可扩展的方式来执行此操作。请注意,此解决方案需要Kubernetes 1.13来支持kubectl diff
。
总体思路是获取舵状态并使用kubectl
来应用它以再次同步两者。 这可能在您的群集上不安全,请使用kubectl diff
验证更改。
从掌舵中获取状态:helm get manifest {service}-release > {service}-release.yaml
检查k8s对象是否存在差异:kubectl diff -f {service}-release.yaml
用helm状态覆盖k8s状态:kubectl apply -f {service}-release.yaml