kubernetes应用的包管理工具—Helm的安装、部署、构建Helm Chart、分发
文章目录
- kubernetes应用的包管理工具---Helm的安装、部署、构建Helm Chart、分发
- 1. 引入Helm的原因
- 1.1 没有使用Helm的部署
- 1.2 使用Helm部署
- 2. Helm核心概念
- 3. Helm架构
- 3.1 V2版本
- 3.2 V3版本
- 4. Helm安装
- 5. Helm仓库
- 5.1 Helm仓库管理
- 5.1.1 查看仓库
- 5.1.2 添加仓库
- 5.1.3 更新Helm仓库
- 5.1.4 删除仓库
- 6. Release
- 6.1 仓库中搜索Charts
- 6.2 通过Chart包部署mysql
- 6.2.1 随机名
- 6.2.2 自定义名
- 6.3 删除Release
- 6.4 定制参数部署应用
- 6.4.1 查看应用可以使用哪些参数
- 6.4.2 通过文件进行传值
- 6.4.3 查看应用创建时传了哪些值
- 6.4.4 查看Release所有相关资源
- 6.5 Release升级和回滚
- 6.5.1 Upgrade
- 6.5.2 rollback
- 7. Helm Chart包
- 7.1 本地chart包安装
- 7.2 远程chart包安装
- 8. Chart包配置
- 8.1 Chart目录结构
- 8.1.1 命令行创建
- 8.1.2 下载包
- 8.2 创建不可修改的Chart
- 8.3 Helm打包
- 8.4 常用Chart变量
- 8.5 创建可配置Chart
- 8.5.1 创建values.yaml
- 8.5.2 修改deployment
- 8.6 Harbor分发helm
- 8.6.1 打包helm
- 8.6.2 harbor配置
- 8.6.3 Linux环境上传helm包
官网helm.sh
Helm 是 Kubernetes 的包管理器.
作为CNCF毕业项目之一,Helm将Yaml作为一个整体进行管理并实现这些Yaml的高效复用,就像Linux中的yum和apt,它使我们能在k8s中方便快捷的安装,管理,卸载k8s应用.
helm是一个命令行客户端工具,主要用于k8s应用chart的创建,打包,发布和管理.
通过helm可以很方便的将之前打包好的Yaml文件部署到k8s环境上.
对于应用发布者而言,可以通过helm打包应用,管理应用的依赖关系,管理应用版本并发布到软件仓库.
对于使用者而言,使用Helm后不需要了解k8s的Yaml语法并编写应用部署文件,可以通过Helm下载并在k8s上安装需要的应用.
除此之外,helm还提供了k8s的软件部署,删除,升级,回滚应用的强大功能.
1. 引入Helm的原因
使用Kubernetes环境后需要写大量的重复的编写资源清单文件,这对使用人员有一定技术要求.为了降低这部分的技术要求,引入了helm
1.1 没有使用Helm的部署
在k8s环境下部署一个Nginx的服务需要经历以下步骤:
- 通过Dockerfile生成镜像,并上传harbor
- 编写deployment资源文件,并部署
kubectl create deployment --image=nginx nginx-dp-01 --dry-run=client -o yaml > nginx.yaml
kubectl apply -f nginx.yaml
- 编写service资源文件,并部署
kubectl expose deployment nginx-dp-01 --port=80 --target-port=80 --type=NodePort --dry-run=client -o yaml > service.yaml
kubectl apply -f service.yaml
-
编写pv,pvc,hpa,rbac等等其他资源文件,并部署(这里我么没有使用,略)
-
测试访问
root@ks-master:~/helm/yaml# kubectl get deploy,svc nginx-dp-01
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/nginx-dp-01 1/1 1 1 103s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/nginx-dp-01 NodePort 10.233.61.159 <none> 80:31755/TCP 93s
访问node节点31755端口
如果是微服务环境,10-20个微服务都要这样反复操作,显然是不合理的
1.2 使用Helm部署
2. Helm核心概念
Helm基于Go语言开发,用户只要提供贵的的目录结构和模板文件.在真正部署是Helm模板引擎可以将其渲染成真正的k8s资源文件,并安装正确的顺序将它们部署到节点上.
Helm定义了一套Chart格式来描述一个应用,打个比方,一个安卓程序打包成APK格式就可以安装到任意一台安卓手机上,如果把k8s环境比作安卓,k8s内应用就是安卓程序,那么Chart就可以比作APK.这就意味着,k8s集群只要打包成Chart,就可以通过Helm部署到任意一个k8s集群中
Helm中有三个重要概念,分别是Chart,Repository,Release.
- Chart代表Helm包.它包含在k8s集群内部运行应用程序,工具或服务所需的所有资源定义,为所有项目资源清单yaml文件的集合,采用TAR格式,可以类比成yum中的RPM.
- Repository就是用来存放和共享Chart的地方,可以类比为YUM仓库
- Release是运行在k8s集群中的Chart实例,一个Chart可以在一个集群中安装多次,Chart就像流水线中初始化好的模板,Release就是这个模板产出的各个产品
Helm作为k8s的包管理软件,每次安装Chart到K8s集群是,都会创建一个新的Release,你可以在Helm的Repository中寻找需要的Chart.
Helm对于部署过程的优化点在于简化了原先完成配置文件编写后还需要使用一串kubectl命令进行操作,统一管理了部署时可配置项以及方便了部署完成后的升级和维护.
3. Helm架构
3.1 V2版本
v2版本是需要在k8s集群中安装Tiller
3.2 V3版本
Helm客户端使用REST+JSON的方式与K8s中的apiserver进行交互,进而管理deployment,service等资源,并且用户端本身并不需要数据库,它会把相关信息存储在k8s集群内的secrets中.
4. Helm安装
本次实验使用helm3.11.3
在k8s集群节点上安装
wget https://get.helm.sh/helm-v3.11.3-linux-amd64.tar.gz
tar xf helm-v3.11.3-linux-amd64.tar.gz
\cp linux-amd64/helm /usr/local/bin/helm
确认版本
root@ks-master:~/helm# helm version
version.BuildInfo{Version:"v3.11.3", GitCommit:"323249351482b3bbfc9f5004f65d400aa70f9ae7", GitTreeState:"clean", GoVersion:"go1.20.3"}
5. Helm仓库
5.1 Helm仓库管理
5.1.1 查看仓库
root@ks-master:~/helm# helm repo list
Error: no repositories to show
此时没有仓库
5.1.2 添加仓库
# 微软
helm repo add microsoft http://mirror.azure.cn/kubernetes/charts/
# bitnami
helm repo add bitnami https://charts.bitnami.com/bitnami
# prometheus
helm repo add prometheus https://prometheus-community.github.io/helm-charts
查看结果
root@ks-master:~/helm# helm repo list
NAME URL
microsoft http://mirror.azure.cn/kubernetes/charts/
bitnami https://charts.bitnami.com/bitnami
prometheus https://prometheus-community.github.io/helm-charts
5.1.3 更新Helm仓库
root@ks-master:~/helm# helm repo update
Hang tight while we grab the latest from your chart repositories...
...Successfully got an update from the "prometheus" chart repository
...Successfully got an update from the "microsoft" chart repository
...Successfully got an update from the "bitnami" chart repository
Update Complete. ⎈Happy Helming!⎈
5.1.4 删除仓库
helm repo remove prometheus
查看结果
root@ks-master:~/helm# helm repo remove prometheus
"prometheus" has been removed from your repositories
root@ks-master:~/helm# helm repo list
NAME URL
microsoft http://mirror.azure.cn/kubernetes/charts/
bitnami https://charts.bitnami.com/bitnami
6. Release
6.1 仓库中搜索Charts
root@ks-master:~/helm# helm search repo mysql
NAME CHART VERSION APP VERSION DESCRIPTION
bitnami/mysql 9.9.1 8.0.33 MySQL is a fast, reliable, scalable, and easy t...
microsoft/mysql 1.6.9 5.7.30 DEPRECATED - Fast, reliable, scalable, and easy...
microsoft/mysqldump 2.6.2 2.4.1 DEPRECATED! - A Helm chart to help backup MySQL...
microsoft/prometheus-mysql-exporter 0.7.1 v0.11.0 DEPRECATED A Helm chart for prometheus mysql ex...
bitnami/phpmyadmin 11.1.1 5.2.1 phpMyAdmin is a free software tool written in P...
microsoft/percona 1.2.3 5.7.26 DEPRECATED - free, fully compatible, enhanced, ...
microsoft/percona-xtradb-cluster 1.0.8 5.7.19 DEPRECATED - free, fully compatible, enhanced, ...
microsoft/phpmyadmin 4.3.5 5.0.1 DEPRECATED phpMyAdmin is an mysql administratio...
bitnami/mariadb 12.2.3 10.11.3 MariaDB is an open source, community-developed ...
bitnami/mariadb-galera 8.2.1 10.11.3 MariaDB Galera is a multi-primary database clus...
microsoft/gcloud-sqlproxy 0.6.1 1.11 DEPRECATED Google Cloud SQL Proxy
microsoft/mariadb 7.3.14 10.3.22 DEPRECATED Fast, reliable, scalable, and easy t...
6.2 通过Chart包部署mysql
6.2.1 随机名
环境说明: k8s集群default空间下已经存在sc managed-nfs-storage
root@ks-master:~/helm# kubectl get sc
NAME PROVISIONER RECLAIMPOLICY VOLUMEBINDINGMODE ALLOWVOLUMEEXPANSION AGE
local (default) openebs.io/local Delete WaitForFirstConsumer false 53d
managed-nfs-storage (default) fuseim.pri/ifs Delete Immediate false 34d
从heml部署mysql
root@ks-master:~/helm# helm install microsoft/mysql --generate-name --set persistence.storageClass=managed-nfs-storage --set mysqlRootPassword=test123
WARNING: This chart is deprecated
NAME: mysql-1684127504
LAST DEPLOYED: Mon May 15 13:11:47 2023
NAMESPACE: default
STATUS: deployed
REVISION: 1
NOTES:
MySQL can be accessed via port 3306 on the following DNS name from within your cluster:
mysql-1684127504.default.svc.cluster.local
To get your root password run:
MYSQL_ROOT_PASSWORD=$(kubectl get secret --namespace default mysql-1684127504 -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. Install the mysql client:
$ apt-get update && apt-get install mysql-client -y
3. Connect using the mysql cli, then provide your password:
$ mysql -h mysql-1684127504 -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-1684127504 3306
mysql -h ${MYSQL_HOST} -P${MYSQL_PORT} -u root -p${MYSQL_ROOT_PASSWORD}
root@ks-master:~/helm# kubectl get pods
NAME READY STATUS RESTARTS AGE
busybox 1/1 Running 113 33d
mysql-1684127504-75495f88f6-tfc8t 0/1 Running 0 29s
nfs-client-provisioner-68c8fcd77-hg8hl 1/1 Running 19 34d
nginx-5458dbdbd4-bq48r 1/1 Running 0 10d
nginx-deployment-8f558f666-97tvr 1/1 Running 0 10d
nginx-deployment-8f558f666-g8c2c 1/1 Running 0 10d
nginx-dp-01-76bb89c887-9lhb4 1/1 Running 0 3h15m
static-web-ks-master 1/1 Running 1 11d
root@ks-master:~/helm# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.233.0.1 <none> 443/TCP 53d
mysql-1684127504 ClusterIP 10.233.5.57 <none> 3306/TCP 57s
nginx-dp-01 NodePort 10.233.61.159 <none> 80:31755/TCP 3h16m
root@ks-master:~/helm# kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
mysql-1684127504 Bound pvc-1f312c44-23c9-46a6-92dc-8a9c5f1d3306 8Gi RWO managed-nfs-storage 8m49s
查看helm部署的结果
root@ks-master:~/helm# helm list
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
mysql-1684127504 default 1 2023-05-15 13:11:47.613586278 +0800 CST deployed mysql-1.6.9 5.7.30
6.2.2 自定义名
root@ks-master:~/helm# helm install mysql_5_7 microsoft/mysql --set persistence.storageClass=managed-nfs-storage --set mysqlRootPassword=test123
WARNING: This chart is deprecated
Error: INSTALLATION FAILED: release name "mysql_5_7": invalid release name, must match regex ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$ and the length must not be longer than 53
root@ks-master:~/helm# helm install mysql-57 microsoft/mysql --set persistence.storageClass=managed-nfs-storage --set mysqlRootPassword=test123
WARNING: This chart is deprecated
NAME: mysql-57
LAST DEPLOYED: Mon May 15 13:36:16 2023
NAMESPACE: default
STATUS: deployed
REVISION: 1
NOTES:
MySQL can be accessed via port 3306 on the following DNS name from within your cluster:
mysql-57.default.svc.cluster.local
To get your root password run:
MYSQL_ROOT_PASSWORD=$(kubectl get secret --namespace default mysql-57 -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. Install the mysql client:
$ apt-get update && apt-get install mysql-client -y
3. Connect using the mysql cli, then provide your password:
$ mysql -h mysql-57 -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-57 3306
mysql -h ${MYSQL_HOST} -P${MYSQL_PORT} -u root -p${MYSQL_ROOT_PASSWORD}
oot@ks-master:~/helm# kubectl get deploy,svc,pvc mysql-57
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/mysql-57 1/1 1 1 71s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/mysql-57 ClusterIP 10.233.58.89 <none> 3306/TCP 71s
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
persistentvolumeclaim/mysql-57 Bound pvc-8482a9ca-6b3b-452c-82ef-1161b44aec3c 8Gi RWO managed-nfs-storage 71s
root@ks-master:~/helm# helm list
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
mysql-1684127504 default 1 2023-05-15 13:11:47.613586278 +0800 CST deployed mysql-1.6.9 5.7.30
mysql-57 default 1 2023-05-15 13:36:16.056348414 +0800 CST deployed mysql-1.6.9 5.7.30
# 服务解析
root@ks-master:~/helm# dig -t a mysql-57.default.svc.cluster.local @169.254.25.10
; <<>> DiG 9.16.1-Ubuntu <<>> -t a mysql-57.default.svc.cluster.local @169.254.25.10
;; global options: +cmd
;; Got answer:
;; WARNING: .local is reserved for Multicast DNS
;; You are currently testing what happens when an mDNS query is leaked to DNS
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 38949
;; flags: qr aa rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; WARNING: recursion requested but not available
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
; COOKIE: cd972b5529625fa1 (echoed)
;; QUESTION SECTION:
;mysql-57.default.svc.cluster.local. IN A
;; ANSWER SECTION:
mysql-57.default.svc.cluster.local. 30 IN A 10.233.58.89
;; Query time: 3 msec
;; SERVER: 169.254.25.10#53(169.254.25.10)
;; WHEN: Mon May 15 13:40:53 CST 2023
;; MSG SIZE rcvd: 125
尝试使用test123密码登录数据库
root@ks-master:~/helm# kubectl get pods
NAME READY STATUS RESTARTS AGE
busybox 1/1 Running 113 33d
mysql-1684127504-75495f88f6-tfc8t 1/1 Running 0 30m
mysql-57-67cc584744-lcndp 1/1 Running 0 6m18s
nfs-client-provisioner-68c8fcd77-hg8hl 1/1 Running 19 34d
nginx-5458dbdbd4-bq48r 1/1 Running 0 10d
nginx-deployment-8f558f666-97tvr 1/1 Running 0 10d
nginx-deployment-8f558f666-g8c2c 1/1 Running 0 10d
nginx-dp-01-76bb89c887-9lhb4 1/1 Running 0 3h46m
static-web-ks-master 1/1 Running 1 11d
ubuntu 0/1 Completed 0 17m
root@ks-master:~/helm# kubectl exec -it mysql-57-67cc584744-lcndp -- bash
Defaulted container "mysql-57" out of: mysql-57, remove-lost-found (init)
root@mysql-57-67cc584744-lcndp:/# mysql -uroot -ptest123 -h mysql-57.default.svc.cluster.local
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 101
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.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.01 sec)
mysql>
这样就说明数据库连接正常
6.3 删除Release
root@ks-master:~/helm# helm list
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
mysql-1684127504 default 1 2023-05-15 13:11:47.613586278 +0800 CST deployed mysql-1.6.9 5.7.30
mysql-57 default 1 2023-05-15 13:36:16.056348414 +0800 CST deployed mysql-1.6.9 5.7.30
root@ks-master:~/helm# helm uninstall mysql-1684127504
release "mysql-1684127504" uninstalled
root@ks-master:~/helm# helm list
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
mysql-57 default 1 2023-05-15 13:36:16.056348414 +0800 CST deployed mysql-1.6.9 5.7.30
在某些情况下,我们需要删除,但又担心今后可能还需要恢复,可以加上–keep-history,这样会删除资源但下次需要是仍能恢复
这样就能保留release记录,该记录的状态是uninstalled
root@ks-master:~/helm# helm ls
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
mysql-57 default 1 2023-05-15 13:36:16.056348414 +0800 CST deployed mysql-1.6.9 5.7.30
root@ks-master:~/helm# helm uninstall mysql-57 --keep-history
release "mysql-57" uninstalled
root@ks-master:~/helm# helm ls -a
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
mysql-57 default 1 2023-05-15 13:36:16.056348414 +0800 CST uninstalled mysql-1.6.9 5.7.30
恢复
helm rollback [version]
root@ks-master:~/helm# kubectl get pods
NAME READY STATUS RESTARTS AGE
busybox 1/1 Running 114 33d
nfs-client-provisioner-68c8fcd77-hg8hl 1/1 Running 19 34d
nginx-5458dbdbd4-bq48r 1/1 Running 0 10d
nginx-deployment-8f558f666-97tvr 1/1 Running 0 10d
nginx-deployment-8f558f666-g8c2c 1/1 Running 0 10d
nginx-dp-01-76bb89c887-9lhb4 1/1 Running 0 4h16m
static-web-ks-master 1/1 Running 1 11d
ubuntu 0/1 Completed 0 47m
root@ks-master:~/helm# helm rollback mysql-57 1
Rollback was a success! Happy Helming!
root@ks-master:~/helm# helm ls
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
mysql-57 default 2 2023-05-15 14:14:44.977006218 +0800 CST deployed mysql-1.6.9 5.7.30
root@ks-master:~/helm# kubectl get pods
NAME READY STATUS RESTARTS AGE
busybox 1/1 Running 114 33d
mysql-57-67cc584744-9hcd5 1/1 Running 0 3m38s
nfs-client-provisioner-68c8fcd77-hg8hl 1/1 Running 19 34d
nginx-5458dbdbd4-bq48r 1/1 Running 0 10d
nginx-deployment-8f558f666-97tvr 1/1 Running 0 10d
nginx-deployment-8f558f666-g8c2c 1/1 Running 0 10d
nginx-dp-01-76bb89c887-9lhb4 1/1 Running 0 4h21m
static-web-ks-master 1/1 Running 1 11d
ubuntu 0/1 Completed 0 53m
6.4 定制参数部署应用
6.4.1 查看应用可以使用哪些参数
helm show values microsoft/mysql
效果如下
root@ks-master:~/helm# helm search repo mysql
NAME CHART VERSION APP VERSION DESCRIPTION
bitnami/mysql 9.9.1 8.0.33 MySQL is a fast, reliable, scalable, and easy t...
microsoft/mysql 1.6.9 5.7.30 DEPRECATED - Fast, reliable, scalable, and easy...
microsoft/mysqldump 2.6.2 2.4.1 DEPRECATED! - A Helm chart to help backup MySQL...
microsoft/prometheus-mysql-exporter 0.7.1 v0.11.0 DEPRECATED A Helm chart for prometheus mysql ex...
bitnami/phpmyadmin 11.1.1 5.2.1 phpMyAdmin is a free software tool written in P...
microsoft/percona 1.2.3 5.7.26 DEPRECATED - free, fully compatible, enhanced, ...
microsoft/percona-xtradb-cluster 1.0.8 5.7.19 DEPRECATED - free, fully compatible, enhanced, ...
microsoft/phpmyadmin 4.3.5 5.0.1 DEPRECATED phpMyAdmin is an mysql administratio...
bitnami/mariadb 12.2.3 10.11.3 MariaDB is an open source, community-developed ...
bitnami/mariadb-galera 8.2.1 10.11.3 MariaDB Galera is a multi-primary database clus...
microsoft/gcloud-sqlproxy 0.6.1 1.11 DEPRECATED Google Cloud SQL Proxy
microsoft/mariadb 7.3.14 10.3.22 DEPRECATED Fast, reliable, scalable, and easy t...
root@ks-master:~/helm# helm show values microsoft/mysql
## mysql image version
## ref: https://hub.docker.com/r/library/mysql/tags/
##
image: "mysql"
imageTag: "5.7.30"
strategy:
type: Recreate
busybox:
image: "busybox"
tag: "1.32"
testFramework:
enabled: true
image: "bats/bats"
tag: "1.2.1"
imagePullPolicy: IfNotPresent
securityContext: {}
略
6.4.2 通过文件进行传值
配置文件内容如下:
root@ks-master:~/mysqldir# cat mysql-config.yaml
mysqlDatabase: helm # 初始化完毕自动创建数据库名
mysqlRootPassword: test123 # root密码
persistence:
enabled: true
storageClass: "managed-nfs-storage" # storageclass名
resources: # 资源限制
requests:
memory: 260Mi
cpu: 120m
通过yaml创建资源,命令如下
helm install mysql-helm -f /root/mysqldir/mysql-config.yaml microsoft/mysql
执行结果如下
root@ks-master:~# helm install mysql-helm -f /root/mysqldir/mysql-config.yaml microsoft/mysql
WARNING: This chart is deprecated
NAME: mysql-helm
LAST DEPLOYED: Mon May 15 14:34:14 2023
NAMESPACE: default
STATUS: deployed
REVISION: 1
NOTES:
MySQL can be accessed via port 3306 on the following DNS name from within your cluster:
mysql-helm.default.svc.cluster.local
To get your root password run:
MYSQL_ROOT_PASSWORD=$(kubectl get secret --namespace default mysql-helm -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. Install the mysql client:
$ apt-get update && apt-get install mysql-client -y
3. Connect using the mysql cli, then provide your password:
$ mysql -h mysql-helm -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-helm 3306
mysql -h ${MYSQL_HOST} -P${MYSQL_PORT} -u root -p${MYSQL_ROOT_PASSWORD}
可以看到root密码和数据库都是按照我们的意愿被创建
root@ks-master:~# kubectl describe pod mysql-helm-55c75d5768-7hhjp |egrep "cpu|memory"
cpu: 10m
memory: 10Mi
cpu: 120m
memory: 260Mi
root@ks-master:~# kubectl exec -it mysql-helm-55c75d5768-7hhjp -- bash
Defaulted container "mysql-helm" out of: mysql-helm, remove-lost-found (init)
root@mysql-helm-55c75d5768-7hhjp:/# mysql -uroot -ptest123 -h mysql-helm.default.svc.cluster.local
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 14
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.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| helm |
| mysql |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.01 sec)
mysql>
6.4.3 查看应用创建时传了哪些值
root@ks-master:~# helm ls
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
mysql-57 default 2 2023-05-15 14:14:44.977006218 +0800 CST deployed mysql-1.6.9 5.7.30
mysql-helm default 1 2023-05-15 14:34:14.055004607 +0800 CST deployed mysql-1.6.9 5.7.30
root@ks-master:~# helm get values mysql-helm
USER-SUPPLIED VALUES:
mysqlDatabase: helm
mysqlRootPassword: test123
persistence:
enabled: true
storageClass: managed-nfs-storage
resources:
requests:
cpu: 120m
memory: 260Mi
6.4.4 查看Release所有相关资源
root@ks-master:~# kubectl get all -l release=mysql-helm
NAME READY STATUS RESTARTS AGE
pod/mysql-helm-55c75d5768-7hhjp 1/1 Running 0 15m
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/mysql-helm ClusterIP 10.233.24.182 <none> 3306/TCP 15m
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/mysql-helm 1/1 1 1 15m
NAME DESIRED CURRENT READY AGE
replicaset.apps/mysql-helm-55c75d5768 1 1 1 15m
6.5 Release升级和回滚
6.5.1 Upgrade
root@ks-master:~# kubectl exec -it mysql-helm-55c75d5768-7hhjp -- mysql -uroot -ptest123 -e "select version();"
Defaulted container "mysql-helm" out of: mysql-helm, remove-lost-found (init)
mysql: [Warning] Using a password on the command line interface can be insecure.
+-----------+
| version() |
+-----------+
| 5.7.30 |
+-----------+
2个方法可以升级
方法1:
修改yaml
# 通过下面这行来修改image版本
imageTag: "5.7.31"
mysqlDatabase: helm
mysqlRootPassword: test123
persistence:
enabled: true
storageClass: "managed-nfs-storage"
resources:
requests:
memory: 260Mi
cpu: 120m
通过yaml文件upgrade
helm upgrade mysql-57 -f mysql-config.yaml micorsoft/mysql
方法2:
helm upgrade mysql-57 -f mysql-config.yaml --set imageTag=5.7.31 micorsoft/mysql
升级后
root@ks-master:~/mysqldir# kubectl exec -it mysql-helm-694df9746f-2qdjh -- mysql -uroot -ptest123 -e "select version();"
Defaulted container "mysql-helm" out of: mysql-helm, remove-lost-found (init)
mysql: [Warning] Using a password on the command line interface can be insecure.
+-----------+
| version() |
+-----------+
| 5.7.31 |
+-----------+
root@ks-master:~/mysqldir# kubectl get deployments.apps mysql-helm -o wide
NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR
mysql-helm 1/1 1 1 90m mysql-helm mysql:5.7.31 app=mysql-helm,release=mysql-helm
root@ks-master:~/mysqldir# kubectl get pods mysql-helm-694df9746f-2qdjh -o jsonpath={.spec.containers[].image}
mysql:5.7.31
6.5.2 rollback
查看Release版本
root@ks-master:~/mysqldir# helm history mysql-helm
REVISION UPDATED STATUS CHART APP VERSION DESCRIPTION
1 Mon May 15 14:34:14 2023 superseded mysql-1.6.9 5.7.30 Install complete
2 Mon May 15 15:56:56 2023 deployed mysql-1.6.9 5.7.30 Upgrade complete
回滚
helm rollback mysql-helm 1
结果验证
root@ks-master:~/mysqldir# helm rollback mysql-helm 1
Rollback was a success! Happy Helming!
root@ks-master:~/mysqldir# kubectl exec -it mysql-helm-55c75d5768-wsplm -- mysql -uroot -ptest123 -e "select version();"
Defaulted container "mysql-helm" out of: mysql-helm, remove-lost-found (init)
mysql: [Warning] Using a password on the command line interface can be insecure.
+-----------+
| version() |
+-----------+
| 5.7.30 |
+-----------+
查看Release版本
root@ks-master:~/mysqldir# helm history mysql-helm
REVISION UPDATED STATUS CHART APP VERSION DESCRIPTION
1 Mon May 15 14:34:14 2023 superseded mysql-1.6.9 5.7.30 Install complete
2 Mon May 15 15:56:56 2023 superseded mysql-1.6.9 5.7.30 Upgrade complete
3 Mon May 15 16:13:43 2023 deployed mysql-1.6.9 5.7.30 Rollback to 1
7. Helm Chart包
7.1 本地chart包安装
# helm pull micorsoft/mysql
# ls mysql-1.6.9.tgz
mysql-1.6.9.tgz
## 使用这个chart包部署应用
# helm install mysql2 --set persistence.storageClass=managed-nfs-storage mysql-1.6.9.tgz
7.2 远程chart包安装
helm install mysql2 --set persistence.storageClass=managed-nfs-storage http://192.168.31.132:30800/mysql-1.6.9.tgz
8. Chart包配置
8.1 Chart目录结构
nginx/
├── Chart.yaml # 填写chart包描述
├── charts # 存放chart包,或者依赖chart包
├── templates # 存放部署模板,主要是资源清单文件
│ ├── NOTES.txt
│ ├── _helpers.tpl
│ ├── deployment.yaml
│ ├── hpa.yaml
│ ├── ingress.yaml
│ ├── service.yaml
│ ├── serviceaccount.yaml
│ └── tests
│ └── test-connection.yaml
└── values.yaml # 变量
有两种方式可以创建chart目录
- 使用helm create创建
- 下载已有的chart包,解压
8.1.1 命令行创建
root@ks-master:~/helm# helm create nginx
Creating nginx
root@ks-master:~/helm# tree nginx/
nginx/
├── Chart.yaml
├── charts
├── templates
│ ├── NOTES.txt
│ ├── _helpers.tpl
│ ├── deployment.yaml
│ ├── hpa.yaml
│ ├── ingress.yaml
│ ├── service.yaml
│ ├── serviceaccount.yaml
│ └── tests
│ └── test-connection.yaml
└── values.yaml
3 directories, 10 files
8.1.2 下载包
root@ks-master:~/helm# helm repo list
NAME URL
micorsoft http://mirror.azure.cn/kubernetes/charts/
bitnami https://charts.bitnami.com/bitnami
root@ks-master:~/helm# helm search repo nginx
NAME CHART VERSION APP VERSION DESCRIPTION
bitnami/nginx 14.2.1 1.24.0 NGINX Open Source is a web server that can be a...
bitnami/nginx-ingress-controller 9.6.3 1.7.1 NGINX Ingress Controller is an Ingress controll...
bitnami/nginx-intel 2.1.15 0.4.9 DEPRECATED NGINX Open Source for Intel is a lig...
micorsoft/nginx-ingress 1.41.3 v0.34.1 DEPRECATED! An nginx Ingress controller that us...
micorsoft/nginx-ldapauth-proxy 0.1.6 1.13.5 DEPRECATED - nginx proxy with ldapauth
micorsoft/nginx-lego 0.3.1 Chart for nginx-ingress-controller and kube-lego
micorsoft/gcloud-endpoints 0.1.2 1 DEPRECATED Develop, deploy, protect and monitor...
root@ks-master:~/helm# helm pull bitnami/nginx
root@ks-master:~/helm# mkdir nginx-14.2.1
root@ks-master:~/helm# tar xf nginx-14.2.1.tgz
root@ks-master:~/helm# tar xf nginx-14.2.1.tgz -C nginx-14.2.1
root@ks-master:~/helm# tree nginx-14.2.1
nginx-14.2.1
└── nginx
├── Chart.lock
├── Chart.yaml
├── README.md
├── 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
│ │ ├── _warnings.tpl
│ │ └── validations
│ │ ├── _cassandra.tpl
│ │ ├── _mariadb.tpl
│ │ ├── _mongodb.tpl
│ │ ├── _mysql.tpl
│ │ ├── _postgresql.tpl
│ │ ├── _redis.tpl
│ │ └── _validations.tpl
│ └── values.yaml
├── templates
│ ├── NOTES.txt
│ ├── _helpers.tpl
│ ├── deployment.yaml
│ ├── extra-list.yaml
│ ├── health-ingress.yaml
│ ├── hpa.yaml
│ ├── ingress.yaml
│ ├── pdb.yaml
│ ├── prometheusrules.yaml
│ ├── server-block-configmap.yaml
│ ├── serviceaccount.yaml
│ ├── servicemonitor.yaml
│ ├── svc.yaml
│ └── tls-secrets.yaml
├── values.schema.json
└── values.yaml
6 directories, 41 files
8.2 创建不可修改的Chart
创建chart目录
mkdir nginx/template -p
创建Chart.yaml
name: helm-nginx
version: 1.0.0
apiVersion: v1
appVersion: "1.0"
description: A Helm chart nginx for kubernetes
创建模板
kubectl create deployment nginx-helm --image=nginx:1.24 --dry-run=client -o yaml >> templates/deploy.yaml
root@ks-master:~/helm/nginx# cat templates/deploy.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: nginx-helm
name: nginx-helm
spec:
replicas: 1
selector:
matchLabels:
app: nginx-helm
template:
metadata:
labels:
app: nginx-helm
spec:
containers:
- image: nginx:1.24
name: nginx
创建service
kubectl expose deployment nginx-helm --port=80 --target-port=80 --type=NodePort --dry-run=client -o yaml >>
root@ks-master:~/helm/nginx# cat templates/service.yaml
apiVersion: v1
kind: Service
metadata:
labels:
app: nginx-helm
name: nginx-helm
spec:
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
app: nginx-helm
type: NodePort
status:
loadBalancer: {}
部署
root@ks-master:~/helm/nginx# helm ls
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
mysql-57 default 5 2023-05-16 08:19:09.535265892 +0800 CST deployed mysql-1.6.9 5.7.30
mysql-helm default 3 2023-05-15 16:13:43.809485811 +0800 CST deployed mysql-1.6.9 5.7.30
mysql2 default 1 2023-05-15 16:31:31.629337481 +0800 CST deployed mysql-1.6.9 5.7.30
root@ks-master:~/helm/nginx# helm install helm-nginx /root/helm/nginx
NAME: helm-nginx
LAST DEPLOYED: Tue May 16 10:35:07 2023
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
root@ks-master:~/helm/nginx# helm ls
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
helm-nginx default 1 2023-05-16 10:35:07.194310072 +0800 CST deployed helm-nginx-1.0.0 1.0
mysql-57 default 5 2023-05-16 08:19:09.535265892 +0800 CST deployed mysql-1.6.9 5.7.30
mysql-helm default 3 2023-05-15 16:13:43.809485811 +0800 CST deployed mysql-1.6.9 5.7.30
mysql2 default 1 2023-05-15 16:31:31.629337481 +0800 CST deployed mysql-1.6.9 5.7.30
root@ks-master:~/helm/nginx# kubectl get all -l app=nginx-helm
NAME READY STATUS RESTARTS AGE
pod/nginx-helm-76cc8b5ccb-p7mh7 1/1 Running 0 96s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/nginx-helm NodePort 10.233.46.228 <none> 80:30174/TCP 96s
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/nginx-helm 1/1 1 1 96s
NAME DESIRED CURRENT READY AGE
replicaset.apps/nginx-helm-76cc8b5ccb 1 1 1 96s
8.3 Helm打包
# helm package /root/helm/nginx
Successfully packaged chart and saved it to: /root/helm/helm-nginx-1.0.0.tgz
用包部署
root@ks-master:~/helm# helm ls
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
mysql-57 default 5 2023-05-16 08:19:09.535265892 +0800 CST deployed mysql-1.6.9 5.7.30
mysql-helm default 3 2023-05-15 16:13:43.809485811 +0800 CST deployed mysql-1.6.9 5.7.30
mysql2 default 1 2023-05-15 16:31:31.629337481 +0800 CST deployed mysql-1.6.9 5.7.30
root@ks-master:~/helm# helm install nginx-helm helm-nginx-1.0.0.tgz
NAME: nginx-helm
LAST DEPLOYED: Tue May 16 10:46:32 2023
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
root@ks-master:~/helm# helm ls
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
mysql-57 default 5 2023-05-16 08:19:09.535265892 +0800 CST deployed mysql-1.6.9 5.7.30
mysql-helm default 3 2023-05-15 16:13:43.809485811 +0800 CST deployed mysql-1.6.9 5.7.30
mysql2 default 1 2023-05-15 16:31:31.629337481 +0800 CST deployed mysql-1.6.9 5.7.30
nginx-helm default 1 2023-05-16 10:46:32.801054838 +0800 CST deployed helm-nginx-1.0.0 1.0
root@ks-master:~/helm# kubectl get all -l app=nginx-helm
NAME READY STATUS RESTARTS AGE
pod/nginx-helm-76cc8b5ccb-2d76q 1/1 Running 0 2m46s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/nginx-helm NodePort 10.233.43.14 <none> 80:31249/TCP 2m46s
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/nginx-helm 1/1 1 1 2m46s
NAME DESIRED CURRENT READY AGE
replicaset.apps/nginx-helm-76cc8b5ccb 1 1 1 2m46s
8.4 常用Chart变量
- Release.Name 发布的名称
- Release.Time 更新时间
- Release.Namespace 发布的命名空间
- Release.Service 进行发布的服务
- Release.IsUpgrade 如果当前操作是升级或者回滚,则为true
- Release.IsInstall 如果当前操作是安装,则为true
- Release.Revision 修订号,从1开始递增,每个upgrade都触发.
- Chart 内容为Chart.yaml的值
- Chart.Version
- Chart.Maintainers
- Files 类似chart的对象,包含charts中所有非特殊文件. {{.Files.Get.name}} {{.File.GetStringname}}
- Capabilities 类似于地图对象,包含关于kubernetes {{.Capabilities.KubeVersion}}
8.5 创建可配置Chart
8.5.1 创建values.yaml
image:
repository: nginx
tag: 1.17
replicas: 2
8.5.2 修改deployment
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: nginx-helm
name: nginx-helm
spec:
replicas: {{ .Values.replicas }}
selector:
matchLabels:
app: nginx-helm
template:
metadata:
labels:
app: nginx-helm
spec:
containers:
- image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
name: nginx
部署应用
# helm install helm-nginx /root/helm/nginx
NAME: helm-nginx
LAST DEPLOYED: Tue May 16 11:21:56 2023
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
root@ks-master:~/helm# helm ls
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
helm-nginx default 1 2023-05-16 11:21:56.196836289 +0800 CST deployed helm-nginx-1.0.0 1.0
mysql-57 default 5 2023-05-16 08:19:09.535265892 +0800 CST deployed mysql-1.6.9 5.7.30
mysql-helm default 3 2023-05-15 16:13:43.809485811 +0800 CST deployed mysql-1.6.9 5.7.30
mysql2 default 1 2023-05-15 16:31:31.629337481 +0800 CST deployed mysql-1.6.9 5.7.30
root@ks-master:~/helm# kubectl get all -l app=nginx-helm
NAME READY STATUS RESTARTS AGE
pod/nginx-helm-6dffc75f54-7ljp5 1/1 Running 0 3m4s
pod/nginx-helm-6dffc75f54-bzjms 1/1 Running 0 3m4s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/nginx-helm NodePort 10.233.1.99 <none> 80:30868/TCP 3m4s
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/nginx-helm 2/2 2 2 3m4s
NAME DESIRED CURRENT READY AGE
replicaset.apps/nginx-helm-6dffc75f54 2 2 2 3m4s
通过–set方式传递参数
root@ks-master:~/helm# helm install helm-nginx --set replicas=3 /root/helm/nginx --dry-run
NAME: helm-nginx
LAST DEPLOYED: Tue May 16 11:41:36 2023
NAMESPACE: default
STATUS: pending-install
REVISION: 1
TEST SUITE: None
HOOKS:
MANIFEST:
---
# Source: helm-nginx/templates/service.yaml
apiVersion: v1
kind: Service
metadata:
labels:
app: nginx-helm
name: nginx-helm
spec:
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
app: nginx-helm
type: NodePort
status:
loadBalancer: {}
---
# Source: helm-nginx/templates/deploy.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: nginx-helm
name: nginx-helm
spec:
replicas: 3
selector:
matchLabels:
app: nginx-helm
template:
metadata:
labels:
app: nginx-helm
spec:
containers:
- image: nginx:1.17
name: nginx
8.6 Harbor分发helm
8.6.1 打包helm
root@ks-master:~/helm/nginx# helm package .
Successfully packaged chart and saved it to: /root/helm/nginx/helm-nginx-1.0.0.tgz
8.6.2 harbor配置
开启harbor chart支持
./install.sh --with-chartmuseum
web端上传
添加harbor仓库
root@ks-master:~/helm/nginx# helm repo add --ca-file /root/helm/ca.crt --cert-file /root/helm/harbor.crt --key-file /root/helm/ca.key --username admin --password root123 harborhelm https://harbor.intra.com/chartrepo/nginx
"harborhelm" has been added to your repositories
root@ks-master:~/helm/nginx# helm repo ls
NAME URL
micorsoft http://mirror.azure.cn/kubernetes/charts/
bitnami https://charts.bitnami.com/bitnami
harborhelm https://harbor.intra.com/chartrepo/nginx
查找helm-nginx包
root@ks-master:~/helm/nginx# helm repo update
Hang tight while we grab the latest from your chart repositories...
...Successfully got an update from the "harborhelm" chart repository
...Successfully got an update from the "micorsoft" chart repository
...Successfully got an update from the "bitnami" chart repository
Update Complete. ⎈Happy Helming!⎈
root@ks-master:~/helm/nginx# helm search repo helm-nginx
NAME CHART VERSION APP VERSION DESCRIPTION
harborhelm/helm-nginx 1.0.0 1.0 A Helm chart nginx for kubernetes
通过harbor的chartrepo部署应用
root@ks-master:~/helm/nginx# helm install my-nginx --set replicas=3 harborhelm/helm-nginx
NAME: my-nginx
LAST DEPLOYED: Tue May 16 14:14:44 2023
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
root@ks-master:~/helm/nginx# helm ls
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
my-nginx default 1 2023-05-16 14:14:44.384420585 +0800 CST deployed helm-nginx-1.0.0 1.0
mysql-57 default 5 2023-05-16 08:19:09.535265892 +0800 CST deployed mysql-1.6.9 5.7.30
mysql-helm default 3 2023-05-15 16:13:43.809485811 +0800 CST deployed mysql-1.6.9 5.7.30
mysql2 default 1 2023-05-15 16:31:31.629337481 +0800 CST deployed mysql-1.6.9 5.7.30
root@ks-master:~/helm/nginx# kubectl get all -l app=nginx-helm
NAME READY STATUS RESTARTS AGE
pod/nginx-helm-6dffc75f54-9pjtg 1/1 Running 0 49s
pod/nginx-helm-6dffc75f54-bdb69 1/1 Running 0 49s
pod/nginx-helm-6dffc75f54-z6hn8 1/1 Running 0 49s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/nginx-helm NodePort 10.233.62.114 <none> 80:30617/TCP 49s
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/nginx-helm 3/3 3 3 49s
NAME DESIRED CURRENT READY AGE
replicaset.apps/nginx-helm-6dffc75f54 3 3 3 49s
8.6.3 Linux环境上传helm包
安装helm-push插件
root@ks-master:~/helm/nginx# helm plugin install https://github.com/chartmuseum/helm-push
Downloading and installing helm-push v0.10.3 ...
https://github.com/chartmuseum/helm-push/releases/download/v0.10.3/helm-push_0.10.3_linux_amd64.tar.gz
Installed plugin: cm-push
root@ks-master:~# ls /root/.local/share/helm/plugins/helm-push/bin/helm-cm-push
/root/.local/share/helm/plugins/helm-push/bin/helm-cm-push
上传
root@ks-master:~/helm/nginx# helm cm-push --username admin --password root123 --ca-file /root/helm/ca.crt --cert-file /root/helm/harbor.crt --key-file /root/helm/ca.key helm-nginx-1.0.1.tgz harborhelm
Pushing helm-nginx-1.0.1.tgz to harborhelm...
Done.
此时在web端也能看到新版本
更新repo后,可以看到已经是最新的版本了
root@ks-master:~/helm/nginx# helm repo update
Hang tight while we grab the latest from your chart repositories...
...Successfully got an update from the "harborhelm" chart repository
...Successfully got an update from the "bitnami" chart repository
...Successfully got an update from the "micorsoft" chart repository
Update Complete. ⎈Happy Helming!⎈
root@ks-master:~/helm/nginx# helm search repo helm-nginx
NAME CHART VERSION APP VERSION DESCRIPTION
harborhelm/helm-nginx 1.0.1 nginx:1.17 A Helm chart nginx for kubernetes
升级版本
root@ks-master:~/helm/nginx# helm upgrade nginx --set image.tag=1.19 harborhelm/helm-nginx
Release "nginx" has been upgraded. Happy Helming!
NAME: nginx
LAST DEPLOYED: Tue May 16 15:11:14 2023
NAMESPACE: default
STATUS: deployed
REVISION: 4
TEST SUITE: None
更新确认
root@ks-master:~/helm/nginx# kubectl get pod nginx-helm-54b9bdf756-tj77d -o jsonpath={.spec.containers[].image}
nginx:1.19