我是一個對Helm圖表完全陌生的人,但我已經成功地得到了一個帶有ApacheDS(LDAP服務器)的pod,并在上面運行。 我可以在其中執行shell操作,我可以登錄并從LDAP服務器獲得回應。
然而,從集群外,我得到了一個連接拒絕。 通過查詢,我 "認為 "我需要一個 NodePort。 Kube 檔案然而,我看不到該規格放在哪里。 我已經嘗試了很多方法,但就是得不到它。 根據檔案,我需要像這樣的東西:
spec:
型別: NodePort
選擇器:
app: MyApp
ports:
- port: 10389
targetPort: 10389
節點埠: 30007
這里是我的deployment.yaml:
apiVersion: apps/v1
kind: Deployment
metadata: Deployment
name: {{ include "buildchart.fullname" . }}} "buildchart.fullname" 。
標簽:
{{- include "buildchart.labs" 。 | nindent 4 }}.
spec:
{{- if not .Values.autoscaling.enabled }}.Values.autoscaling.enabled
replicas: {{ .Values.replicaCount }}.
{{- end }}}。
選擇器:
matchLabels:/span>
{{- include "buildchart.selectorLabels"/span> 。 | nindent 6 }}。
template:
metadata:/span>
{{- with .Values.podAnnotations }}}
注釋:
{{- toYaml . | nindent 8 }}.
{{- end }}}.
標簽:
{{- include "buildchart.selectorLabels"/span> 。 | nindent 8 }}。
spec:
imagePullSecrets:/span>
- name: {{ .Values.imagePullSecrets }}.
{{- end }}}。
serviceAccountName: {{ include "buildchart.serviceAccountName" 。}
securityContext:
{{- toYaml .Value. podSecurityContext | nindent 8 }}.
containers:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values. securityContext | nindent 12 }}.
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}.
port:
- name:admin-port
containerPort: 8080
hostPort: 8080
協議: TCP
- name:ldap-port
containerPort: 10389
hostPort: 10389
協議: UDP
有效性探針:
執行:
命令: 命令:
- curl ldap://localhost:10389/
initialDelaySeconds: {{ .Values.livenessProbe.initialDelaySeconds }}.
periodSeconds: {{ .Values.livenessProbe.periodSeconds }}.
readinessProbe:
exec:
命令:
- sh
- c
- curl ldap://localhost:10389/
initialDelaySeconds: {{ .Values.readinessProbe.initialDelaySeconds }}.
periodSeconds: {{ .Values.readinessProbe.periodSeconds }}.
資源:
{{- toYaml .Value. resources | nindent 12 }}.
{{- with .Values.nodeSelector }}}
nodeSelector:/span>
{{- toYaml . | nindent 8 }}.
{{- end }}}.
{{- with .Values.affinity }}.
親和力:
{{- toYaml . | nindent 8 }}.
{{- end }}}.
{{- with .Values.tolerance }}}
容忍度:
{{- toYaml . | nindent 8 }}.
{{- end }}}。
我如何向世界其他地區開放這個埠? 或者至少是容器所在的盒子。
uj5u.com熱心網友回復:
是的,你需要為你的部署創建一個服務。
另外,我建議你不要使用硬編碼,因為在values.yaml檔案中改變一個值比編輯模板檔案來添加一個新的硬編碼值更容易。
在deployment.yaml中設定:
.../span>
{{ if .Values.ports}}}}
ports:/span>
{{ 范圍 .Values.ports }}}
- name: {{ .name }}.
containerPort: {{ .containerPort }}.
protocol: {{ .protocol }}.
{{ 結束 }}}
{{ end }}}
...。
在values.yaml中設定:
ports:。
- name:/span> admin-port
containerPort: 8080
節點埠: 8080
協議: TCP
- name:ldap-port
containerPort: 10389
節點埠: 10389
協議: UDP
創建service.yaml檔案并設定
apiVersion: v1
kind: Service
metadata: 服務
name: {{ include "buildchart.fullname" . }}"buildchart.fullname" 。
標簽:
{{- include "buildchart.labs" 。 | nindent 4 }}。
spec:
type: {{ .Values.service.type }}spec:
ports:
{{ range .Values.ports }}**.
- port: {{ .nodePort }}.
targetPort: {{ .containerPort }}.
protocol: {{ .protocol }}.
name: {{ .name }}.
{{ end }}}。
選擇器:
{{- include "buildchart.selectorLabels" 。 | nindent 4 }}。
uj5u.com熱心網友回復:
你應該將其作為服務物件規格來添加,而不是在你的部署物件中。
例如,
apiVersion: v1
kind: Service
metadata: 服務
name: my-app-service
規格:
型別: NodePort
選擇器:
app: MyApp
ports:
- port: 10389
targetPort: 10389
節點埠: 30007
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/330608.html
標籤:
上一篇:如何獲得小部件的尺寸?
