helm3下载

github地址

  1. https://github.com/helm/helm

image.png

  1. wget https://get.helm.sh/helm-v3.3.4-linux-amd64.tar.gz
  1. tar xvf helm-v3.3.4-linux-amd64.tar.gz
  2. chmod +x linux-amd64/helm
  3. mv linux-amd64/helm /usr/bin/

38.helm3使用 - 图2

helm重要概念

Helm 重要概念:

  • charts:包含了创建Kubernetes的一个应用实例的必要信息
  • values:包含了应用发布配置信息
  • release:是一个 chart 及其配置的一个运行实例
  • repo:charts仓库,用于存储charts

    helm常用命令

    常用的项目
    1. https://artifacthub.io/

    repo

    1. helm repo --help
    image.png

    查看repo

    1. helm repo list
    image.png

    增加repo

    1. helm repo add bitnami https://charts.bitnami.com/bitnami
    image.png

    更新repo

    1. helm repo update
    image.png

    移除repo

    1. helm remove bitnami
    image.png

    search

    1. helm search --help
    image.png

    查看repo下面的包

    1. helm search repo
    image.png
    1. helm search repo mysql
    image.png

    show

    1. helm show --help
    image.png

查看charts所有信息

  1. helm show all stable/mysql

image.png

查看charts values信息

  1. helm show values stable/mysql

image.png

install

  1. helm install --help

image.png

-n 指定namespace

  1. helm install tomcat01 stable/tomcat -n test

image.png

—set 设values变量

  1. helm install tomcat02 stable/tomcat -n test --set hostPort=8010

image.png

list

  1. helm list --help

image.png

查看部署的项目

  1. helm list -n test

image.png

upgrade

  1. helm upgrade --help

image.png

更新一个项目

  1. helm upgrade tomcat01 stable/tomcat -n test --set hostPort=8011

image.png
image.png

status

  1. helm status --help

image.png

查看项目状态

  1. helm status tomcat01 -n test

image.png

delete

  1. helm delete --help

image.png

删除一个项目

  1. helm delete tomcat02 -n test

image.png

rollback

  1. helm rollback --help

image.png

回滚上一个项目

  1. helm rollback tomcat01 1 -n test

image.png

history

  1. helm history --help

image.png

查看项目历史记录

  1. helm history tomcat01 -n test

image.png

自定义chart

  1. helm create test

image.png

创建模板

把 templates 目录下面所有文件全部删除掉,来创建模板文件

  1. rm -rf test/templates/*

image.png

不加参数直接deployment

  1. cat > test/templates/deployment.yaml << EOF
  2. apiVersion: apps/v1
  3. kind: Deployment
  4. metadata:
  5. name: app-name-dev
  6. labels:
  7. app: app
  8. spec:
  9. replicas: 1
  10. strategy:
  11. rollingUpdate:
  12. maxSurge: 1
  13. maxUnavailable: 1
  14. selector:
  15. matchLabels:
  16. app: app
  17. app-name: app-name
  18. template:
  19. metadata:
  20. labels:
  21. app: app
  22. app-name: app-name
  23. spec:
  24. containers:
  25. - name: app-name
  26. image: tomcat:latest
  27. imagePullPolicy: Always
  28. readinessProbe:
  29. tcpSocket:
  30. port: 8080
  31. initialDelaySeconds: 50
  32. timeoutSeconds: 5
  33. periodSeconds: 3
  34. livenessProbe:
  35. tcpSocket:
  36. port: 8080
  37. initialDelaySeconds: 50
  38. timeoutSeconds: 5
  39. periodSeconds: 3
  40. ports:
  41. - name: http
  42. containerPort: 8080
  43. resources:
  44. limits:
  45. memory: 1Gi
  46. volumeMounts:
  47. - name: app
  48. mountPath: /opt/logs
  49. volumes:
  50. - name: app
  51. hostPath:
  52. path: /opt/logs
  53. type: DirectoryOrCreate
  54. EOF
  1. helm install app ./test

image.png

配置参数

  1. cat > test/templates/deployment.yaml << EOF
  2. apiVersion: apps/v1
  3. kind: Deployment
  4. metadata:
  5. name: {{ .Values.dev.appname }}-dev
  6. labels:
  7. app: {{ .Values.dev.app }}
  8. spec:
  9. replicas: 1
  10. strategy:
  11. rollingUpdate:
  12. maxSurge: 1
  13. maxUnavailable: 1
  14. selector:
  15. matchLabels:
  16. app: {{ .Values.dev.app }}
  17. app-name: {{ .Values.dev.appname }}
  18. template:
  19. metadata:
  20. labels:
  21. app: {{ .Values.dev.app }}
  22. app-name: {{ .Values.dev.appname }}
  23. spec:
  24. containers:
  25. - name: {{ .Values.dev.appname }}
  26. image: {{ .Values.container.image }}:{{ .Values.container.tag }}
  27. imagePullPolicy: Always
  28. readinessProbe:
  29. tcpSocket:
  30. port: {{ .Values.container.port }}
  31. initialDelaySeconds: 50
  32. timeoutSeconds: 5
  33. periodSeconds: 3
  34. livenessProbe:
  35. tcpSocket:
  36. port: 8080
  37. initialDelaySeconds: 50
  38. timeoutSeconds: 5
  39. periodSeconds: 3
  40. ports:
  41. - name: http
  42. containerPort: {{ .Values.container.port }}
  43. resources:
  44. limits:
  45. memory: {{ .Values.container.memory }}
  46. volumeMounts:
  47. - name: app
  48. mountPath: /opt/logs
  49. volumes:
  50. - name: app
  51. hostPath:
  52. path: /opt/logs
  53. type: DirectoryOrCreate
  54. EOF
  1. cat > test/values.yaml << EOF
  2. dev:
  3. app: tomcat
  4. appname: tomcat-8
  5. container:
  6. image: tomcat
  7. tag: latest
  8. port: 8080
  9. memory: 1Gi
  10. EOF
  1. helm install app01 ./test

image.png
image.png