K8s应用程序使用Helm安装后不会显示在Helm列表表中。

huangapple go评论93阅读模式
英文:

K8s app installed using Helm does not show up in Helm list table

问题

我正在尝试使用一个简单的nginx图表来学习Helm,该图表创建一个单独的Pod和Service。

我想将其安装到指定的命名空间(在这种情况下为"dev")。

我的图表包括两个模板,一个用于部署以创建Pod,另一个用于Service以映射端口到容器。

deployment.yaml

  1. apiVersion: apps/v1
  2. kind: Deployment
  3. metadata:
  4. name: {{ include "nginx.fullname" . }}
  5. namespace: {{ .Release.Namespace | quote }}
  6. labels:
  7. {{- include "nginx.labels" . | nindent 4 }}
  8. spec:
  9. replicas: {{ .Values.replicaCount | default 1 }}
  10. selector:
  11. matchLabels:
  12. {{- include "nginx.selectorLabels" . | nindent 6 }}
  13. template:
  14. metadata:
  15. {{- with .Values.podAnnotations }}
  16. annotations:
  17. {{- toYaml . | nindent 8 }}
  18. {{- end }}
  19. labels:
  20. {{- include "nginx.selectorLabels" . | nindent 8 }}
  21. spec:
  22. containers:
  23. - name: {{ .Chart.Name }}
  24. securityContext:
  25. {{- toYaml .Values.securityContext | nindent 12 }}
  26. image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
  27. imagePullPolicy: {{ .Values.image.pullPolicy }}
  28. ports:
  29. - name: http
  30. containerPort: {{ .Values.service.containerport }}
  31. protocol: TCP
  32. livenessProbe:
  33. httpGet:
  34. path: /
  35. port: http
  36. readinessProbe:
  37. httpGet:
  38. path: /
  39. port: http

service.yaml

  1. apiVersion: v1
  2. kind: Service
  3. metadata:
  4. name: {{ include "nginx.fullname" . }}
  5. namespace: {{ .Release.Namespace | quote }}
  6. labels:
  7. {{- include "nginx.labels" . | nindent 4 }}
  8. spec:
  9. type: {{ .Values.service.type }}
  10. ports:
  11. - port: {{ .Values.service.port }}
  12. nodePort: {{ .Values.service.nodePort }}
  13. protocol: TCP
  14. name: http
  15. selector:
  16. {{- include "nginx.selectorLabels" . | nindent 4 }}

而values文件如下:

values-dev.yaml

  1. replicaCount: 1
  2. image:
  3. repository: nginx
  4. pullPolicy: IfNotPresent
  5. # 覆盖默认的图像标签,其默认值为图表的appVersion。
  6. tag: ""
  7. service:
  8. type: NodePort
  9. containerport: 80
  10. port: 80
  11. nodePort: 31010
  12. resources:
  13. limits:
  14. memory: 256Mi
  15. cpu: "250m"
  16. requests:
  17. memory: 128Mi
  18. cpu: "80m"

当我运行我的Helm命令时:

  1. helm install dev-nginx ./ --namespace dev --create-namespace --values values-dev.yaml

Helm似乎正在将所有必需的内容安装到正确的命名空间中。

  1. NAME: dev-nginx
  2. LAST DEPLOYED: Wed Jun 14 18:22:03 2023
  3. NAMESPACE: dev
  4. STATUS: deployed
  5. REVISION: 1
  6. TEST SUITE: None

但当我运行 helm list 时,安装不会显示在表格中。

  1. helm list
  2. NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION

如果我使用 kubectl 进行验证,我可以看到所有内容。

  1. kubectl get all -n dev
  2. NAME READY STATUS RESTARTS AGE
  3. pod/dev-nginx-5bff4b9659-mxmrb 1/1 Running 0 2m27s
  4. NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
  5. service/dev-nginx NodePort 10.109.251.249 <none> 80:31010/TCP 2m27s
  6. NAME READY UP-TO-DATE AVAILABLE AGE
  7. deployment.apps/dev-nginx 1/1 1 1 2m27s
  8. NAME DESIRED CURRENT READY AGE
  9. replicaset.apps/dev-nginx-5bff4b9659 1 1 1 2m27s

如果我不尝试控制命名空间,允许Helm部署到默认的命名空间,安装会显示在 helm install 表格中。

使用Helm安装到自定义命名空间是可能的,我只是犯了一个错误吗?

非常感谢。

英文:

I'm trying to learn Helm using a simple nginx chart that creates a single pod and service.

I want to install this into a specified namespace (dev in this case).

My chart comprises x2 templates, x1 for the deployment to create the pod, and x1 for a service to map a port to the container.

