我使用 k8s 并使用 gitlab 部署我的应用程序。例如,我的集群具有命名空间 product
。如果我最初安装我运行的应用程序:
$ helm install --name super-app -f values.yml ./Path/To/Project/helm
此命令将在命名空间生产中成功安装应用程序,因为它在 helm 值中指定:
replicaCount: 3
imagePullSecret: regcred
namespace: production
在项目 Helm chart 中,我设置了默认命名空间:
replicaCount: 3
imagePullSecret: regcred
namespace: default
当我从 gitlab ci 运行程序运行以下命令时:
helm upgrade -f ./values.yaml --set image.tag=master-$DOCKER_IMAGE_TAG super-app ./helm
在values.yaml中再次指定命名空间生成,我得到以下结果:
Release "super-app has been upgraded.
LAST DEPLOYED: Wed Oct 23 12:15:36 2019
NAMESPACE: production
STATUS: DEPLOYED
RESOURCES:
==> v1/ConfigMap
NAME DATA AGE
super-app 1 0s
==> v1/Deployment
NAME READY UP-TO-DATE AVAILABLE AGE
super-app 0/3 3 0 0s
==> v1/Pod(related)
NAME READY STATUS RESTARTS AGE
super-app-5d6dc6c9d-25q9g 0/1 ContainerCreating 0 0s
super-app-5d6dc6c9d-tdfhh 0/1 ContainerCreating 0 0s
super-app-5d6dc6c9d-z7h96 0/1 ContainerCreating 0 0s
==> v1/Secret
NAME TYPE DATA AGE
super-app Opaque 0 0s
==> v1/Service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
super-app LoadBalancer 10.100.115.194 <pending> 8080:32645/TCP 0s
应用程序现在部署在默认命名空间中,而不是在生产环境中。即使现有应用程序(在 helm 升级命令之前)正在生产命名空间中运行。 Helm 只是在默认命名空间中创建一个新的服务和应用程序。 同样的逻辑适用于其他应用程序,为什么 k8s 忽略我的命名空间配置?
谢谢
最佳答案
尽管 Chart Best Practices 中没有记录它然而,这个问题( #5465 )解决了命名空间注意事项:
In general, templates should not define a namespace. This is because Helm installs objects into the namespace provided with the
--namespace
flag. By omitting this information, it also provides templates with some flexibility for post-render operations (likehelm template | kubectl create --namespace foo -f -
)
如前所述,您的最佳选择是将 --namespace
添加到安装/升级命令中,而不是在模板上定义它。
关于kubernetes - helm 升级忽略命名空间配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58522811/