Last class, we successfully installed the Helm client and Tiller Server. We also tried to create our first Helm Chart package by ourselves. In this class, we will learn some common operation methods of Helm with you.
warehouse
The Repo repository for Helm is similar to the Docker Registry. Chart library can be used to store and share the location where Chart is packaged. After installing Helm, the default repository address is an address in Google. For those of us who can’t access the Internet scientifically, we can’t access the official Chart warehouse. We can use helm Repo List to check the current warehouse configuration:
$helm repo list NAME local stable URL https://kubernetes-charts.storage.googleapis.com/ http://127.0.0.1:8879/chartsCopy the code
We can see that in addition to a default stable repository configuration, we also have a local local repository, which is one of the repository addresses we tested locally. In fact, it is very simple to create a Chart warehouse, which is an HTTP server with index. Yaml index file and any packaged Chart. For example, when we want to share a Chart package, Upload our local Chart package to the server so that others can use it, so in fact, it is very simple for us to host a Chart warehouse, such as Ali Cloud OSS, Github Pages, or even a simple server created by ourselves.
In order to solve the problem of scientific Internet access, I have built a Github Pages repository, which will automatically synchronize with the official repository every day, the address is: github.com/cnych/kube-… So we can change our Helm default warehouse address to our own warehouse address:
$ helm repo remove stable "stable" has been removed from your repositories $ helm repo add stable https://cnych.github.io/kube-charts-mirror/ "stable" has been added to your repositories $ helm repo list NAME URL Stable local https://cnych.github.io/kube-charts-mirror/ http://127.0.0.1:8879/charts $helm repo update Hang tight while we grab the latest from your chart repositories... . Skip local chart repository ... Successfully got an update from the "stable" chart repository update complet. ⎈ Happy Helming! ⎈Copy the code
After the warehouse is added, you can use the update command to update the warehouse. Of course, if we wanted to create a Web server to serve Helm Chart, we would only need to implement the following function points to provide the service:
- The index and
Chart
Put it in the server directory - Ensure index files
index.yaml
Can be accessed without authentication requirements - Ensure the correct content type of the YAML file (text/ YAMl or text/ X-YAMl)
If your Web service provides these functions, you can use it as a Helm Chart repository.
Find the chart
Helm installs the Charts package into the Kubernetes cluster. An instance of the installation is a new Release. To find the new Chart, we can search for the command.
Remember, if you can’t scientifically access the Internet, replace the default warehouse address for stable with the one we created above
To see which Charts are available, run helm Search directly:
$ helm search NAME CHART VERSION APP VERSION DESCRIPTION ... Stable /minio 1.6.3 RELEASE. 2018-08-25T01-56-38z Minio is a high performance distributed Object Storage SE... Stable /mission Control 0.4.2 3.1.2 A Helm Chart for JFrog Mission Control stable/mongodb 4.2.2 4.0.2 NoSQL document-oriented database that stores JSON-like do... Stable /mongodb-replicaset 3.5.6 3.6 NoSQL document-oriented database that stores json-like do... . Stable/ZetCD 0.1.9 0.0.3 CoreOS Zetcd Helm Chart for Kubernetes...Copy the code
Helm Search displays all available charts if no filtering criteria are used. You can narrow down the results of a search by using filter criteria:
$ helm search mysql NAME CHART VERSION APP VERSION DESCRIPTION ... Stable /mysql 0.10.1 5.7.14 Fast, reliable, Scalable, and Easy to use Open-source rel... Stable /mysqldump 0.1.0 5.7.21 A Helm chart to help backup MySQL databases using mysqldump Stable/Prometheus -mysql- 0.1.0v0.10.0 A Helm chart for Prometheus stable/ Mariadb 4.4.0 10.1.35 Fast, reliable, scalable, and easy to use open-source rel... .Copy the code
We can see that there are significantly fewer charts. Similarly, we can use the inspect command to view the details of a chart:
$helm inspect stable/mysql appVersion: 5.7.14 description: Fast, reliable, scalable, and easy to use open-source relational database system. engine: gotpl home: https://www.mysql.com/ icon: https://www.mysql.com/common/logos/logo-mysql-170x115.png keywords: - mysql - database - sql maintainers: - email: [email protected] name: olemarkus - email: [email protected] name: viglesiasce name: mysql sources: - https://github.com/kubernetes/charts - https://github.com/docker-library/mysql version: 0.10.1 - # # mysql image version # # ref: https://hub.docker.com/r/library/mysql/tags/ # # image: "mysql" imageTag: "5.7.14"...Copy the code
Use inspect command to view all description information in chart, including operation mode, configuration information and so on.
We can find the chart package we want through the helm search command, and then we can install it through the helm install command.
Install the chart
To install a new package, simply use the helm install command. In the simplest case, it takes only one chart name argument:
$ helm install stable/mysql NAME: mewing-squid LAST DEPLOYED: Tue Sep 4 23:31:23 2018 NAMESPACE: default STATUS: DEPLOYED RESOURCES: ==> v1/PersistentVolumeClaim NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE mewing-squid-mysql Pending 1s ==> V1 /Service NAME TYPE cluster-ip external-ip PORT(S) AGE mewing-squid-mysql ClusterIP 10.108.197.48 < None > 3306/tcp 1s ==> v1beta1/Deployment NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE mewing-squid-mysql 1 0 0 0 1s ==> v1/Pod(related) NAME READY STATUS RESTARTS AGE mewing-squid-mysql-69f587bdf9-z7glv 0/1 Pending 0 0s ==> v1/Secret NAME TYPE DATA AGE mewing-squid-mysql Opaque 2 1s ==> v1/ConfigMap NAME DATA AGE mewing-squid-mysql-test 1 1s NOTES: MySQL can be accessed via port 3306 on the following DNS name from within your cluster: mewing-squid-mysql.default.svc.cluster.local To get your root password run: MYSQL_ROOT_PASSWORD=$(kubectl get secret --namespace default mewing-squid-mysql -o jsonpath="{.data.mysql-root-password}" | base64 --decode; echo) To connect to your database: 1. Run an Ubuntu pod that you can use as a client: Kubectl run -i --tty ubuntu --image=ubuntu:16.04 --restart=Never -- bash-il 2. $ apt-get update && apt-get install mysql-client -y 3. Connect using the mysql cli, then provide your password: $ mysql -h mewing-squid-mysql -p To connect to your database directly from outside the K8s cluster: MYSQL_HOST=127.0.0.1 MYSQL_PORT=3306 # Execute the following command to route the connection: kubectl port-forward svc/mewing-squid-mysql 3306 mysql -h ${MYSQL_HOST} -P${MYSQL_PORT} -u root -p${MYSQL_ROOT_PASSWORD}Copy the code
Now that mysql Chart is installed, installing Chart creates a new Release object. The release above is named hmewing-squid. If you want to use your own release name, just specify it with the –name argument, as in:
$ helm install stable/mysql --name mydb
Copy the code
During installation, the Helm client prints useful information about which resources are created, the state of release, and other useful configuration information, such as how to access mysql services, get root’s password, and how to connect to mysql.
Note that Helm does not exit until all resources are running. Because many charts require very large mirroring resources, it can take a long time to install into a cluster.
To track release status or re-read configuration information, you can view it using helm Status:
$ helm status mewing-squid
LAST DEPLOYED: Tue Sep 4 23:31:23 2018
NAMESPACE: default
STATUS: DEPLOYED
RESOURCES:
...
Copy the code
You can see that the current Release is in the DEPLOYED state with some information from the installation below.
The custom chart
The above installation uses chart’s default configuration options. However, in most cases, we need to customize chart to meet our own needs. To customize chart, we need to know the configurable options supported by the chart we use.
To see the configurable options on chart, use the helm inspect values command.
$ helm inspect values stable/mysql ## mysql image version ## ref: https://hub.docker.com/r/library/mysql/tags/ ## image: "mysql" imageTag: "5.7.14" ## Specify password for root user ## ## Default: random 10 character string # mysqlRootPassword: testing ## Create a database user ## # mysqlUser: ## Default: random 10 character string # mysqlPassword: ## Allow unauthenticated access, uncomment to enable ## # mysqlAllowEmptyPassword: true ## Create a database ## # mysqlDatabase: ## Specify an imagePullPolicy (Required) ## It's recommended to change this to 'Always' if the image tag is 'latest' ## ref: http://kubernetes.io/docs/user-guide/images/#updating-images ## imagePullPolicy: IfNotPresent extraVolumes: | # - name: extras # emptyDir: {} extraVolumeMounts: | # - name: extras # mountPath: /usr/share/extras # readOnly: true extraInitContainers: | # - name: do-something # image: busybox # command: ['do', 'something'] # Optionally specify an array of imagePullSecrets. # Secrets must be manually created in the namespace. # ref: https://kubernetes.io/docs/concepts/containers/images/#specifying-imagepullsecrets-on-a-pod # imagePullSecrets: # - name: myRegistryKeySecretName ## Node selector ## ref: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#nodeselector nodeSelector: {} livenessProbe: initialDelaySeconds: 30 periodSeconds: 10 timeoutSeconds: 5 successThreshold: 1 failureThreshold: 3 readinessProbe: initialDelaySeconds: 5 periodSeconds: 10 timeoutSeconds: 1 successThreshold: 1 failureThreshold: 3 ## Persist data to a persistent volume persistence: enabled: true ## database data Persistent Volume Storage Class ## If defined, storageClassName: <storageClass> ## If set to "-", storageClassName: "", which disables dynamic provisioning ## If undefined (the default) or set to null, no storageClassName spec is ## set, choosing the default provisioner. (gp2 on AWS, standard on ## GKE, AWS & OpenStack) ## # storageClass: "-" accessMode: ReadWriteOnce size: 8Gi annotations: {} ## Configure resource requests and limits ## ref: http://kubernetes.io/docs/user-guide/compute-resources/ ## resources: requests: memory: 256Mi cpu: 100m # Custom mysql configuration files used to override default mysql settings configurationFiles: {} # mysql.cnf: |- # [mysqld] # skip-name-resolve # ssl-ca=/ssl/ca.pem # ssl-cert=/ssl/server-cert.pem # ssl-key=/ssl/server-key.pem # Custom mysql init SQL files used to initialize the database initializationFiles: {} # first-db.sql: |- # CREATE DATABASE IF NOT EXISTS first DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci; # second-db.sql: |- # CREATE DATABASE IF NOT EXISTS second DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci; Metrics: enabled: false image: PROM/mysqlD-mine imageTag: v0.10.0 imagePullPolicy: IfNotPresent resources: {} annotations: {} # prometheus.io/scrape: "true" # prometheus.io/port: "9104" livenessProbe: initialDelaySeconds: 15 timeoutSeconds: 5 readinessProbe: initialDelaySeconds: 5 timeoutSeconds: 1 ## Configure the service ## ref: http://kubernetes.io/docs/user-guide/services/ service: ## Specify a service type ## ref: https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services---service-types type: ClusterIP port: 3306 # nodePort: 32000 ssl: enabled: false secret: mysql-ssl-certs certificates: # - name: mysql-ssl-certs # ca: |- # -----BEGIN CERTIFICATE----- # ... # -----END CERTIFICATE----- # cert: |- # -----BEGIN CERTIFICATE----- # ... # -----END CERTIFICATE----- # key: |- # -----BEGIN RSA PRIVATE KEY----- # ... # -----END RSA PRIVATE KEY----- ## Populates the 'TZ' system timezone environment variable ## ref: https://dev.mysql.com/doc/refman/5.7/en/time-zone-support.html # # # # Default: nil (mysql will use image's default timezone, normally UTC) ## Example: 'Australia/Sydney' # timezone: # To be added to the database server pod(s) podAnnotations: {}Copy the code
We can then override any of the above configuration directly in a YAML file, which we use at installation time :(config.yaml)
mysqlUser: haimaxyUser
mysqlDatabase: haimaxyDB
service:
type: NodePort
Copy the code
Here we define mysqlUser and mysqlDatabase through the config.yaml file and change the service type to NodePort, and now we specify the yaml file directly when we install:
$ helm install -f config.yaml stable/mysql --name mydb NAME: mydb LAST DEPLOYED: Wed Sep 5 00:09:44 2018 NAMESPACE: default STATUS: DEPLOYED RESOURCES: ==> v1/Secret NAME TYPE DATA AGE mydb-mysql Opaque 2 1s ==> v1/ConfigMap NAME DATA AGE mydb-mysql-test 1 1s ==> v1/PersistentVolumeClaim NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE mydb-mysql Pending 1s ==> v1/Service NAME TYPE cluster-ip external-ip PORT(S) AGE mydb-mysql NodePort 10.96.150.198 < None > 3306:32604/TCP 0s ==> v1beta1/Deployment NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE mydb-mysql 1 1 1 0 0s ==> v1/Pod(related) NAME READY STATUS RESTARTS AGE mydb-mysql-dfc999888-hbw5d 0/1 Pending 0 0s ...Copy the code
We can see that the name of the current release has changed to myDB. Mydb = NodePort; mydb = NodePort;
$kubectl get SVC NAME TYPE cluster-ip external-ip PORT(S) AGE Kubernetes ClusterIP 10.96.0.1 < None > 443/TCP 110D Mewing-squid-mysql ClusterIP 10.108.197.48 < None > 3306/TCP 46m mydb-mysql NodePort 10.96.150.198 <none> 3306:32604/TCP 8mCopy the code
Mydb-mysql = ClusterIP; mydb-mysql = ClusterIP; mydb-mysql = ClusterIP; mydb-mysql = ClusterIP;
Let’s take a look at the Pod status:
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
mewing-squid-mysql-69f587bdf9-z7glv 0/1 Pending 0 49m
mydb-mysql-dfc999888-hbw5d 0/1 Pending 0 11m
Copy the code
Describe = Pending; describe = Pending; describe = Pending
$ kubectl describe pod mydb-mysql-dfc999888-hbw5d
Name: mydb-mysql-dfc999888-hbw5d
Namespace: default
Node: <none>
Labels: app=mydb-mysql
pod-template-hash=897555444
...
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Warning FailedScheduling 2m (x37 over 12m) default-scheduler pod has unbound PersistentVolumeClaims (repeated 2 times)
Copy the code
We can find that the two pods are in Pending state because the PVC is not bound, so we can solve this problem by using storageclass or manually creating a suitable PV object.
To illustrate the use of the helm update, we can disable data persistence directly in the config.yaml file above:
persistence:
enabled: false
Copy the code
Another way to override a value is to use –set during installation, such as to disable persistent data.
$ helm install stable/mysql --set persistence.enabled=false --name mydb
Copy the code
upgrade
Update myDB with data persistence disabled:
$ echo config.yaml
mysqlUser: haimaxyUser
mysqlDatabase: haimaxyDB
service:
type: NodePort
persistence:
enabled: false
$ helm upgrade -f config.yaml mydb stable/mysql
helm upgrade -f config.yaml mydb stable/mysql
Release "mydb" has been upgraded. Happy Helming!
LAST DEPLOYED: Wed Sep 5 00:38:33 2018
NAMESPACE: default
STATUS: DEPLOYED
RESOURCES:
...
Copy the code
Let’s see the DEPLOYED state now let’s look at the Pod state:
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
mewing-squid-mysql-69f587bdf9-z7glv 0/1 Pending 0 1h
mydb-mysql-6ffc84bbf6-lcn4d 0/1 PodInitializing 0 49s
...
Copy the code
Mydb = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
$ kubectl describe pod mydb-mysql-6ffc84bbf6-lcn4d Name: mydb-mysql-6ffc84bbf6-lcn4d Namespace: default Node: Node02/10.151.30.63 Start Time: Wed, 05 Sep 2018 00:38:33 +0800 Labels: app=mydb-mysql pod-template-hash=2997406692 Annotations: <none> Status: Pending ... Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal SuccessfulMountVolume 58s kubelet, node02 MountVolume.SetUp succeeded for volume "data" Normal SuccessfulMountVolume 58s kubelet, node02 MountVolume.SetUp succeeded for volume "default-token-n9w2d" Normal Scheduled 57s default-scheduler Successfully assigned mydb-mysql-6ffc84bbf6-lcn4d to node02 Normal Pulling 57s kubelet, Node02 pulling image "Busybox :1.25.0" Normal Pulled 45s kubelet, Node02 Successfully pulled image "busybox:1.25.0" Normal Created 44s kubelet, node02 Created container Normal Started 44s kubelet, node02 Started container Normal Pulling 41s kubelet, Node02 pulling image "mysql: 5.7.14"Copy the code
We can see that there is no error message about PVC now, because the data persistence is disabled in the version we just updated, proving that helm Upgrade and — values are in effect. Now we use the helm ls command to look at the current release:
$ helm ls
NAME REVISION UPDATED STATUS CHART APP VERSION NAMESPACE
mewing-squid 1 Tue Sep 4 23:31:23 2018 DEPLOYED mysql-0.10.1 5.7.14 default
mydb 2 Wed Sep 5 00:38:33 2018 DEPLOYED mysql-0.10.1 5.7.14 default
Copy the code
REVISION of myDB release has changed to 2. This is because the version of myDB release is incremented. Each installation, upgrade, or rollback increases the version number by 1, and the first REVISION is always 1. We can also use the helm history command to check the historical version of release:
$helm History MyDB REVISION UPDATED STATUS CHART DESCRIPTION 1 Wed Sep 5 00:09:44 2018 SUPERSEDED mysqL-0.10.1 Install Complete 2 Wed Sep 5 00:38:33 2018 DEPLOYED mysqL-0.10.1 Upgrade CompleteCopy the code
If we want to rollback to a certain version, we can use the helm rollback command. For example, we can rollback mydb to the previous version:
$ $ helm rollback mydb 1
Copy the code
delete
In the last class we learned that to delete a release we can use the helm delete command:
$ helm delete mewing-squid
release "mewing-squid" deleted
Copy the code
This will remove the release from the cluster, but that doesn’t mean it’s completely deleted. We can also use the –deleted parameter to indicate that the release was deleted:
$ helm list --deleted NAME REVISION UPDATED STATUS CHART APP VERSION NAMESPACE mewing-squid 1 Tue Sep 4 23:31:23 2018 DELETED mysql-0.10.1 5.7.14 Default $helm List -- All NAME REVISION UPDATED STATUS CHART APP VERSION NAMESPACE Mewing-squid 1 Tue Sep 4 23:31:23 2018 DELETED MYSQL-0.10.1 5.7.14 default myDB 2 Wed Sep 5 00:38:33 2018 DEPLOYED Mysql - 0.10.1 5.7.14 defaultCopy the code
Helm list –all shows all releases, including those that have been deleted
Because Helm keeps a record of deleted releases, the release name cannot be reused. (If you do need to reuse the release name, you can use this -replace parameter, but it only reuses an existing release and replaces its resources.) Is this similar to the management of Docker Container
Note that because release is saved this way, you can roll back the deleted resource and reactivate it.
To remove release completely, add the –purge parameter:
$ helm delete mewing-squid --purge
release "mewing-squid" deleted
Copy the code
We’ve just covered some of the common methods of Helm, and we’ll see more of them later in the course.
Finally, I would like to make an advertisement to recommend a high-quality course carefully created by myself, which is now in a limited time offer:Advanced from Docker to Kubernetes
Scan the QR code below (or wechat search)K8s technology circle
) Follow our wechat public account and reply to our wechat public accountAdd groupJoin our Kubernetes discussion group to learn more.