Basic use of helm package manager of container orchestration system k8s (2)

Time:2021-11-25

Previously, we introduced the terms related to helm and how to use helm to install and uninstall applications. For review, please refer to:https://www.cnblogs.com/qiuhom-1874/p/14305902.html; Today, let’s introduce the topics related to the use of custom chart, packaged chart, helm and other commands and the construction of private helm warehouse;

Following the previous blog, we learned about using helm to install and uninstall applications on k8s, as well as adding, deleting and updating warehouses; For helm chart, it is a packaged file that publishes the configuration lists we need in the form of templates. When users use it, they can define the corresponding attribute values from the line according to the values.yaml file. Of course, they can also use the — set option to specify the attribute values of individual configuration lists; Then, we use the helm command to install the application from the warehouse. Where is the corresponding package file? By default, we use the helm command to install the application, which will store the chart package file of the corresponding application in the. Cache / helm / repository / directory of the current user’s home directory, a compressed package ending in. Tgz; as follows

Tip: as long as we have used the helm install command to install the application in the above directory, the corresponding chart package file will be downloaded here;

View the corresponding packaging directory structure

[[email protected] ~]# ll .cache/helm/repository/
total 6520
-rw-r--r-- 1 root root     865 Jan 21 02:23 bitnami-charts.txt
-rw-r--r-- 1 root root 6555926 Jan 21 02:23 bitnami-index.yaml
-rw-r--r-- 1 root root    4381 Jan 20 23:19 redis
-rw-r--r-- 1 root root   31909 Jan 20 22:54 redis-10.5.7.tgz
-rw-r--r-- 1 root root   72791 Jan 21 02:26 redis-12.6.2.tgz
[[email protected] ~]# cp .cache/helm/repository/redis-12.6.2.tgz .
[[email protected] ~]# ls
redis-12.6.2.tgz
[[email protected] ~]# tar xf redis-12.6.2.tgz 
[[email protected] ~]# ls
redis  redis-12.6.2.tgz
[[email protected] ~]# tree redis
redis
├── Chart.lock
├── charts
│   └── common
│       ├── Chart.yaml
│       ├── README.md
│       ├── templates
│       │   ├── _affinities.tpl
│       │   ├── _capabilities.tpl
│       │   ├── _errors.tpl
│       │   ├── _images.tpl
│       │   ├── _ingress.tpl
│       │   ├── _labels.tpl
│       │   ├── _names.tpl
│       │   ├── _secrets.tpl
│       │   ├── _storage.tpl
│       │   ├── _tplvalues.tpl
│       │   ├── _utils.tpl
│       │   ├── validations
│       │   │   ├── _cassandra.tpl
│       │   │   ├── _mariadb.tpl
│       │   │   ├── _mongodb.tpl
│       │   │   ├── _postgresql.tpl
│       │   │   ├── _redis.tpl
│       │   │   └── _validations.tpl
│       │   └── _warnings.tpl
│       └── values.yaml
├── Chart.yaml
├── ci
│   ├── default-values.yaml
│   ├── extra-flags-values.yaml
│   └── production-sentinel-values.yaml
├── img
│   ├── redis-cluster-topology.png
│   └── redis-topology.png
├── README.md
├── templates
│   ├── configmap-scripts.yaml
│   ├── configmap.yaml
│   ├── headless-svc.yaml
│   ├── health-configmap.yaml
│   ├── _helpers.tpl
│   ├── metrics-prometheus.yaml
│   ├── metrics-svc.yaml
│   ├── networkpolicy.yaml
│   ├── NOTES.txt
│   ├── pdb.yaml
│   ├── prometheusrule.yaml
│   ├── psp.yaml
│   ├── redis-master-statefulset.yaml
│   ├── redis-master-svc.yaml
│   ├── redis-node-statefulset.yaml
│   ├── redis-rolebinding.yaml
│   ├── redis-role.yaml
│   ├── redis-serviceaccount.yaml
│   ├── redis-slave-statefulset.yaml
│   ├── redis-slave-svc.yaml
│   ├── redis-with-sentinel-svc.yaml
│   └── secret.yaml
├── values.schema.json
└── values.yaml

7 directories, 53 files
[[email protected] ~]# 

Note: the charts directory is mainly used to store other chart files that the corresponding chart depends on; The chart.yaml file is mainly used to describe the metadata information of the corresponding chart, such as the version, name, profile, etc; The CI directory is used to store the values.yaml file of various environments. By default, the values file is not specified, and the corresponding effective file is the values.yaml file; IMG directory is mainly used to store the icons corresponding to chart in the warehouse; The readme.md file is used to describe the usage of the chart, deployment manual and other information; The template directory is mainly used to store all the resource list files required for the deployment of the chart to release. The resource list file in this directory is not the resource list file we used earlier. Its format is the resource list written in the go template language. When using, we must combine the values defined in values.yaml, It can only be used normally after it is rendered by the template engine; The values.yaml file is mainly used to describe the default values of the corresponding attributes in the corresponding resource template list. Generally, the values file is not specified. The values applied by chart come from the values.yaml file. Of course, you can specify the values of the corresponding attributes through — set, or manually edit the values file. You can also specify the corresponding value file with — values or – f option;

Create custom chart command help

[[email protected] ~]# helm create -h

This command creates a chart directory along with the common files and
directories used in a chart.

For example, 'helm create foo' will create a directory structure that looks
something like this:

    foo/
    ├── .helmignore   # Contains patterns to ignore when packaging Helm charts.
    ├── Chart.yaml    # Information about your chart
    ├── values.yaml   # The default values for your templates
    ├── charts/       # Charts that this chart depends on
    └── templates/    # The template files
        └── tests/    # The test files

'helm create' takes a path for an argument. If directories in the given path
do not exist, Helm will attempt to create them as it goes. If the given
destination exists and there are files in that directory, conflicting files
will be overwritten, but other files will be left alone.

Usage:
  helm create NAME [flags]

Flags:
  -h, --help             help for create
  -p, --starter string   the name or absolute path to Helm starter scaffold

Global Flags:
      --debug                       enable verbose output
      --kube-apiserver string       the address and the port for the Kubernetes API server
      --kube-as-group stringArray   group to impersonate for the operation, this flag can be repeated to specify multiple groups.
      --kube-as-user string         username to impersonate for the operation
      --kube-ca-file string         the certificate authority file for the Kubernetes API server connection
      --kube-context string         name of the kubeconfig context to use
      --kube-token string           bearer token used for authentication
      --kubeconfig string           path to the kubeconfig file
  -n, --namespace string            namespace scope for this request
      --registry-config string      path to the registry config file (default "/root/.config/helm/registry.json")
      --repository-cache string     path to the file containing cached repository indexes (default "/root/.cache/helm/repository")
      --repository-config string    path to the file containing repository names and URLs (default "/root/.config/helm/repositories.yaml")
[[email protected] ~]# 

Example: create a chart of myapp

