k8s笔记7.4--helm构建无端口类型chart

k8s笔记7.4--helm构建无端口类型chart

介绍

helm create chartName 后,默认创建了一个web类型的应用,而且配置了service 和 端口探测;如果直接更换为无端口的worker 类型应用,那么部署就报错了。因此需要调整helm chart文件,是指无端口和service 配置,然后再打包部署。
本文以busybox 为例,打包一个无端口的helm chart,并部署到 k8s 中。

无端口chart

  1. 创建chart
    helm create xg-busybox
    
  2. 清理无用的配置项
    1. values.yaml 中设置ingress 为false
    2. eployment.yaml 中去掉端口相关的配置 containers.ports
    3. 去掉配置文件 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 }}
    
  3. 打包部署
    # 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
    
    此时可以发现已经正常更新服务 xg-busybox-dev了。

注意事项

  1. helm 打包无端口的服务一定要去掉service.yaml, 且需要关闭端口和服务相关的配置。
  2. 实际部署的时候最好区分 dev-values.yaml(开发测试环境) 和 prod-values.yaml(生产环境),以达到一个chart 匹配多种环境的目的。

说明

helm 版本 v3.6.1
helm 官方文档

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

昕光xg

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值