k8s ~ helm build an application

Three concepts

  1. chart: contains the necessary information to create an application instance of Kubernetes
  2. config: contains application release configuration information
  3. release: is a running instance of a chart and its configuration

Create a helm charts

helm create hello-world
  • Chart.yaml is used to describe the relevant information of this Chart, including name, description information and version.
    Just some simple text descriptions

  • values.yaml is used to store the values ​​of variables used in template files in the templates directory.

  • NOTES.txt is used to introduce some information after the Chart is deployed, for example: how to use the Chart, list the default settings, etc.

  • Under the Templates directory are templates for YAML files, which follow the Go template syntax.

The values ​​of the YAML file templates in the Templates directory are all defined in values.yaml by default, such as the container image defined in deployment.yaml.
image: "{{.Values.image.repository}}: {{.Values.image.tag}}"
The value of .Values.image.repository is nginx, .Values.image. defined in values.yaml The value of tag is stable.
The above two variable values ​​are the default values ​​that are automatically generated when the chart is created, and you can modify them according to the actual situation. In fact, they are all static texts, which are only parsed when they are executed.

Build a helm application

Open Chart.yaml, you can see the following content, configuration name and version

apiVersion: v1
appVersion: "1.0"
description: A Helm chart for Kubernetes
name: mychart
version: 0.1.0

Edit values.yaml, it will deploy an Nginx on Kubernetes by default. The following is the content of the values.yaml file applied by mychart:

$ cat mychart/values.yaml
# Default values for mychart.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

replicaCount: 1

image:
  repository: nginx
  tag: stable
  pullPolicy: IfNotPresent

service:
  type: ClusterIP
  port: 80

ingress:
  enabled: false
  annotations: {}
    # kubernetes.io/ingress.class: nginx
    # kubernetes.io/tls-acme: "true"
  path: /
  hosts:
    - chart-example.local
  tls: []
  #  - secretName: chart-example-tls
  #    hosts:
  #      - chart-example.local

resources: {}
  # We usually recommend not to specify default resources and to leave this as a conscious
  # choice for the user. This also increases chances charts run on environments with little
  # resources, such as Minikube. If you do want to specify resources, uncomment the following
  # lines, adjust them as necessary, and remove the curly braces after 'resources:'.
  # limits:
  #  cpu: 100m
  #  memory: 128Mi
  # requests:
  #  cpu: 100m
  #  memory: 128Mi

nodeSelector: {}

tolerations: []

affinity: {}

Check module configuration

$ helm lint hello-world/

Bale

helm package hello-world
helm package mychart --debug #显示详细信息

Start helm local warehouse (helm3 has been removed)

helm serve  --repo-path /data/helm/repository/ --url http://172.17.0.22:8879/charts/ &

Warehouse refresh and query application

$ helm repo update
$ helm search mychart
NAME         	CHART VERSION	APP VERSION	DESCRIPTION
local/hello-world	0.1.0        	1.0        	A Helm chart for Kubernetes

Deploy applications in Kubernetes

After the chart is published to the warehouse, the chart can be deployed through the helm install command.

helm install  hello local/hello-world

View the status information of Release

 helm status wordpress

Upgrade charts

helm upgrade  wordpress stable/wordpress
helm upgrade --install --force hello-world ./hello.tgz --namespace test  # 也可以指定命名空间和它的taz包

Roll back to the previous version

helm rollback hello-world 1 # 向上归滚一个版本

Guess you like

Origin www.cnblogs.com/lori/p/12671586.html