[[email protected] ~]# helm create myapp
Creating myapp
[[email protected] ~]# ls
myapp  redis  redis-12.6.2.tgz
[[email protected] ~]# tree myapp/
myapp/
├── charts
├── Chart.yaml
├── templates
│   ├── deployment.yaml
│   ├── _helpers.tpl
│   ├── hpa.yaml
│   ├── ingress.yaml
│   ├── NOTES.txt
│   ├── serviceaccount.yaml
│   ├── service.yaml
│   └── tests
│       └── test-connection.yaml
└── values.yaml

3 directories, 10 files
[[email protected] ~]# 

View the contents of chart.yaml file

[[email protected] ~]# cat myapp/Chart.yaml 
apiVersion: v2
name: myapp
description: A Helm chart for Kubernetes

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "1.16.0"
[[email protected] ~]# 

Note: the chart.yaml file is mainly used to describe the relevant attribute information of the corresponding chart. The apiversion field is used to describe the API version used by the corresponding chart. The default is V2 version; The name field is used to describe the name of the corresponding chart; The description field is used to describe the description and introduction of the corresponding chart; The type field describes whether the corresponding chart is an application or a library file. The chart of the application type can be run as a release, but the chart of the library type cannot be run as a release. It can only be used as a dependent chart of the application type; The version field is used to describe the corresponding chart version; The appVersion field is used to describe the version information of the corresponding chart internal program;

View template file

[[email protected] ~]# ll myapp/templates/
total 28
-rw-r--r-- 1 root root 1826 Jan 21 14:44 deployment.yaml
-rw-r--r-- 1 root root 1762 Jan 21 14:44 _helpers.tpl
-rw-r--r-- 1 root root  910 Jan 21 14:44 hpa.yaml
-rw-r--r-- 1 root root 1052 Jan 21 14:44 ingress.yaml
-rw-r--r-- 1 root root 1739 Jan 21 14:44 NOTES.txt
-rw-r--r-- 1 root root  316 Jan 21 14:44 serviceaccount.yaml
-rw-r--r-- 1 root root  355 Jan 21 14:44 service.yaml
drwxr-xr-x 2 root root   34 Jan 21 14:44 tests
[[email protected] ~]# cat myapp/templates/deployment.yaml 
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "myapp.fullname" . }}
  labels:
    {{- include "myapp.labels" . | nindent 4 }}
