近期文章:Helm 安装+阿里云镜像配置+memcached部署教程,以及kubernetes Helm 自定义 Charts 模板
配置国内存放chart仓库的地址
阿里云仓库(https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts)
官方仓库(https://hub.kubeapps.com/charts/incubator)官方chart仓库,国内可能无法访问。
微软仓库(http://mirror.azure.cn/kubernetes/charts/)这个仓库推荐,基本上官网有的chart这里都有,国内可能无法访问
开源社仓库http://mirror.kaiyuanshe.cn/kubernetes/charts/ 是由中国支持开源的企业,社区及个人所组织的一个开源联盟,旨在推广开源
helm repo add aliyun https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts #添加bitnami仓库 helm repo add bitnami https://charts.bitnami.com/bitnami #更新 [root@master01 ~]# helm repo update #查看 [root@master01 ~]# helm repo list
搜索chart
[root@master01 ~]# helm search repo aliyun|grep jenkins aliyun/jenkins 0.13.5 2.73 Open source continuous integration server. It s...
下载chart
[root@master01 ~]# helm pull aliyun/jenkins [root@master01 ~]# ls jenkins-0.13.5.tgz jenkins-0.13.5.tgz #解压chart包 [root@master01 ~]# tar zxvf jenkins-0.13.5.tgz
安装chart
[root@master01 jenkins]# helm install jenkins .
创建一个chart,并指定名字
[root@master01 ~]# helm create myapp Creating myapp [root@master01 ~]# ls myapp charts Chart.yaml templates values.yaml
创建一个release实例
[root@master01 ~]# cd myapp [root@master01 myapp]# helm install myapp . NAME: myapp LAST DEPLOYED: Thu Aug 31 18:24:35 2023 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" -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
卸载release
[root@master01 myapp]# helm uninstall myapp release "myapp" uninstalled
检测values.yam语法
[root@master01 ~]# helm lint myapp ==> Linting myapp [INFO] Chart.yaml: icon is recommended 1 chart(s) linted, 0 chart(s) failed
失败的为0
upgrade 升级 release
[root@master01 myapp]# kubectl get svc NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE myapp ClusterIP 10.100.221.23 <none> 80/TCP 10h #myapp type类型为ClusterIP,将其修改为NodePort [root@master01 myapp]# helm upgrade --set service.type="NodePort" myapp . Release "myapp" has been upgraded. Happy Helming! NAME: myapp LAST DEPLOYED: Thu Aug 31 18:09:10 2023 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) export NODE_IP=$(kubectl get nodes --namespace default -o jsonpath="{.items[0].status.addresses[0].address}") echo http://$NODE_IP:$NODE_PORT #再次查看svc,已经变成NodePort [root@master01 myapp]# kubectl get svc NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 2d6h myapp NodePort 10.100.221.23 <none> 80:32240/TCP 10h
类型已经从ClusterIP变成NodePort
回滚release
helm hisotry 查看历史版本
[root@master01 myapp]# helm history myapp REVISION UPDATED STATUS CHART APP VERSION DESCRIPTION 1 Thu Aug 31 07:50:39 2023 superseded myapp-0.1.0 1.16.0 Install complete 2 Thu Aug 31 18:09:10 2023 deployed myapp-0.1.0 1.16.0 Upgrade complete
回滚到版本
[root@master01 myapp]# helm rollback myapp 1 Rollback was a success! Happy Helming! [root@master01 myapp]# kubectl get svc NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 2d6h myapp ClusterIP 10.100.221.23 <none> 80/TCP 10h #查看历史版本 [root@master01 myapp]# helm history myapp REVISION UPDATED STATUS CHART APP VERSION DESCRIPTION 1 Thu Aug 31 07:50:39 2023 superseded myapp-0.1.0 1.16.0 Install complete 2 Thu Aug 31 18:09:10 2023 superseded myapp-0.1.0 1.16.0 Upgrade complete 3 Thu Aug 31 18:13:53 2023 deployed myapp-0.1.0 1.16.0 Rollback to 1
从上面内容可以看出,已经回滚成功了,且有三个版本
helm 打包Chart
[root@master01 ~]# helm package myapp Successfully packaged chart and saved it to: /root/myapp-0.1.0.tgz