[root@k8s-master01 ~]# helm repo list NAME URL stable http://mirror.azure.cn/kubernetes/charts/
5.1.4 更新仓库
1 2 3 4
[root@k8s-master01 ~]# helm repo update Hang tight while we grab the latest from your chart repositories... ...Successfully got an update from the "stable" chart repository Update Complete. ⎈Happy Helming!⎈
5.2 查看charts
使用helm search repo 关键字可以查看相关charts
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
[root@k8s-master01 ~]# helm search repo stable NAME CHART VERSION APP VERSION DESCRIPTION stable/acs-engine-autoscaler2.2.22.1.1 DEPRECATED Scales worker nodes within agent pools stable/aerospike 0.3.5 v4.5.0.5 DEPRECATED A Helm chart for Aerospike in Kubern... stable/airflow 7.13.31.10.12 DEPRECATED - please use: https://github.com/air... stable/ambassador 5.3.20.86.1 DEPRECATED A Helm chart for Datawire Ambassador stable/anchore-engine1.7.00.7.3 Anchore container analysis and policy evaluatio... stable/apm-server2.1.77.0.0 DEPRECATED The server receives data from the El... stable/ark 4.2.20.10.2 DEPRECATED A Helm chart for ark stable/artifactory 7.3.26.1.0 DEPRECATED Universal Repository Manager support... stable/artifactory-ha0.4.26.2.0 DEPRECATED Universal Repository Manager support... stable/atlantis 3.12.4 v0.14.0 DEPRECATED A Helm chart for Atlantis https://ww... stable/auditbeat 1.1.26.7.0 DEPRECATED A lightweight shipper to audit the a... stable/aws-cluster-autoscaler0.3.4 DEPRECATED Scales worker nodes within autoscali... stable/aws-iam-authenticator0.1.51.0 DEPRECATED A Helm chart for aws-iam-authenticator stable/bitcoind 1.0.20.17.1 DEPRECATED Bitcoin is an innovative payment net... stable/bookstack 1.2.40.27.5 DEPRECATED BookStack is a simple, self-hosted, ... ......
1 2 3 4 5 6
[root@k8s-master01 ~]# helm search repo nginx NAME CHART VERSION APP VERSION DESCRIPTION stable/nginx-ingress1.41.3 v0.34.1 DEPRECATED! An nginx Ingress controller that us... stable/nginx-ldapauth-proxy0.1.61.13.5 DEPRECATED - nginx proxy with ldapauth stable/nginx-lego0.3.1 Chart for nginx-ingress-controller and kube-lego stable/gcloud-endpoints0.1.21 DEPRECATED Develop, deploy, protect and monitor...
1 2 3
[root@k8s-master01 ~]# helm search repo tomcat NAME CHART VERSION APP VERSION DESCRIPTION stable/tomcat 0.4.37.0 DEPRECATED - Deploy a basic tomcat application ...
5.3 部署应用 MySQL
环境说明:k8s集群中存在storageclass:nfs-client
我们现在安装一个 mysql 应用:
1 2 3
[root@k8s-master01 ~]# helm search repo mysql NAME CHART VERSION APP VERSION DESCRIPTION stable/mysql 1.6.95.7.30 DEPRECATED - Fast, reliable, scalable, and easy...
部署过程输出的信息: NAME: mysql-1658996042 LAST DEPLOYED: Thu Jul 2816:14:032022 NAMESPACE: default STATUS: deployed REVISION: 1 NOTES: MySQL can be accessed via port 3306 on the following DNS name from within your cluster: mysql-1658996042.default.svc.cluster.local
[root@k8s-master01 ~]# kubectl get pods NAME READY STATUS RESTARTS AGE mysql-1658996042-755f5f64f6-j5s671/1 Running 082s
1 2 3
[root@k8s-master01 ~]# kubectl get pvc NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE mysql-1658996042 Bound pvc-7fcb894e-5b8c-4f3e-945d-21b60b9309e58Gi RWO nfs-client93s
1 2 3
[root@k8s-master01 ~]# kubectl get pv NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE pvc-7fcb894e-5b8c-4f3e-945d-21b60b9309e58Gi RWO Delete Bound default/mysql-1658996042 nfs-client97s
[root@k8s-master01 ~]# helm ls NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION mysql-1658996042 default 12022-07-2816:14:03.530489788 +0800 CST deployed mysql-1.6.95.7.30 mysql-1658996297 default 12022-07-2816:18:19.282074215 +0800 CST deployed mysql-1.6.95.7.30
1 2 3 4 5
[root@k8s-master01 ~]# kubectl get pods NAME READY STATUS RESTARTS AGE mysql-1658996042-755f5f64f6-j5s671/1 Running 045m mysql-1658996297-75f6f86d84-5qd8r1/1 Running 041m nfs-client-provisioner-9d46587b5-7n2vf1/1 Running 0123m
root@mysql-1658996042-755f5f64f6-j5s67:/# mysql -uroot -ptest123 mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 547 Server version: 5.7.30 MySQL Community Server (GPL)
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.
Type'help;' or '\h'for help. Type'\c' to clear the current input statement.
[root@k8s-master01 ~]# kubectl get all -l release=mysql-1658996042 NAME READY STATUS RESTARTS AGE pod/mysql-1658996042-755f5f64f6-j5s671/1 Running 072m
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE service/mysql-1658996042 ClusterIP 10.96.2.136 <none> 3306/TCP 72m
NAME READY UP-TO-DATE AVAILABLE AGE deployment.apps/mysql-16589960421/11172m
NAME DESIRED CURRENT READY AGE replicaset.apps/mysql-1658996042-755f5f64f611172m
我们也可以 helm show chart 命令来了解 MySQL 这个 chart 包的一些特性:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
[root@k8s-master01 ~]# helm show chart stable/mysql apiVersion: v1 appVersion: 5.7.30 deprecated: true description: DEPRECATED - Fast, reliable, scalable, and easy to use open-source relational database system. home: https://www.mysql.com/ icon: https://www.mysql.com/common/logos/logo-mysql-170x115.png keywords: - mysql - database - sql name: mysql sources: - https://github.com/kubernetes/charts - https://github.com/docker-library/mysql version: 1.6.9
如果想要了解更多信息,可以用 helm show all 命令:
1 2
[root@k8s-master01 ~]# helm show all stable/mysql ......
[root@k8s-master01 ~]# helm ls NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION mysql-1605192239 default 1 ......... deployed mysql-1.6.95.7.30
[root@k8s-master01 ~]# helm ls -a NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION mysql-1605192239 default 1 ........ uninstalled mysql-1.6.95.7.30 状态为uninstalled
审查历史时甚至可以取消删除release。
Usage: helm rollback <RELEASE> [REVISION] [flags]
1 2 3 4 5 6 7
[root@k8s-master01 ~]# helm rollback mysql-1605192239 1 Rollback was a success! Happy Helming!
[root@k8s-master01 ~]# helm ls NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION mysql-1605192239 default 2 ......... deployed mysql-1.6.95.7.30 rollback后,又回到deployed状态
NAME: mysql LAST DEPLOYED: Fri Jul 2914:07:172022 NAMESPACE: default STATUS: deployed REVISION: 1 NOTES: MySQL can be accessed via port 3306 on the following DNS name from within your cluster: mysql.default.svc.cluster.local
To get your root password run:
MYSQL_ROOT_PASSWORD=$(kubectl get secret --namespace default 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
3. Connect using the mysql cli, then provide your password: $ mysql -h 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/mysql 3306
mysql -h${MYSQL_HOST} -P${MYSQL_PORT} -u root -p${MYSQL_ROOT_PASSWORD}
3, 查看覆盖的参数
1 2 3 4 5 6 7
# 这是查看除了默认的配置之外自己配置的,但是部署mysql的时候是--set指定的,如果是直接部署,没有任何的指定,获取values的值为空 [root@master ~]# helm get values mysql USER-SUPPLIED VALUES: mysqlDatabase: helm persistence: enabled: true storageClass: nfs-client
4, 查看部署的相关资源
1 2 3 4 5 6 7 8 9 10 11 12
[root@k8s-master01helmdir]# kubectl get all -l release=mysql NAME READY STATUS RESTARTS AGE pod/mysql-855976764d-npvgm1/1 Running 040m
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE service/mysql ClusterIP 10.96.0.84 <none> 3306/TCP 40m
NAME READY UP-TO-DATE AVAILABLE AGE deployment.apps/mysql 1/11140m
NAME DESIRED CURRENT READY AGE replicaset.apps/mysql-855976764d11140m
5, 查看pod的IP
1 2 3 4 5
[root@k8s-master01helmdir]# kubectl get pods -o wide -l release=mysql NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES mysql-855976764d-npvgm1/1 Running 041m 100.119.84.71 k8s-worker01 <none> <none>
得到pod的IP为100.119.84.71
6, 安装mysql客户端并连接测试
1
[root@k8s-master01 ~]# yum install mariadb -y
1 2 3
# 获取helm部署的mysql的root密码 [root@k8s-master01 ~]# kubectl get secret --namespace default mysql -o jsonpath="{.data.mysql-root-password}" | base64 --decode; echo wL2SD0RCsT
1 2 3 4
[root@k8s-master01 ~]# kubectl get svc NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 27h mysql ClusterIP 10.96.0.84 <none> 3306/TCP 5m21s
[root@k8s-master01helmdir]# kubectl get deployment mysql -o wide NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR mysql 1/11154m mysql mysql:5.7.30 app=mysql,release=mysql images版本为5.7.30
2,修改配置并升级
1 2 3 4 5
[root@k8s-master01helmdir]# vim mysql-config.yml mysqlDatabase: kubemsb persistence: enabled: true storageClass: nfs-client
升级并且加一个--set imageTag=5.7.31参数设置为5.7.31版本
1
[root@k8s-master01 ~]# helm upgrade mysql -f mysql-config.yml --set imageTag=5.7.31 stable/mysql
WARNING: This chart is deprecated Release "mysql" has been upgraded. Happy Helming! NAME: mysql LAST DEPLOYED: Fri Jul 2915:04:202022 NAMESPACE: default STATUS: deployed REVISION: 2 NOTES: MySQL can be accessed via port 3306 on the following DNS name from within your cluster: mysql.default.svc.cluster.local
To get your root password run:
MYSQL_ROOT_PASSWORD=$(kubectl get secret --namespace default 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
3. Connect using the mysql cli, then provide your password: $ mysql -h 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/mysql 3306
mysql -h${MYSQL_HOST} -P${MYSQL_PORT} -u root -p${MYSQL_ROOT_PASSWORD}
注意:更新过程中,密码会被更新,但是实际使用中,密码并未更新。
3, 升级后确认版本
1 2 3
[root@k8s-master01helmdir]# kubectl get deployment mysql -o wide NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR mysql 1/11158m mysql mysql:5.7.31 app=mysql,release=mysql
1 2 3
[root@k8s-master01helmdir]# kubectl get pods -o wide NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES mysql-6f57f64c9d-sc72v1/1 Running 02m20s 100.119.84.72 k8s-worker01 <none> <none>
[root@k8s-master01helmdir]# helm history mysql REVISION UPDATED STATUS CHART APP VERSION DESCRIPTION 1 Fri Jul 2914:07:172022 superseded mysql-1.6.95.7.30 Install complete 2 Fri Jul 2915:04:202022 deployed mysql-1.6.95.7.30 Upgrade complete
1 2
[root@k8s-master01helmdir]# helm rollback mysql 1 Rollback was a success! Happy Helming!
5, 验证
1 2 3
[root@k8s-master01helmdir]# kubectl get deployment mysql -o wide NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR mysql 1/11165m mysql mysql:5.7.30 app=mysql,release=mysql
1 2 3 4 5
[root@k8s-master01helmdir]# helm history mysql REVISION UPDATED STATUS CHART APP VERSION DESCRIPTION 1 Fri Jul 2914:07:172022 superseded mysql-1.6.95.7.30 Install complete 2 Fri Jul 2915:04:202022 superseded mysql-1.6.95.7.30 Upgrade complete 3 Fri Jul 2915:12:242022 deployed mysql-1.6.95.7.30 Rollback to 1