spec:
  {{- if not .Values.autoscaling.enabled }}
  replicas: {{ .Values.replicaCount }}
  {{- end }}
  selector:
    matchLabels:
      {{- include "myapp.selectorLabels" . | nindent 6 }}
  template:
    metadata:
      {{- with .Values.podAnnotations }}
      annotations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      labels:
        {{- include "myapp.selectorLabels" . | nindent 8 }}
    spec:
      {{- with .Values.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      serviceAccountName: {{ include "myapp.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 }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          ports:
            - name: http
              containerPort: 80
              protocol: TCP
          livenessProbe:
            httpGet:
              path: /
              port: http
          readinessProbe:
            httpGet:
              path: /
              port: http
          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 }}
[[email protected] ~]# 

Tip: the deployment list template file is mainly written in the go template language, where {{include “myapp. Fullname.”}} means to take the full name of myapp; {{. Values. Image. Repository}} This code means reading the value of the image.repository field in the values file in the current directory; {{. Values. Image. Tag | default. Chart. AppVersion}} indicates the value of image.tag in the values file or read the value of appVersion field in the default.chart file; To put it simply, the go template is to use the corresponding go template syntax to define the values of related attributes; Generally, the values of the corresponding fields are loaded from the values.yaml file as the values of the relevant attributes of the template file;

Value references in the values file

[[email protected] ~]# cat myapp/values.yaml 
# Default values for myapp.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

replicaCount: 1

image:
  repository: nginx
  pullPolicy: IfNotPresent
  # Overrides the image tag whose default is the chart appVersion.
  tag: ""

imagePullSecrets: []
nameOverride: ""
fullnameOverride: ""

serviceAccount:
  # Specifies whether a service account should be created
  create: true
  # Annotations to add to the service account
  annotations: {}
  # The name of the service account to use.
  # If not set and create is true, a name is generated using the fullname template
  name: ""

podAnnotations: {}

podSecurityContext: {}
  # fsGroup: 2000

securityContext: {}
  # capabilities:
  #   drop:
  #   - ALL
  # readOnlyRootFilesystem: true
  # runAsNonRoot: true
  # runAsUser: 1000

service:
  type: ClusterIP
  port: 80

ingress:
  enabled: false
  annotations: {}
    # kubernetes.io/ingress.class: nginx
    # kubernetes.io/tls-acme: "true"
  hosts:
    - host: chart-example.local
      paths: []
  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

autoscaling:
  enabled: false
  minReplicas: 1
  maxReplicas: 100
  targetCPUUtilizationPercentage: 80
  # targetMemoryUtilizationPercentage: 80

nodeSelector: {}

tolerations: []

affinity: {}
[[email protected] ~]# 

Tip: for example, if we want to reference the value of the tag field under the image field in the values.yaml file, we can write it as {{. Values. Image. Tag}} in the template file; If we use the — set option on the command line to apply, we can write it as image.tag; To modify the corresponding value, you can directly edit the value of the corresponding field in the corresponding values.yaml file, or you can directly use — set to specify the corresponding value of the corresponding field; By default, the values given by using the — set option on the command line will be directly replaced. If there is no given value, the default value given in the values.yaml file will still be used by default;

Example: modifying values in the values.yaml file

[[email protected] ~]# cat myapp/values.yaml
# Default values for myapp.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

replicaCount: 1

image:
  repository: ikubernetes/myapp
  pullPolicy: IfNotPresent
  # Overrides the image tag whose default is the chart appVersion.
  tag: "v1"

imagePullSecrets: []
nameOverride: ""
fullnameOverride: ""

serviceAccount:
  # Specifies whether a service account should be created
  create: true
  # Annotations to add to the service account
  annotations: {}
  # The name of the service account to use.
  # If not set and create is true, a name is generated using the fullname template
  name: ""

podAnnotations: {}

podSecurityContext: {}
  # fsGroup: 2000

securityContext: {}
  # capabilities:
  #   drop:
  #   - ALL
  # readOnlyRootFilesystem: true
  # runAsNonRoot: true
  # runAsUser: 1000

service:
  type: ClusterIP
  port: 80

ingress:
  enabled: false
  annotations: {}
    # kubernetes.io/ingress.class: nginx
    # kubernetes.io/tls-acme: "true"
  hosts:
    - host: chart-example.local
      paths: []
  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

autoscaling:
  enabled: false
  minReplicas: 1
  maxReplicas: 100
  targetCPUUtilizationPercentage: 80
  # targetMemoryUtilizationPercentage: 80

nodeSelector: {}

tolerations: []

affinity: {}
[[email protected] ~]# 

Tip: in the above values.yaml file, we modified the value of image.repository to ikubernets / myapp and image.tag to V1; This means that the image warehouse of the corresponding chart user is ikubernets / myapp warehouse; Version V1; Then modify the resources field; The corresponding resource restriction configuration is added;

Check whether the syntax of the corresponding values file is correct?

[[email protected] ~]# helm  lint ./myapp/
==> Linting ./myapp/
[INFO] Chart.yaml: icon is recommended
[ERROR] values.yaml: unable to parse YAML: error converting YAML to JSON: yaml: line 60: did not find expected key
[ERROR] templates/: cannot load values.yaml: error converting YAML to JSON: yaml: line 60: did not find expected key
[ERROR] : unable to load chart
        cannot load values.yaml: error converting YAML to JSON: yaml: line 60: did not find expected key

Error: 1 chart(s) linted, 1 chart(s) failed
[[email protected] ~]# 

Tip: check the configuration syntax of the values file. You can use the helm lint command to specify the directory of the corresponding chart; The above inspection results tell us that there is a problem with the 60 line configuration of values.yaml;

Tip: in the above values file, the corresponding configuration is given after the resource field, and the corresponding {} can no longer be used. Using {} means to leave the resource field blank; Therefore, we only need to delete the corresponding braces;

Remove the braces from the resource field and check the syntax of values again

[[email protected] ~]# helm  lint ./myapp/  
==> Linting ./myapp/
[INFO] Chart.yaml: icon is recommended

1 chart(s) linted, 0 chart(s) failed
[[email protected] ~]# 

Prompt: as long as there is no wrong class information in the above inspection process, it indicates that the values syntax is correct; At this point, we can use the chart we created manually to deploy as a release;

Modify the information in chart.yaml and deploy myapp chart as a release

[[email protected] ~]# cat ./myapp/Chart.yaml
apiVersion: v2
name: myapp
description: web server

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "v1"
[[email protected] ~]# 

Apply myapp chart

[[email protected] ~]# helm install myapp-v1 ./myapp/ 
NAME: myapp-v1
LAST DEPLOYED: Thu Jan 21 15:15:52 2021
NAMESPACE: default
STATUS: deployed
REVISION: 1
NOTES:
1. Get the application URL by running these commands:
  export POD_NAME=$(kubectl get pods --namespace default -l "app.kubernetes.io/name=myapp,app.kubernetes.io/instance=myapp-v1" -o jsonpath="{.items[0].metadata.name}")
  export CONTAINER_PORT=$(kubectl get pod --namespace default $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
  echo "Visit http://127.0.0.1:8080 to use your application"
  kubectl --namespace default port-forward $POD_NAME 8080:$CONTAINER_PORT
[[email protected] ~]#

Tip: to deploy a custom chart, use helm install to specify the corresponding release name and the directory where the chart is located;

View release

[[email protected] ~]# helm list
NAME            NAMESPACE       REVISION        UPDATED                                 STATUS          CHART           APP VERSION
myapp-v1        default         1               2021-01-21 15:15:52.57286036 +0800 CST  deployed        myapp-0.1.0     v1         
redis           default         1               2021-01-21 02:26:26.13324987 +0800 CST  deployed        redis-12.6.2    6.0.10     
redis-demo      default         1               2021-01-21 01:58:18.20798703 +0800 CST  deployed        redis-12.6.2    6.0.10     
[[email protected] ~]# 

Check whether the corresponding pod is running normally? Is the corresponding service created normally?

Tip: you can see that the corresponding pod and SVC are created normally;

Upgrade release

Change the contents of the chart.yaml file

[[email protected] ~]# cat myapp/Chart.yaml
apiVersion: v2
name: myapp
description: web server

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.2.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "v2"
[[email protected] ~]# 

Change the version of the corresponding image in the values.yaml file

[[email protected] ~]# cat myapp/values.yaml
# Default values for myapp.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

replicaCount: 1

image:
  repository: ikubernetes/myapp
  pullPolicy: IfNotPresent
  # Overrides the image tag whose default is the chart appVersion.
  tag: "v2"

imagePullSecrets: []
nameOverride: ""
fullnameOverride: ""

serviceAccount:
  # Specifies whether a service account should be created
  create: true
  # Annotations to add to the service account
  annotations: {}
  # The name of the service account to use.
  # If not set and create is true, a name is generated using the fullname template
  name: ""

podAnnotations: {}

podSecurityContext: {}
  # fsGroup: 2000

securityContext: {}
  # capabilities:
  #   drop:
  #   - ALL
  # readOnlyRootFilesystem: true
  # runAsNonRoot: true
  # runAsUser: 1000

service:
  type: ClusterIP
  port: 80

ingress:
  enabled: false
  annotations: {}
    # kubernetes.io/ingress.class: nginx
    # kubernetes.io/tls-acme: "true"
  hosts:
    - host: chart-example.local
      paths: []
  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

autoscaling:
  enabled: false
  minReplicas: 1
  maxReplicas: 100
  targetCPUUtilizationPercentage: 80
  # targetMemoryUtilizationPercentage: 80

nodeSelector: {}

tolerations: []

affinity: {}
[[email protected] ~]# 

Use the upgrade command to upgrade release

[[email protected] ~]# helm list
NAME            NAMESPACE       REVISION        UPDATED                                 STATUS          CHART           APP VERSION
myapp-v1        default         1               2021-01-21 15:15:52.57286036 +0800 CST  deployed        myapp-0.1.0     v1         
redis           default         1               2021-01-21 02:26:26.13324987 +0800 CST  deployed        redis-12.6.2    6.0.10     
redis-demo      default         1               2021-01-21 01:58:18.20798703 +0800 CST  deployed        redis-12.6.2    6.0.10     
[[email protected] ~]# helm upgrade --set service.type="NodePort" myapp-v1 ./myapp/ 
Release "myapp-v1" has been upgraded. Happy Helming!
NAME: myapp-v1
LAST DEPLOYED: Thu Jan 21 15:24:22 2021
NAMESPACE: default
STATUS: deployed
REVISION: 2
NOTES:
1. Get the application URL by running these commands:
  export NODE_PORT=$(kubectl get --namespace default -o jsonpath="{.spec.ports[0].nodePort}" services myapp-v1)
  export NODE_IP=$(kubectl get nodes --namespace default -o jsonpath="{.items[0].status.addresses[0].address}")
  echo http://$NODE_IP:$NODE_PORT
[[email protected] ~]# helm list
NAME            NAMESPACE       REVISION        UPDATED                                 STATUS          CHART           APP VERSION
myapp-v1        default         2               2021-01-21 15:24:22.882236621 +0800 CST deployed        myapp-0.2.0     v2         
redis           default         1               2021-01-21 02:26:26.13324987 +0800 CST  deployed        redis-12.6.2    6.0.10     
redis-demo      default         1               2021-01-21 01:58:18.20798703 +0800 CST  deployed        redis-12.6.2    6.0.10     
[[email protected] ~]# kubectl get pods
NAME                        READY   STATUS        RESTARTS   AGE
myapp-v1-7c9d7c999f-8k6rm   0/1     Terminating   0          8m47s
myapp-v1-866b6d4cc6-nx87c   1/1     Running       0          16s
redis-demo-master-0         1/1     Running       1          13h
redis-demo-slave-0          1/1     Running       2          13h
redis-demo-slave-1          1/1     Running       7          13h
redis-master-0              1/1     Running       1          12h
redis-slave-0               1/1     Running       1          12h
redis-slave-1               1/1     Running       1          12h
[[email protected] ~]# kubectl get svc
NAME                  TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGE
kubernetes            ClusterIP   10.96.0.1                443/TCP        15h
myapp-v1              NodePort    10.110.153.241           80:32434/TCP   8m53s
redis-demo-headless   ClusterIP   None                     6379/TCP       13h
redis-demo-master     ClusterIP   10.109.45.70             6379/TCP       13h
redis-demo-slave      ClusterIP   10.111.222.218           6379/TCP       13h
redis-headless        ClusterIP   None                     6379/TCP       12h
redis-master          ClusterIP   10.108.35.165            6379/TCP       12h
redis-slave           ClusterIP   10.99.96.166             6379/TCP       12h
[[email protected] ~]#

Tip: you can see that the corresponding myapp-v1pod and SVC have changed;

Verify: view the version information of the corresponding pod

[[email protected] ~]# kubectl describe pods myapp-v1-866b6d4cc6-nx87c |grep Image
    Image:          ikubernetes/myapp:v2
    Image ID:       docker-pullable://ikubernetes/[email protected]:85a2b81a62f09a414ea33b74fb8aa686ed9b168294b26b4c819df0be0712d358
[[email protected] ~]# 

Of course, if the update operation changes less information, we can also directly use the — set option in the command to specify the value of the corresponding attribute for update, as shown below

[[email protected] ~]# helm list
NAME            NAMESPACE       REVISION        UPDATED                                 STATUS          CHART           APP VERSION
myapp-v1        default         2               2021-01-21 15:24:22.882236621 +0800 CST deployed        myapp-0.2.0     v2         
redis           default         1               2021-01-21 02:26:26.13324987 +0800 CST  deployed        redis-12.6.2    6.0.10     
redis-demo      default         1               2021-01-21 01:58:18.20798703 +0800 CST  deployed        redis-12.6.2    6.0.10     
[[email protected] ~]# helm upgrade --set image.tag="v3" myapp-v1 ./myapp/
Release "myapp-v1" has been upgraded. Happy Helming!
NAME: myapp-v1
LAST DEPLOYED: Thu Jan 21 15:29:46 2021
NAMESPACE: default
STATUS: deployed
REVISION: 3
NOTES:
1. Get the application URL by running these commands:
  export POD_NAME=$(kubectl get pods --namespace default -l "app.kubernetes.io/name=myapp,app.kubernetes.io/instance=myapp-v1" -o jsonpath="{.items[0].metadata.name}")
  export CONTAINER_PORT=$(kubectl get pod --namespace default $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
  echo "Visit http://127.0.0.1:8080 to use your application"
  kubectl --namespace default port-forward $POD_NAME 8080:$CONTAINER_PORT
[[email protected] ~]# helm list
NAME            NAMESPACE       REVISION        UPDATED                                 STATUS          CHART           APP VERSION
myapp-v1        default         3               2021-01-21 15:29:46.491467084 +0800 CST deployed        myapp-0.2.0     v2         
redis           default         1               2021-01-21 02:26:26.13324987 +0800 CST  deployed        redis-12.6.2    6.0.10     
redis-demo      default         1               2021-01-21 01:58:18.20798703 +0800 CST  deployed        redis-12.6.2    6.0.10     
[[email protected] ~]# 

Tip: manually use the command line option – set to update. We need to modify the information in the corresponding chart in advance. Otherwise, as above, we have not modified the information in the corresponding file, and it still retains the original information;

Verify: check whether the version of the corresponding pod has been updated?

[[email protected] ~]# kubectl get pods
NAME                        READY   STATUS    RESTARTS   AGE
myapp-v1-675d685ddf-nn2zd   1/1     Running   0          106s
redis-demo-master-0         1/1     Running   1          13h
redis-demo-slave-0          1/1     Running   2          13h
redis-demo-slave-1          1/1     Running   7          13h
redis-master-0              1/1     Running   1          13h
redis-slave-0               1/1     Running   1          13h
redis-slave-1               1/1     Running   1          13h
[[email protected] ~]# kubectl describe pods/myapp-v1-675d685ddf-nn2zd |grep Image
    Image:          ikubernetes/myapp:v3
    Image ID:       docker-pullable://ikubernetes/[email protected]:b8d74db2515d3c1391c78c5768272b9344428035ef6d72158fd9f6c4239b2c69
[[email protected] ~]# kubectl get svc
NAME                  TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)    AGE
kubernetes            ClusterIP   10.96.0.1                443/TCP    15h
myapp-v1              ClusterIP   10.110.153.241           80/TCP     16m
redis-demo-headless   ClusterIP   None                     6379/TCP   13h
redis-demo-master     ClusterIP   10.109.45.70             6379/TCP   13h
redis-demo-slave      ClusterIP   10.111.222.218           6379/TCP   13h
redis-headless        ClusterIP   None                     6379/TCP   13h
redis-master          ClusterIP   10.108.35.165            6379/TCP   13h
redis-slave           ClusterIP   10.99.96.166             6379/TCP   13h
[[email protected] ~]#

Tip: the above command line option specifies that the version update of the corresponding image is successful; The corresponding SVC does not specify its type, which is also the default type used;

Rollback release

[[email protected] ~]# helm list       
NAME            NAMESPACE       REVISION        UPDATED                                 STATUS          CHART           APP VERSION
myapp-v1        default         3               2021-01-21 15:29:46.491467084 +0800 CST deployed        myapp-0.2.0     v2         
redis           default         1               2021-01-21 02:26:26.13324987 +0800 CST  deployed        redis-12.6.2    6.0.10     
redis-demo      default         1               2021-01-21 01:58:18.20798703 +0800 CST  deployed        redis-12.6.2    6.0.10     
[[email protected] ~]# helm rollback myapp-v1 2
Rollback was a success! Happy Helming!
[[email protected] ~]# helm list
NAME            NAMESPACE       REVISION        UPDATED                                 STATUS          CHART           APP VERSION
myapp-v1        default         4               2021-01-21 15:33:58.389015959 +0800 CST deployed        myapp-0.2.0     v2         
redis           default         1               2021-01-21 02:26:26.13324987 +0800 CST  deployed        redis-12.6.2    6.0.10     
redis-demo      default         1               2021-01-21 01:58:18.20798703 +0800 CST  deployed        redis-12.6.2    6.0.10     
[[email protected] ~]# helm rollback myapp-v1 2
Rollback was a success! Happy Helming!
[[email protected] ~]# helm rollback myapp-v1 1
Rollback was a success! Happy Helming!
[[email protected] ~]# helm history myapp-v1
REVISION        UPDATED                         STATUS          CHART           APP VERSION     DESCRIPTION     
1               Thu Jan 21 15:15:52 2021        superseded      myapp-0.1.0     v1              Install complete
2               Thu Jan 21 15:24:22 2021        superseded      myapp-0.2.0     v2              Upgrade complete
3               Thu Jan 21 15:29:46 2021        superseded      myapp-0.2.0     v2              Upgrade complete
4               Thu Jan 21 15:33:58 2021        superseded      myapp-0.2.0     v2              Rollback to 2   
5               Thu Jan 21 15:36:08 2021        superseded      myapp-0.2.0     v2              Rollback to 2   
6               Thu Jan 21 15:36:26 2021        deployed        myapp-0.1.0     v1              Rollback to 1   
[[email protected] ~]# helm rollback myapp-v1 1
Rollback was a success! Happy Helming!
[[email protected] ~]# helm history myapp-v1   
REVISION        UPDATED                         STATUS          CHART           APP VERSION     DESCRIPTION     
1               Thu Jan 21 15:15:52 2021        superseded      myapp-0.1.0     v1              Install complete
2               Thu Jan 21 15:24:22 2021        superseded      myapp-0.2.0     v2              Upgrade complete
3               Thu Jan 21 15:29:46 2021        superseded      myapp-0.2.0     v2              Upgrade complete
4               Thu Jan 21 15:33:58 2021        superseded      myapp-0.2.0     v2              Rollback to 2   
5               Thu Jan 21 15:36:08 2021        superseded      myapp-0.2.0     v2              Rollback to 2   
6               Thu Jan 21 15:36:26 2021        superseded      myapp-0.1.0     v1              Rollback to 1   
7               Thu Jan 21 15:38:21 2021        deployed        myapp-0.1.0     v1              Rollback to 1   
[[email protected] ~]# helm rollback myapp-v1 3
Rollback was a success! Happy Helming!
[[email protected] ~]# helm history myapp-v1   
REVISION        UPDATED                         STATUS          CHART           APP VERSION     DESCRIPTION     
1               Thu Jan 21 15:15:52 2021        superseded      myapp-0.1.0     v1              Install complete
2               Thu Jan 21 15:24:22 2021        superseded      myapp-0.2.0     v2              Upgrade complete
3               Thu Jan 21 15:29:46 2021        superseded      myapp-0.2.0     v2              Upgrade complete
4               Thu Jan 21 15:33:58 2021        superseded      myapp-0.2.0     v2              Rollback to 2   
5               Thu Jan 21 15:36:08 2021        superseded      myapp-0.2.0     v2              Rollback to 2   
6               Thu Jan 21 15:36:26 2021        superseded      myapp-0.1.0     v1              Rollback to 1   
7               Thu Jan 21 15:38:21 2021        superseded      myapp-0.1.0     v1              Rollback to 1   
8               Thu Jan 21 15:40:38 2021        deployed        myapp-0.2.0     v2              Rollback to 3   
[[email protected] ~]# 

Tip: for rollback operation, we need to specify the corresponding rollback location, which is represented by a number, which is the serial number of the corresponding historical version; For example, when rolling back to the version with serial number 2, use helm rollback myapp-v1 2; If you roll back to the version with version number 3, change the corresponding subsequent version number to 3; Rollback according to this logic; To view the version history of the corresponding release, you can use helm history release_ Name to view; At the end of the above command, we will roll to the version with serial number 3, which corresponds to the version of the application V3;

Verify: check whether the corresponding pod program version is V3?

[[email protected] ~]# kubectl get pods
NAME                        READY   STATUS    RESTARTS   AGE
myapp-v1-675d685ddf-7c8zd   1/1     Running   0          11m
redis-demo-master-0         1/1     Running   1          13h
redis-demo-slave-0          1/1     Running   2          13h
redis-demo-slave-1          1/1     Running   7          13h
redis-master-0              1/1     Running   1          13h
redis-slave-0               1/1     Running   1          13h
redis-slave-1               1/1     Running   1          13h
[[email protected]master01 ~]# kubectl describe pods/myapp-v1-675d685ddf-7c8zd |grep Image
    Image:          ikubernetes/myapp:v3
    Image ID:       docker-pullable://ikubernetes/[email protected]:b8d74db2515d3c1391c78c5768272b9344428035ef6d72158fd9f6c4239b2c69
[[email protected] ~]# 

Tip: you can see that the image version used by the corresponding pod is V3;

View the status of myapp-v1

[[email protected] ~]# helm status myapp-v1
NAME: myapp-v1
LAST DEPLOYED: Thu Jan 21 15:40:38 2021
NAMESPACE: default
STATUS: deployed
REVISION: 8
NOTES:
1. Get the application URL by running these commands:
  export POD_NAME=$(kubectl get pods --namespace default -l "app.kubernetes.io/name=myapp,app.kubernetes.io/instance=myapp-v1" -o jsonpath="{.items[0].metadata.name}")
  export CONTAINER_PORT=$(kubectl get pod --namespace default $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
  echo "Visit http://127.0.0.1:8080 to use your application"
  kubectl --namespace default port-forward $POD_NAME 8080:$CONTAINER_PORT
[[email protected] ~]# 

Tip: the helm status command is equivalent to rendering the notes.txt file in the template directory in the corresponding chart and outputting it to the user; This content mainly tells the user how to connect and use the corresponding chart, the status information of the corresponding chart, etc;

Use the command to view the contents of readme file, chart.yaml file and values file

[[email protected] ~]# helm show readme 
[[email protected] ~]# helm show readme myapp/
[[email protected] ~]# helm show chart myapp/ 
apiVersion: v2
appVersion: v2
description: web server
name: myapp
type: application
version: 0.2.0

[[email protected] ~]# helm show values myapp/
# Default values for myapp.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

replicaCount: 1

image:
  repository: ikubernetes/myapp
  pullPolicy: IfNotPresent
  # Overrides the image tag whose default is the chart appVersion.
  tag: "v2"

imagePullSecrets: []
nameOverride: ""
fullnameOverride: ""

serviceAccount:
  # Specifies whether a service account should be created
  create: true
  # Annotations to add to the service account
  annotations: {}
  # The name of the service account to use.
  # If not set and create is true, a name is generated using the fullname template
  name: ""

podAnnotations: {}

podSecurityContext: {}
  # fsGroup: 2000

securityContext: {}
  # capabilities:
  #   drop:
  #   - ALL
  # readOnlyRootFilesystem: true
  # runAsNonRoot: true
  # runAsUser: 1000

service:
  type: ClusterIP
  port: 80

ingress:
  enabled: false
  annotations: {}
    # kubernetes.io/ingress.class: nginx
    # kubernetes.io/tls-acme: "true"
  hosts:
    - host: chart-example.local
      paths: []
  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

autoscaling:
  enabled: false
  minReplicas: 1
  maxReplicas: 100
  targetCPUUtilizationPercentage: 80
  # targetMemoryUtilizationPercentage: 80

nodeSelector: {}

tolerations: []

affinity: {}

[[email protected] ~]# 

Note: there is no readme.md file in the corresponding chart, and the corresponding content cannot be obtained by using the helm show readme command;

View the contents of the template file in the template directory

[[email protected] ~]# helm template myapp/
---
# Source: myapp/templates/serviceaccount.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
  name: RELEASE-NAME-myapp
  labels:
    helm.sh/chart: myapp-0.2.0
    app.kubernetes.io/name: myapp
    app.kubernetes.io/instance: RELEASE-NAME
    app.kubernetes.io/version: "v2"
    app.kubernetes.io/managed-by: Helm
---
# Source: myapp/templates/service.yaml
apiVersion: v1
kind: Service
metadata:
  name: RELEASE-NAME-myapp
  labels:
    helm.sh/chart: myapp-0.2.0
    app.kubernetes.io/name: myapp
    app.kubernetes.io/instance: RELEASE-NAME
    app.kubernetes.io/version: "v2"
    app.kubernetes.io/managed-by: Helm
spec:
  type: ClusterIP
  ports:
    - port: 80
      targetPort: http
      protocol: TCP
      name: http
  selector:
    app.kubernetes.io/name: myapp
    app.kubernetes.io/instance: RELEASE-NAME
---
# Source: myapp/templates/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: RELEASE-NAME-myapp
  labels:
    helm.sh/chart: myapp-0.2.0
    app.kubernetes.io/name: myapp
    app.kubernetes.io/instance: RELEASE-NAME
    app.kubernetes.io/version: "v2"
    app.kubernetes.io/managed-by: Helm
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: myapp
      app.kubernetes.io/instance: RELEASE-NAME
  template:
    metadata:
      labels:
        app.kubernetes.io/name: myapp
        app.kubernetes.io/instance: RELEASE-NAME
    spec:
      serviceAccountName: RELEASE-NAME-myapp
      securityContext:
        {}
      containers:
        - name: myapp
          securityContext:
            {}
          image: "ikubernetes/myapp:v2"
          imagePullPolicy: IfNotPresent
          ports:
            - name: http
              containerPort: 80
              protocol: TCP
          livenessProbe:
            httpGet:
              path: /
              port: http
          readinessProbe:
            httpGet:
              path: /
              port: http
          resources:
            limits:
              cpu: 100m
              memory: 128Mi
            requests:
              cpu: 100m
              memory: 128Mi
---
# Source: myapp/templates/tests/test-connection.yaml
apiVersion: v1
kind: Pod
metadata:
  name: "RELEASE-NAME-myapp-test-connection"
  labels:
    helm.sh/chart: myapp-0.2.0
    app.kubernetes.io/name: myapp
    app.kubernetes.io/instance: RELEASE-NAME
    app.kubernetes.io/version: "v2"
    app.kubernetes.io/managed-by: Helm
  annotations:
    "helm.sh/hook": test
spec:
  containers:
    - name: wget
      image: busybox
      command: ['wget']
      args: ['RELEASE-NAME-myapp:80']
  restartPolicy: Never
[[email protected] ~]# 

Tip: the above list is the result of rendering through the template engine combined with the values defined in the values file;

Download the chart file from the warehouse to the local

Tip: if you want to download the corresponding chart file, you can use the pull command, which will download the packed file of the corresponding chart to the local warehouse; Your server cannot connect to the warehouse normally. Please use an agent; Above;

Get the extended information of the installed release

[[email protected] ~]# helm list
NAME            NAMESPACE       REVISION        UPDATED                                 STATUS          CHART           APP VERSION
myapp-v1        default         8               2021-01-21 15:40:38.060295891 +0800 CST deployed        myapp-0.2.0     v2         
redis           default         1               2021-01-21 02:26:26.13324987 +0800 CST  deployed        redis-12.6.2    6.0.10     
redis-demo      default         1               2021-01-21 01:58:18.20798703 +0800 CST  deployed        redis-12.6.2    6.0.10     
[[email protected] ~]# helm get values myapp-v1
USER-SUPPLIED VALUES:
image:
  tag: v3
[[email protected] ~]# helm get notes myapp-v1 
NOTES:
1. Get the application URL by running these commands:
  export POD_NAME=$(kubectl get pods --namespace default -l "app.kubernetes.io/name=myapp,app.kubernetes.io/instance=myapp-v1" -o jsonpath="{.items[0].metadata.name}")
  export CONTAINER_PORT=$(kubectl get pod --namespace default $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
  echo "Visit http://127.0.0.1:8080 to use your application"
  kubectl --namespace default port-forward $POD_NAME 8080:$CONTAINER_PORT

[[email protected] ~]# helm get hooks myapp-v1
---
# Source: myapp/templates/tests/test-connection.yaml
apiVersion: v1
kind: Pod
metadata:
  name: "myapp-v1-test-connection"
  labels:
    helm.sh/chart: myapp-0.2.0
    app.kubernetes.io/name: myapp
    app.kubernetes.io/instance: myapp-v1
    app.kubernetes.io/version: "v2"
    app.kubernetes.io/managed-by: Helm
  annotations:
    "helm.sh/hook": test
spec:
  containers:
    - name: wget
      image: busybox
      command: ['wget']
      args: ['myapp-v1:80']
  restartPolicy: Never
[[email protected] ~]# helm get manifest myapp-v1
---
# Source: myapp/templates/serviceaccount.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
  name: myapp-v1
  labels:
    helm.sh/chart: myapp-0.2.0
    app.kubernetes.io/name: myapp
    app.kubernetes.io/instance: myapp-v1
    app.kubernetes.io/version: "v2"
    app.kubernetes.io/managed-by: Helm
---
# Source: myapp/templates/service.yaml
apiVersion: v1
kind: Service
metadata:
  name: myapp-v1
  labels:
    helm.sh/chart: myapp-0.2.0
    app.kubernetes.io/name: myapp
    app.kubernetes.io/instance: myapp-v1
    app.kubernetes.io/version: "v2"
    app.kubernetes.io/managed-by: Helm
spec:
  type: ClusterIP
  ports:
    - port: 80
      targetPort: http
      protocol: TCP
      name: http
  selector:
    app.kubernetes.io/name: myapp
    app.kubernetes.io/instance: myapp-v1
---
# Source: myapp/templates/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp-v1
  labels:
    helm.sh/chart: myapp-0.2.0
    app.kubernetes.io/name: myapp
    app.kubernetes.io/instance: myapp-v1
    app.kubernetes.io/version: "v2"
    app.kubernetes.io/managed-by: Helm
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: myapp
      app.kubernetes.io/instance: myapp-v1
  template:
    metadata:
      labels:
        app.kubernetes.io/name: myapp
        app.kubernetes.io/instance: myapp-v1
    spec:
      serviceAccountName: myapp-v1
      securityContext:
        {}
      containers:
        - name: myapp
          securityContext:
            {}
          image: "ikubernetes/myapp:v3"
          imagePullPolicy: IfNotPresent
          ports:
            - name: http
              containerPort: 80
              protocol: TCP
          livenessProbe:
            httpGet:
              path: /
              port: http
          readinessProbe:
            httpGet:
              path: /
              port: http
          resources:
            limits:
              cpu: 100m
              memory: 128Mi
            requests:
              cpu: 100m
              memory: 128Mi

[[email protected] ~]# 

Tip: if you want to obtain all the above contents at one time, you can use the helm get all command to obtain them;

Package custom chart

[[email protected] ~]# ls
logstash-3.0.2.tgz  myapp  redis  redis-12.6.2.tgz
[[email protected] ~]# helm package ./myapp/
Successfully packaged chart and saved it to: /root/myapp-0.2.0.tgz
[[email protected] ~]# ls
logstash-3.0.2.tgz  myapp  myapp-0.2.0.tgz  redis  redis-12.6.2.tgz
[[email protected] ~]# 

Tip: after packing the chart file, we can put the corresponding file in the corresponding warehouse and share it with others;

Helm private warehouse construction

Helm private warehouse is essentially an HTTP file server. We only need to put the corresponding chart package file and the metadata information of the corresponding warehouse into the corresponding directory

Find a server to install nginx as the helm private repository

[[email protected]_registry ~]# yum install -y nginx

Generate Warehouse Metadata Information

[[email protected] ~]# mkdir repo-test
[[email protected] ~]# mv *.tgz repo-test/
[[email protected] ~]# ls
myapp  redis  repo-test
[[email protected] ~]# cd repo-test/
[[email protected] repo-test]# helm repo index . --url http://192.168.0.99/repo-test
[[email protected] repo-test]# ls
index.yaml  logstash-3.0.2.tgz  myapp-0.2.0.tgz  redis-12.6.2.tgz
[[email protected] repo-test]# cat index.yaml 
apiVersion: v1
entries:
  logstash:
  - annotations:
      category: LogManagement
    apiVersion: v2
    appVersion: 7.10.2
    created: "2021-01-21T16:43:51.585642435+08:00"
    dependencies:
    - name: common
      repository: https://charts.bitnami.com/bitnami
      tags:
      - bitnami-common
      version: 1.x.x
    description: Logstash is an open source, server-side data processing pipeline that ingests data from a multitude of sources simultaneously, transforms it, and then sends it to your favorite "stash".
    digest: b60ccc7d48acfbfafd6a226b32316fff173f7e17112cee8367c5680012bc37a1
    home: https://github.com/bitnami/charts/tree/master/bitnami/logstash
    icon: https://bitnami.com/assets/stacks/logstash/img/logstash-stack-220x234.png
    keywords:
    - logstash
    - logging
    - elk
    maintainers:
    - email: [email protected]
      name: Bitnami
    name: logstash
    sources:
    - https://github.com/bitnami/bitnami-docker-logstash
    - https://www.elastic.co/products/logstash
    urls:
    - http://192.168.0.99/repo-test/logstash-3.0.2.tgz
    version: 3.0.2
  myapp:
  - apiVersion: v2
    appVersion: v2
    created: "2021-01-21T16:43:51.586100842+08:00"
    description: web server
    digest: 55710394a8f2a8b0770c7212aaa92477adefebfbe72640d8c84e42c7999dd1d9
    name: myapp
    type: application
    urls:
    - http://192.168.0.99/repo-test/myapp-0.2.0.tgz
    version: 0.2.0
  redis:
  - annotations:
      category: Database
    apiVersion: v2
    appVersion: 6.0.10
    created: "2021-01-21T16:43:51.589712477+08:00"
    dependencies:
    - name: common
      repository: https://charts.bitnami.com/bitnami
      tags:
      - bitnami-common
      version: 1.x.x
    description: Open source, advanced key-value store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets and sorted sets.
    digest: 4208a6eae05c9486dbecc55db3bc6e04960708e0b389adfa1f7e309d3937a451
    home: https://github.com/bitnami/charts/tree/master/bitnami/redis
    icon: https://bitnami.com/assets/stacks/redis/img/redis-stack-220x234.png
    keywords:
    - redis
    - keyvalue
    - database
    maintainers:
    - email: [email protected]
      name: Bitnami
    - email: [email protected]
      name: desaintmartin
    name: redis
    sources:
    - https://github.com/bitnami/bitnami-docker-redis
    - http://redis.io/
    urls:
    - http://192.168.0.99/repo-test/redis-12.6.2.tgz
    version: 12.6.2
generated: "2021-01-21T16:43:51.568008766+08:00"
[[email protected] repo-test]# 

Copy the repo test directory to the web page root directory of the web server nginx

[[email protected] repo-test]# cd ..
[[email protected] ~]# scp -r repo-test 192.168.0.99:/usr/share/nginx/html/
[email protected]'s password: 
logstash-3.0.2.tgz                                                                                      100%   26KB   8.8MB/s   00:00    
myapp-0.2.0.tgz                                                                                         100% 3584   406.3KB/s   00:00    
redis-12.6.2.tgz                                                                                        100%   71KB  10.5MB/s   00:00    
index.yaml                                                                                              100% 2548   348.1KB/s   00:00    
[[email protected] ~]# ssh 192.168.0.99
[email protected]'s password: 
Last login: Thu Jan 21 16:35:28 2021 from 192.168.0.232
[[email protected]_registry ~]# ll /usr/share/nginx/html/
total 12
-rw-r--r-- 1 root root 3650 Nov  1 10:01 404.html
-rw-r--r-- 1 root root 3693 Nov  1 10:01 50x.html
lrwxrwxrwx 1 root root   20 Jan 21 16:36 en-US -> ../../doc/HTML/en-US
drwxr-xr-x 2 root root   27 Jan 21 16:36 icons
lrwxrwxrwx 1 root root   18 Jan 21 16:36 img -> ../../doc/HTML/img
lrwxrwxrwx 1 root root   25 Jan 21 16:36 index.html -> ../../doc/HTML/index.html
-rw-r--r-- 1 root root  368 Nov  1 10:01 nginx-logo.png
lrwxrwxrwx 1 root root   14 Jan 21 16:36 poweredby.png -> nginx-logo.png
drwxr-xr-x 2 root root   97 Jan 21 16:45 repo-test
[[email protected]_registry ~]# 

Start nginx service

[[email protected]_registry ~]# systemctl start nginx
[[email protected]_registry ~]# ss -tnl
State      Recv-Q Send-Q                        Local Address:Port                                       Peer Address:Port              
LISTEN     0      128                                       *:111                                                   *:*                  
LISTEN     0      128                                       *:80                                                    *:*                  
LISTEN     0      128                                       *:20048                                                 *:*                  
LISTEN     0      5                             192.168.122.1:53                                                    *:*                  
LISTEN     0      128                                       *:22                                                    *:*                  
LISTEN     0      128                            192.168.0.99:631                                                   *:*                  
LISTEN     0      100                               127.0.0.1:25                                                    *:*                  
LISTEN     0      64                                        *:45725                                                 *:*                  
LISTEN     0      128                                       *:36254                                                 *:*                  
LISTEN     0      64                                        *:2049                                                  *:*                  
LISTEN     0      128                                      :::111                                                  :::*                  
LISTEN     0      128                                      :::80                                                   :::*                  
LISTEN     0      128                                      :::20048                                                :::*                  
LISTEN     0      128                                      :::22                                                   :::*                  
LISTEN     0      100                                     ::1:25                                                   :::*                  
LISTEN     0      128                                      :::52761                                                :::*                  
LISTEN     0      64                                       :::2049                                                 :::*                  
LISTEN     0      64                                       :::43907                                                :::*                  
[[email protected]_registry ~]# 

Validation: add a private warehouse using Helm

[[email protected] ~]# helm repo add repo-test http://192.168.0.99/repo-test
"repo-test" has been added to your repositories
[[email protected] ~]# helm repo list
NAME            URL                               
bitnami         https://charts.bitnami.com/bitnami
repo-test       http://192.168.0.99/repo-test     
[[email protected] ~]# helm search repo repo-test
NAME                    CHART VERSION   APP VERSION     DESCRIPTION                                       
repo-test/logstash      3.0.2           7.10.2          Logstash is an open source, server-side data pr...
repo-test/myapp         0.2.0           v2              web server                                        
repo-test/redis         12.6.2          6.0.10          Open source, advanced key-value store. It is of...
[[email protected] ~]# 

Tip: you can see that the charts in the corresponding warehouse can be listed normally;

Install chart in private warehouse

[[email protected] ~]# helm install myapp-test repo-test/myapp
NAME: myapp-test
LAST DEPLOYED: Thu Jan 21 16:54:06 2021
NAMESPACE: default
STATUS: deployed
REVISION: 1
NOTES:
1. Get the application URL by running these commands:
  export POD_NAME=$(kubectl get pods --namespace default -l "app.kubernetes.io/name=myapp,app.kubernetes.io/instance=myapp-test" -o jsonpath="{.items[0].metadata.name}")
  export CONTAINER_PORT=$(kubectl get pod --namespace default $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
  echo "Visit http://127.0.0.1:8080 to use your application"
  kubectl --namespace default port-forward $POD_NAME 8080:$CONTAINER_PORT
[[email protected] ~]# helm list
NAME            NAMESPACE       REVISION        UPDATED                                 STATUS          CHART           APP VERSION
myapp-test      default         1               2021-01-21 16:54:06.041883984 +0800 CST deployed        myapp-0.2.0     v2         
myapp-v1        default         8               2021-01-21 15:40:38.060295891 +0800 CST deployed        myapp-0.2.0     v2         
redis           default         1               2021-01-21 02:26:26.13324987 +0800 CST  deployed        redis-12.6.2    6.0.10     
redis-demo      default         1               2021-01-21 01:58:18.20798703 +0800 CST  deployed        redis-12.6.2    6.0.10     
[[email protected] ~]# kubectl get pods 
NAME                          READY   STATUS    RESTARTS   AGE
myapp-test-58c57d75fc-s22cn   1/1     Running   0          31s
myapp-v1-675d685ddf-7c8zd     1/1     Running   0          73m
redis-demo-master-0           1/1     Running   1          14h
redis-demo-slave-0            1/1     Running   2          14h
redis-demo-slave-1            1/1     Running   7          14h
redis-master-0                1/1     Running   1          14h
redis-slave-0                 1/1     Running   1          14h
redis-slave-1                 1/1     Running   1          14h
[[email protected] ~]# kubectl get svc
NAME                  TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)    AGE
kubernetes            ClusterIP   10.96.0.1                443/TCP    17h
myapp-test            ClusterIP   10.108.7.220             80/TCP     39s
myapp-v1              ClusterIP   10.110.153.241           80/TCP     98m
redis-demo-headless   ClusterIP   None                     6379/TCP   14h
redis-demo-master     ClusterIP   10.109.45.70             6379/TCP   14h
redis-demo-slave      ClusterIP   10.111.222.218           6379/TCP   14h
redis-headless        ClusterIP   None                     6379/TCP   14h
redis-master          ClusterIP   10.108.35.165            6379/TCP   14h
redis-slave           ClusterIP   10.99.96.166             6379/TCP   14h
[[email protected] ~]# curl 10.108.7.220
Hello MyApp | Version: v2 | Pod Name
[[email protected] ~]#

Tip: you can see that the chart in the private warehouse can run normally as a release, and the corresponding generated SVC can also be accessed normally;

Use Alibaba cloud’s private helm warehouse

1. Entry:https://repomanage.rdc.aliyun.com/my/repo?spm=a2c4g.11186623.2.7.7b646b06Zv1cAd, log in to an alicloud account, register and open cloud services, and create an enterprise;

2. Create namespace

 

3. Add warehouse

4. Installing the helm push plug-in

[[email protected] ~]# helm plugin install https://github.com/chartmuseum/helm-push 
Downloading and installing helm-push v0.9.0 ...
https://github.com/chartmuseum/helm-push/releases/download/v0.9.0/helm-push_0.9.0_linux_amd64.tar.gz
Installed plugin: push
[[email protected] ~]# 

5. Publish chart directory

[[email protected] ~]# cat myapp/Chart.yaml 
apiVersion: v2
name: myapp
description: web server

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.2.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "v2"
[[email protected] ~]# helm push myapp/ $NAMESPACE
Pushing myapp-0.2.0.tgz to 136529-test...
Done.
[[email protected] ~]# 

6. Publish chart package file

[[email protected] ~]#  helm push repo-test/myapp-0.2.0.tgz $NAMESPACE
Pushing myapp-0.2.0.tgz to 136529-test...
Done.
[[email protected] ~]# 

Tip: if the custom chart is not packaged, please use helm package chart first_ Dir packaging;

7. Update local warehouse index

[[email protected] ~]# helm repo update
Hang tight while we grab the latest from your chart repositories...
...Successfully got an update from the "repo-test" chart repository
...Successfully got an update from the "bitnami" chart repository
...Successfully got an update from the "136529-test" chart repository
Update Complete. ⎈Happy Helming!⎈
[[email protected] ~]# 

Verification: search myapp to see if the corresponding warehouse can list the corresponding chart?

[[email protected] ~]# helm search repo myapp
NAME                    CHART VERSION   APP VERSION     DESCRIPTION
136529-test/myapp       0.2.0           v2              web server 
repo-test/myapp         0.2.0           v2              web server 
[[email protected] ~]# 

View the uploaded chart on Alibaba cloud

Verification: install myapp to see if the corresponding chart can run as a release?

Tip: you can see that you can download the corresponding chart from the corresponding helm warehouse and run it as a release on k8s;

Recommended Today

Apache sqoop

Source: dark horse big data 1.png From the standpoint of Apache, data flow can be divided into data import and export: Import: data import. RDBMS—–>Hadoop Export: data export. Hadoop—->RDBMS 1.2 sqoop installation The prerequisite for installing sqoop is that you already have a Java and Hadoop environment. Latest stable version: 1.4.6 Download the sqoop installation […]