k8s笔记7.4--helm构建无端口类型chart
k8s笔记7.4--helm构建无端口类型chart介绍无端口chart注意事项说明介绍helm create chartName 后,默认创建了一个web类型的应用,而且配置了service 和 端口探测;如果直接更换为无端口的worker 类型应用,那么部署就报错了。因此需要调整helm chart文件,是指无端口和service 配置,然后再打包部署。本文以busybox 为例,打包一个无端
·
介绍
helm create chartName 后,默认创建了一个web类型的应用,而且配置了service 和 端口探测;如果直接更换为无端口的worker 类型应用,那么部署就报错了。因此需要调整helm chart文件,是指无端口和service 配置,然后再打包部署。
本文以busybox 为例,打包一个无端口的helm chart,并部署到 k8s 中。
无端口chart
- 创建chart
helm create xg-busybox - 清理无用的配置项
- values.yaml 中设置ingress 为false
- eployment.yaml 中去掉端口相关的配置 containers.ports
- 去掉配置文件 service.yaml
values.yaml replicaCount: 1 image: repository: registry-vpc.cn-shanghai.aliyuncs.com/yourNamespace/busybox pullPolicy: IfNotPresent # Overrides the image tag whose default is the chart appVersion. tag: busybox_1.31 imagePullSecrets: [{"name": "regcred"}] nameOverride: "" fullnameOverride: "" serviceAccount: create: true annotations: {} name: "" podAnnotations: {} podSecurityContext: {} # fsGroup: 2000 securityContext: {} service: type: ClusterIP port: 80 ingress: enabled: false className: "" annotations: {} hosts: - host: chart-example.local paths: - path: / pathType: ImplementationSpecific tls: [] resources: {} autoscaling: enabled: false minReplicas: 1 maxReplicas: 100 targetCPUUtilizationPercentage: 80 nodeSelector: {} tolerations: [] affinity: {} vim templates/deployment.yaml apiVersion: apps/v1 kind: Deployment metadata: name: {{ include "xg-busybox.fullname" . }} labels: {{- include "xg-busybox.labels" . | nindent 4 }} spec: {{- if not .Values.autoscaling.enabled }} replicas: {{ .Values.replicaCount }} {{- end }} selector: matchLabels: {{- include "xg-busybox.selectorLabels" . | nindent 6 }} template: metadata: {{- with .Values.podAnnotations }} annotations: {{- toYaml . | nindent 8 }} {{- end }} labels: {{- include "xg-busybox.selectorLabels" . | nindent 8 }} spec: {{- with .Values.imagePullSecrets }} imagePullSecrets: {{- toYaml . | nindent 8 }} {{- end }} serviceAccountName: {{ include "xg-busybox.serviceAccountName" . }} securityContext: {{- toYaml .Values.podSecurityContext | nindent 8 }} containers: - name: {{ .Chart.Name }} securityContext: {{- toYaml .Values.securityContext | nindent 12 }} image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" command: [sh, -c, 'sleep infinity'] imagePullPolicy: {{ .Values.image.pullPolicy }} resources: {{- toYaml .Values.resources | nindent 12 }} {{- with .Values.nodeSelector }} nodeSelector: {{- toYaml . | nindent 8 }} {{- end }} {{- with .Values.affinity }} affinity: {{- toYaml . | nindent 8 }} {{- end }} {{- with .Values.tolerations }} tolerations: {{- toYaml . | nindent 8 }} {{- end }} - 打包部署
此时可以发现已经正常更新服务 xg-busybox-dev了。# helm push xg-busybox/ bigdata-apps # helm repo update # helm upgrade xg-busybox-dev bigdata-apps/xg-busybox -f xg-busybox/dev-values.yaml --set=image.tag=busybox_1.31 -n sre-test # helm list -A|grep xg-busybox xg-busybox-dev sre-test 2 2021-08-21 17:09:41.318788496 +0800 CST deployed xg-busybox-0.1.4 1.31
注意事项
- helm 打包无端口的服务一定要去掉service.yaml, 且需要关闭端口和服务相关的配置。
- 实际部署的时候最好区分 dev-values.yaml(开发测试环境) 和 prod-values.yaml(生产环境),以达到一个chart 匹配多种环境的目的。
说明
helm 版本 v3.6.1
helm 官方文档
更多推荐



所有评论(0)