deployment.yaml

  1. apiVersion: apps/v1
  2. kind: Deployment
  3. metadata:
  4. name: {{ include &quot;nginx.fullname&quot; . }}
  5. namespace: {{ .Release.Namespace | quote }}
  6. labels:
  7. {{- include &quot;nginx.labels&quot; . | nindent 4 }}
  8. spec:
  9. replicas: {{ .Values.replicaCount | default 1 }}
  10. selector:
  11. matchLabels:
  12. {{- include &quot;nginx.selectorLabels&quot; . | nindent 6 }}
  13. template:
  14. metadata:
  15. {{- with .Values.podAnnotations }}
  16. annotations:
  17. {{- toYaml . | nindent 8 }}
  18. {{- end }}
  19. labels:
  20. {{- include &quot;nginx.selectorLabels&quot; . | nindent 8 }}
  21. spec:
  22. containers:
  23. - name: {{ .Chart.Name }}
  24. securityContext:
  25. {{- toYaml .Values.securityContext | nindent 12 }}
  26. image: &quot;{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}&quot;
  27. imagePullPolicy: {{ .Values.image.pullPolicy }}
  28. ports:
  29. - name: http
  30. containerPort: {{ .Values.service.containerport }}
  31. protocol: TCP
  32. livenessProbe:
  33. httpGet:
  34. path: /
  35. port: http
  36. readinessProbe:
  37. httpGet:
  38. path: /
  39. port: http

service.yaml

  1. apiVersion: v1
  2. kind: Service
  3. metadata:
  4. name: {{ include &quot;nginx.fullname&quot; . }}
  5. namespace: {{ .Release.Namespace | quote }}
  6. labels:
  7. {{- include &quot;nginx.labels&quot; . | nindent 4 }}
  8. spec:
  9. type: {{ .Values.service.type }}
  10. ports:
  11. - port: {{ .Values.service.port }}
  12. nodePort: {{ .Values.service.nodePort }}
  13. protocol: TCP
  14. name: http
  15. selector:
  16. {{- include &quot;nginx.selectorLabels&quot; . | nindent 4 }}

And the values file looks like this:

values-dev.yaml

  1. replicaCount: 1
  2. image:
  3. repository: nginx
  4. pullPolicy: IfNotPresent
  5. # Overrides the image tag whose default is the chart appVersion.
  6. tag: &quot;&quot;
  7. service:
  8. type: NodePort
  9. containerport: 80
  10. port: 80
  11. nodePort: 31010
  12. resources:
  13. limits:
  14. memory: 256Mi
  15. cpu: &quot;250m&quot;
  16. requests:
  17. memory: 128Mi
  18. cpu: &quot;80m&quot;

When I run my Helm command:

helm install dev-nginx ./ --namespace dev --create-namespace --values values-dev.yaml

Helm does seem to be installing everything required into the right namespace.

  1. NAME: dev-nginx
  2. LAST DEPLOYED: Wed Jun 14 18:22:03 2023
  3. NAMESPACE: dev
  4. STATUS: deployed
  5. REVISION: 1
  6. TEST SUITE: None

But when I run a helm list the installation does not show up in the table.

  1. helm list
  2. NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION

I can see everything if I verify using kubectl.

  1. k get all -n dev
  2. NAME READY STATUS RESTARTS AGE
  3. pod/dev-nginx-5bff4b9659-mxmrb 1/1 Running 0 2m27s
  4. NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
  5. service/dev-nginx NodePort 10.109.251.249 &lt;none&gt; 80:31010/TCP 2m27s
  6. NAME READY UP-TO-DATE AVAILABLE AGE
  7. deployment.apps/dev-nginx 1/1 1 1 2m27s
  8. NAME DESIRED CURRENT READY AGE
  9. replicaset.apps/dev-nginx-5bff4b9659 1 1 1 2m27s

If I don't try to control the namespace and allow Helm to deploy into the 'default' namespace, the install shows up in the helm install table.

Is using Helm to install to a custom namespace possible and I am just making a mistake?

Many thanks

答案1

得分: 0

helm list 命令将显示在 default 命名空间中安装的 Helm 图表,而你将其安装在 dev 命名空间中。

只需运行 helm list -n dev 来显示在 dev 命名空间中的安装,或者运行 helm list -A 来显示所有命名空间中的安装。

英文:

The helm list command will give you the installed helm chart in the default namespace and you installed it in dev namespace.

Just run helm list -n dev to show installations in dev namespace or helm list -A for all namespaces.

huangapple
  • 本文由 发表于 2023年6月15日 01:33:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/76476190.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定