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

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

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

问题

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

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

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

deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "nginx.fullname" . }}
  namespace: {{ .Release.Namespace | quote }}
  labels:
    {{- include "nginx.labels" . | nindent 4 }}
spec:
  replicas: {{ .Values.replicaCount | default 1 }}
  selector:
    matchLabels:
      {{- include "nginx.selectorLabels" . | nindent 6 }}
  template:
    metadata:
      {{- with .Values.podAnnotations }}
      annotations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      labels:
        {{- include "nginx.selectorLabels" . | nindent 8 }}
    spec:
      containers:
        - name: {{ .Chart.Name }}
          securityContext:
            {{- toYaml .Values.securityContext | nindent 12 }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          ports:
            - name: http
              containerPort: {{ .Values.service.containerport }}
              protocol: TCP
          livenessProbe:
            httpGet:
              path: /
              port: http
          readinessProbe:
            httpGet:
              path: /
              port: http

service.yaml

apiVersion: v1
kind: Service
metadata:
  name: {{ include "nginx.fullname" . }}
  namespace: {{ .Release.Namespace | quote }}
  labels:
    {{- include "nginx.labels" . | nindent 4 }}
spec:
  type: {{ .Values.service.type }}
  ports:
    - port: {{ .Values.service.port }}
      nodePort:  {{ .Values.service.nodePort }}
      protocol: TCP
      name: http
  selector:
    {{- include "nginx.selectorLabels" . | nindent 4 }}

而values文件如下:

values-dev.yaml

replicaCount: 1

image:
  repository: nginx
  pullPolicy: IfNotPresent
  # 覆盖默认的图像标签,其默认值为图表的appVersion。
  tag: ""

service:
  type: NodePort
  containerport: 80
  port: 80
  nodePort: 31010

resources:
  limits:
    memory: 256Mi
    cpu: "250m"
  requests:
    memory: 128Mi
    cpu: "80m"

当我运行我的Helm命令时:

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

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

NAME: dev-nginx
LAST DEPLOYED: Wed Jun 14 18:22:03 2023
NAMESPACE: dev
STATUS: deployed
REVISION: 1
TEST SUITE: None

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

helm list
NAME    NAMESPACE   REVISION    UPDATED STATUS  CHART       APP VERSION

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

kubectl get all -n dev
NAME                             READY   STATUS    RESTARTS   AGE
pod/dev-nginx-5bff4b9659-mxmrb   1/1     Running   0          2m27s

NAME                TYPE       CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGE
service/dev-nginx   NodePort   10.109.251.249   <none>        80:31010/TCP   2m27s

NAME                        READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/dev-nginx   1/1     1            1           2m27s

NAME                                   DESIRED   CURRENT   READY   AGE
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

apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include &quot;nginx.fullname&quot; . }}
  namespace: {{ .Release.Namespace | quote }}
  labels:
    {{- include &quot;nginx.labels&quot; . | nindent 4 }}
spec:
  replicas: {{ .Values.replicaCount | default 1 }}
  selector:
    matchLabels:
      {{- include &quot;nginx.selectorLabels&quot; . | nindent 6 }}
  template:
    metadata:
      {{- with .Values.podAnnotations }}
      annotations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      labels:
        {{- include &quot;nginx.selectorLabels&quot; . | nindent 8 }}
    spec:
      containers:
        - name: {{ .Chart.Name }}
          securityContext:
            {{- toYaml .Values.securityContext | nindent 12 }}
          image: &quot;{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}&quot;
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          ports:
            - name: http
              containerPort: {{ .Values.service.containerport }}
              protocol: TCP
          livenessProbe:
            httpGet:
              path: /
              port: http
          readinessProbe:
            httpGet:
              path: /
              port: http

service.yaml

apiVersion: v1
kind: Service
metadata:
  name: {{ include &quot;nginx.fullname&quot; . }}
  namespace: {{ .Release.Namespace | quote }}
  labels:
    {{- include &quot;nginx.labels&quot; . | nindent 4 }}
spec:
  type: {{ .Values.service.type }}
  ports:
    - port: {{ .Values.service.port }}
      nodePort:  {{ .Values.service.nodePort }}
      protocol: TCP
      name: http
  selector:
    {{- include &quot;nginx.selectorLabels&quot; . | nindent 4 }}

And the values file looks like this:

values-dev.yaml

replicaCount: 1

image:
  repository: nginx
  pullPolicy: IfNotPresent
  # Overrides the image tag whose default is the chart appVersion.
  tag: &quot;&quot;

service:
  type: NodePort
  containerport: 80
  port: 80
  nodePort: 31010

resources:
  limits:
    memory: 256Mi
    cpu: &quot;250m&quot;
  requests:
    memory: 128Mi
    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.

NAME: dev-nginx
LAST DEPLOYED: Wed Jun 14 18:22:03 2023
NAMESPACE: dev
STATUS: deployed
REVISION: 1
TEST SUITE: None

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

helm list
NAME	NAMESPACE	REVISION	UPDATED	STATUS	CHART	APP VERSION

I can see everything if I verify using kubectl.

k get all -n dev
NAME                             READY   STATUS    RESTARTS   AGE
pod/dev-nginx-5bff4b9659-mxmrb   1/1     Running   0          2m27s

NAME                TYPE       CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGE
service/dev-nginx   NodePort   10.109.251.249   &lt;none&gt;        80:31010/TCP   2m27s

NAME                        READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/dev-nginx   1/1     1            1           2m27s

NAME                                   DESIRED   CURRENT   READY   AGE
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:

确定