为什么不使用部署模板中定义的名称? [英] Why doesn't helm use the name defined in the deployment template?
问题描述
即从下面的name: {{ .Chart.Name }}-{{ .Values.module5678.name }}-pod
# deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: {{ template "project1234.name" . }}
chart: {{ template "project1234.chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
name: {{ template "project1234.module5678.fullname" . }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
app: {{ template "project1234.name" . }}
template:
metadata:
labels:
app: {{ template "project1234.name" . }}
spec:
containers:
- image: "{{ .Values.image.name }}:{{ .Values.image.tag }}"
name: {{ .Chart.Name }}-{{ .Values.module5678.name }}-pod
ports:
- containerPort: 1234
imagePullSecrets:
- name: {{ .Values.image.pullSecret }}
我希望广告连播名称为:
I am expecting the pod name to be:
pod/project1234-module5678-pod
pod/project1234-module5678-pod
相反,生成的Pod名称为:
Instead, the resulting Pod name is:
pod/chartname-project1234-module5678-dc7db787-skqvv
pod/chartname-project1234-module5678-dc7db787-skqvv
...在哪里(据我了解):
图表名称来自:helm install --name chartname -f values.yaml .
project1234 来自:
...where (in my understanding):
chartname is from: helm install --name chartname -f values.yaml .
project1234 is from:
# Chart.yaml
apiVersion: v1
appVersion: "1.0"
description: project1234 Helm chart for Kubernetes
name: project1234
version: 0.1.0
module5678 来自:
# values.yaml
rbac:
create: true
serviceAccounts:
module5678:
create: true
name:
image:
name: <image location>
tag: 1.5
pullSecret: <pull secret>
gitlab:
secretName: <secret name>
username: foo
password: bar
module5678:
enabled: true
name: module5678
ingress:
enabled: true
replicaCount: 1
resources: {}
我尝试将name: {{ .Chart.Name }}-{{ .Values.module5678.name }}-pod
更改为纯字符串值,例如"podname1234",但没有遵循.我什至尝试完全删除名称设置,并且结果吊舱名称保持不变.
I've tried changing name: {{ .Chart.Name }}-{{ .Values.module5678.name }}-pod
into a plain string value like "podname1234" and it isn't followed. I even tried removing the name setting entirely and the resulting pod name remains the same.
推荐答案
从Deployment创建的Pod始终具有基于Deployment的名称(以及中间ReplicaSet的名称,如果您不进行查找的话)的生成名称. ).您无法覆盖它.
Pods created from a Deployment always have a generated name based on the Deployment's name (and also the name of the intermediate ReplicaSet, if you go off and look for it). You can't override it.
鉴于您显示的YAML,我希望这个片段:
Given the YAML you've shown, I'd expect that this fragment:
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ template "project1234.module5678.fullname" . }}
扩展为chartname-project1234-module5678
的部署名称;其余的位由ReplicaSet添加,然后由Pod本身添加.
expands out to a Deployment name of chartname-project1234-module5678
; the remaining bits are added in by the ReplicaSet and then the Pod itself.
如果您确实查看Pod和kubectl describe pod chartname-project1234-module5678-dc7db787-skqvv
,您可能会发现它只有一个容器,其预期名称为project1234-module5678-pod
.几乎唯一需要使用此功能的时间是在多容器容器中需要kubectl logs
(或更常见的是kubectl exec
)时;如果是这种情况,则最好使用一个较短的名称,并且由于容器名称始终限于显示它们的特定容器的范围,因此在此处使用简短的固定名称没有任何问题
If you do look up the Pod and kubectl describe pod chartname-project1234-module5678-dc7db787-skqvv
you will probably see that it has a single container that has the expected name project1234-module5678-pod
. Pretty much the only time you need to use this is if you need to kubectl logs
(or, more rarely, kubectl exec
) in a multi-container pod; if you are in this case, you'll appreciate having a shorter name, and since the container names are always scoped to the specific pod in which they appear, there's nothing wrong with using a short fixed name here
spec:
containers:
- name: container
这篇关于为什么不使用部署模板中定义的名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!