关于Kubernetes中使用Helm部署应用及私有Helm源搭建的一些笔记
寫在前面
- 學(xué)習(xí)K8s涉及,整理筆記記憶
- 博文偏實(shí)戰(zhàn),內(nèi)容涉及:
- Helm的基本概念及安裝,Helm源配置
- chart包的安裝部署
- 私有Helm源的搭建及chart包的push和pull
“不愛也不恨”包含了全部世俗智慧的一半;“不要說話也不要相信”則包含了另一半的人生智慧。——叔本華《人生的智慧》
Helm
Helm是一個(gè)由CNCF孵化和管理的項(xiàng)目,用于對需要在Kubernetes上部署的復(fù)雜應(yīng)用進(jìn)行定義、安裝和更新。Helm以Chart的方式對應(yīng)用軟件進(jìn)行描述,可以方便地創(chuàng)建、版本化、共享和發(fā)布復(fù)雜的應(yīng)用軟件。
helm的作用就是把許多的資源定義 比如svc,deployment,一次性通過全部定義好,放在源里統(tǒng)一管理,這樣很容易在其他機(jī)器上部署,個(gè)人理解這個(gè)類似于自動(dòng)化運(yùn)維中ansible中的角色概念,前端項(xiàng)目中的npm包管理工具,后端項(xiàng)目中的maven等構(gòu)建工具一樣,類比Ansible使用角色來整合playbook.yaml達(dá)到復(fù)用性。同樣的,使用helm用于整合k8s中的資源對象yaml文件,實(shí)現(xiàn)復(fù)用性,同時(shí)講資源文件的參數(shù),和參數(shù)值通過temple和value進(jìn)行了分離
Helm主要概念
Chart:一個(gè)Helm包,其中包含運(yùn)行一個(gè)應(yīng)用所需要的工具和資源定義,還可能包含Kubernetes集群中的服務(wù)定義,類似Ansible中的rhel-system-roles軟件包
Release: 在Kubernetes集群上運(yùn)行的一個(gè)Chart實(shí)例。在同一個(gè)集群上,一個(gè)Chart可以被安裝多次。
Repository:用于存放和共享Chart倉庫。簡單來說, Helm整個(gè)系統(tǒng)的主要任務(wù)就是,在倉庫中查找需要的Chart,然后將Chart以Release的形式安裝到Kubernetes集群中。
使用helm我們首先需要安裝,可以通過Github下載安裝包
Helm 安裝
安裝包下載:https://github.com/helm/helm/releases:
解壓安裝
┌──[root@vms81.liruilongs.github.io]-[~] └─$tar zxf helm-v3.2.1-linux-amd64.tar.gz ┌──[root@vms81.liruilongs.github.io]-[~] └─$cd linux-amd64/ ┌──[root@vms81.liruilongs.github.io]-[~/linux-amd64] └─$ls helm LICENSE README.md之后直接將helm復(fù)制到/usr/local/bin/,配置完之后,即可以使用helm命令
┌──[root@vms81.liruilongs.github.io]-[~/linux-amd64] └─$cp helm /usr/local/bin/ ┌──[root@vms81.liruilongs.github.io]-[~/linux-amd64] └─$ls /usr/local/bin/ helm配置命令自動(dòng)補(bǔ)全,通過寫入/etc/profile 文件 souece < (helm completion bash)的方式配置命令自動(dòng)補(bǔ)全。配置完記得使用source /etc/profile去刷新配置
┌──[root@vms81.liruilongs.github.io]-[~/ansible/k8s-helm-create] └─$helm --help | grep bashcompletion generate autocompletions script for the specified shell (bash or zsh) ┌──[root@vms81.liruilongs.github.io]-[~/ansible/k8s-helm-create] └─$vim /etc/profile ┌──[root@vms81.liruilongs.github.io]-[~/ansible/k8s-helm-create] └─$source /etc/profile ┌──[root@vms81.liruilongs.github.io]-[~/ansible/k8s-helm-create] └─$cat /etc/profile | grep -v ^# | grep source source <(kubectl completion bash) source <(helm completion bash) ┌──[root@vms81.liruilongs.github.io]-[~/ansible/k8s-helm-create] └─$驗(yàn)證安裝,查看Helm版本
┌──[root@vms81.liruilongs.github.io]-[~/ansible/k8s-helm-create] └─$helm version version.BuildInfo{Version:"v3.2.1", GitCommit:"fe51cd1e31e6a202cba7dead9552a6d418ded79a", GitTreeState:"clean", GoVersion:"go1.13.10"} ┌──[root@vms81.liruilongs.github.io]-[~/ansible/k8s-helm-create] └─$配置helm源
使用helm需要配置yaml源,常見的有阿里。微軟,和Githup上的源
- 阿里云的源 https://apphub.aliyuncs.com
- 微軟azure的源 http://mirror.azure.cn/kubernetes/charts/
查看所以的源
┌──[root@vms81.liruilongs.github.io]-[~/ansible/k8s-helm-create] └─$helm repo list #查看所以的源 Error: no repositories to show添加指定是源
┌──[root@vms81.liruilongs.github.io]-[~/ansible/k8s-helm-create] └─$helm repo add azure http://mirror.azure.cn/kubernetes/charts/"azure" has been added to your repositories ┌──[root@vms81.liruilongs.github.io]-[~/ansible/k8s-helm-create] └─$helm repo add ali https://apphub.aliyuncs.com "ali" has been added to your repositories查看剛才添加的yum源
┌──[root@vms81.liruilongs.github.io]-[~/ansible/k8s-helm-create] └─$helm repo list NAME URL azure http://mirror.azure.cn/kubernetes/charts/ ali https://apphub.aliyuncs.com ┌──[root@vms81.liruilongs.github.io]-[~/ansible/k8s-helm-create] └─$Helm的常見用法
Helm的常見用法,包括搜索Chart、安裝Chart、自定義Chart配置、更新或回滾Release、刪除Release、創(chuàng)建自定義Chart、搭建私有倉庫等
helm search:搜索可用的Chart
┌──[root@vms81.liruilongs.github.io]-[~/ansible/k8s-helm-create] └─$helm search repo mysql NAME CHART VERSION APP VERSION DESCRIPTIONali/mysql 6.8.0 8.0.19 Chart to create a Highly available MySQL cluster ali/mysqldump 2.6.0 2.4.1 A Helm chart to help backup MySQL databases usi... ali/mysqlha 1.0.0 5.7.13 MySQL cluster with a single master and zero or ... ali/prometheus-mysql-exporter 0.5.2 v0.11.0 A Helm chart for prometheus mysql exporter with... azure/mysql 1.6.9 5.7.30 DEPRECATED - Fast, reliable, scalable, and easy... azure/mysqldump 2.6.2 2.4.1 DEPRECATED! - A Helm chart to help backup MySQL... azure/prometheus-mysql-exporter 0.7.1 v0.11.0 DEPRECATED A Helm chart for prometheus mysql 。。。。。。。。。。chart包拉取
安裝chart可以直接使用命令安裝,也可以拉取到本地之后安裝,也可以直接通過命名行安裝
- 本地的Chart壓縮包(helm install mysql-1.6.4.tgz)
- 一個(gè)Chart目錄(helm install mysql/)
- 一個(gè)完整的URL(helm install https://example.com/charts/mysql-1.6.4.tgz)
chart包拉取
┌──[root@vms81.liruilongs.github.io]-[~/ansible/k8s-helm-create] └─$helm pull azure/mysql --version=1.6.4 ┌──[root@vms81.liruilongs.github.io]-[~/ansible/k8s-helm-create] └─$ls mysql-1.6.4.tgzhelm install:安裝Chart
chart包直接安裝
┌──[root@vms81.liruilongs.github.io]-[~/ansible/k8s-helm-create] └─$#helm install db azure/mysql --version=1.6.4 ┌──[root@vms81.liruilongs.github.io]-[~/ansible/k8s-helm-create] └─$拉取的chart包詳細(xì)信息,通過解壓之后查看
┌──[root@vms81.liruilongs.github.io]-[~/ansible/k8s-helm-create] └─$ls mysql-1.6.4.tgz ┌──[root@vms81.liruilongs.github.io]-[~/ansible/k8s-helm-create] └─$tar zxf mysql-1.6.4.tgz ....... ┌──[root@vms81.liruilongs.github.io]-[~/ansible/k8s-helm-create] └─$ls mysql mysql-1.6.4.tgz ┌──[root@vms81.liruilongs.github.io]-[~/ansible/k8s-helm-create] └─$cd mysql/ ┌──[root@vms81.liruilongs.github.io]-[~/ansible/k8s-helm-create/mysql] └─$ls Chart.yaml README.md templates values.yaml| Chart.yaml | 用于描述Chart信息的YAML文件,版本定義等 |
| README.md | 可選: README文件 |
| values.yaml | 默認(rèn)的配置值,即把可變的值抽離出來。 |
| templates | 可選:即模板,結(jié)合values.yaml,能夠生成Kubernetes的manifest文件 |
對于下載好的yaml文件,我們可以修改后使用helm package 重新打包
┌──[root@vms81.liruilongs.github.io]-[~/ansible/k8s-helm-create] └─$rm -rf mysql-1.6.4.tgz ; helm package mysql/ Successfully packaged chart and saved it to: /root/ansible/k8s-helm-create/mysql-1.6.4.tgz ┌──[root@vms81.liruilongs.github.io]-[~/ansible/k8s-helm-create] └─$ls mysql mysql-1.6.4.tgz下面我們修改chart中的對應(yīng)鏡像為已經(jīng)下載好的mysql和busybox鏡像
┌──[root@vms81.liruilongs.github.io]-[~/ansible] └─$ansible 192.168.26.82 -m shell -a "docker images | grep mysql" 192.168.26.82 | CHANGED | rc=0 >> mysql latest ecac195d15af 2 months ago 516MB mysql <none> 9da615fced53 3 months ago 514MB hub.c.163.com/library/mysql latest 9e64176cd8a2 4 years ago 407MB ┌──[root@vms81.liruilongs.github.io]-[~/ansible] └─$ansible 192.168.26.82 -m shell -a "docker images | grep busybox" 192.168.26.82 | CHANGED | rc=0 >> busybox latest ffe9d497c324 5 weeks ago 1.24MB busybox <none> 7138284460ff 2 months ago 1.24MB busybox <none> cabb9f684f8b 2 months ago 1.24MB busybox 1.27 6ad733544a63 4 years ago 1.13MB yauritux/busybox-curl latest 69894251bd3c 5 years ago 21.3MB ┌──[root@vms81.liruilongs.github.io]-[~/ansible] └─$fg vim ./k8s-helm-create/mysql/values.yaml ┌──[root@vms81.liruilongs.github.io]-[~/ansible] └─$通過修好的yaml文件創(chuàng)建chart, 使用helm ls查看當(dāng)前運(yùn)行的chart
┌──[root@vms81.liruilongs.github.io]-[~/ansible/k8s-helm-create] └─$helm ls NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION使用helm install運(yùn)行Chart
這里我們使用之前的那個(gè)mysq chart來安裝一個(gè)mysql
查看是否是否運(yùn)行成功mydb的pod和SVC
┌──[root@vms81.liruilongs.github.io]-[~/ansible/k8s-helm-create/mysql] └─$kubectl get pods NAME READY STATUS RESTARTS AGE mydb-mysql-7f8c5c47bd-82cts 1/1 Running 0 55s pod1 1/1 Running 2 (7d17h ago) 9d pod2 1/1 Running 3 (3d3h ago) 9d ┌──[root@vms81.liruilongs.github.io]-[~/ansible/k8s-helm-create/mysql] └─$kubectl get svc NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE mydb-mysql ClusterIP 10.107.17.103 <none> 3306/TCP 62s svc1 LoadBalancer 10.106.61.84 192.168.26.240 80:30735/TCP 9d svc2 LoadBalancer 10.111.123.194 192.168.26.241 80:31034/TCP 9d ┌──[root@vms81.liruilongs.github.io]-[~/ansible/k8s-helm-create/mysql] └─$安裝一個(gè)mysql客戶端測試OK
┌──[root@vms82.liruilongs.github.io]-[~] └─$yum install mariadb -y ┌──[root@vms81.liruilongs.github.io]-[~/ansible/k8s-helm-create/mysql] └─$mysql -h10.107.17.103 -uroot -ptesting Welcome to the MariaDB monitor. Commands end with ; or \g. Your MySQL connection id is 7 Server version: 5.7.18 MySQL Community Server (GPL)Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.MySQL [(none)]> use mysql Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -ADatabase changed刪除Release
┌──[root@vms81.liruilongs.github.io]-[~/ansible/k8s-helm-create/mysql] └─$helm del mydb release "mydb" uninstalled ┌──[root@vms81.liruilongs.github.io]-[~/ansible/k8s-helm-create/mysql] └─$helm ls NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION ┌──[root@vms81.liruilongs.github.io]-[~/ansible/k8s-helm-create/mysql] └─$搭建私有Repository
自建的Chart之后自然需要搭建私有倉庫。下面使用Nginx搭建一個(gè)簡單的Chart私有倉庫
倉庫搭建
倉庫搭建,找一臺(tái)機(jī)器運(yùn)行一個(gè)Nginx服務(wù)做倉庫,需要注意要對主頁數(shù)據(jù)做映射
┌──[root@vms83.liruilongs.github.io]-[~] └─$netstat -ntulp | grep 80 ┌──[root@vms83.liruilongs.github.io]-[~] └─$docker run -dit --name=helmrepo -p 8080:80 -v /data:/usr/share/nginx/html/charts docker.io/nginx 7201e001b02602f087105ca6096b0816acb03db02296c35c098a3dfddcb9c8d0 ┌──[root@vms83.liruilongs.github.io]-[~] └─$docker ps | grep helmrepo 7201e001b026 nginx "/docker-entrypoint.…" 16 seconds ago Up 15 seconds 0.0.0.0:8080->80/tcp, :::8080->80/tcp helmrepo訪問測試
┌──[root@vms83.liruilongs.github.io]-[~] └─$curl 127.0.0.1:8080 <!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> 。。。。。。。。chart包上傳
打包之前的mysql包,上傳helm私有倉庫。這里需要本讀生成索引文件index.yaml
┌──[root@vms81.liruilongs.github.io]-[~/ansible/k8s-helm-create] └─$helm package mysql/ Successfully packaged chart and saved it to: /root/ansible/k8s-helm-create/mysql-1.6.4.tgz ┌──[root@vms81.liruilongs.github.io]-[~/ansible/k8s-helm-create] └─$helm repo index . --url http://192.168.26.83:8080/charts ┌──[root@vms81.liruilongs.github.io]-[~/ansible/k8s-helm-create] └─$ls index.yaml mysql mysql-1.6.4.tgz ┌──[root@vms81.liruilongs.github.io]-[~/ansible/k8s-helm-create] └─$cd ..將索引文件和chart包一同上傳到私有倉庫
┌──[root@vms81.liruilongs.github.io]-[~/ansible] └─$ansible 192.168.26.83 -m copy -a "src=./k8s-helm-create/index.yaml dest=/data/" 192.168.26.83 | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"},"changed": true,"checksum": "233a0f3837d46af8a50098f1b29aa524b751cb29","dest": "/data/index.yaml","gid": 0,"group": "root","md5sum": "66953d9558e44ab2f049dc602600ffda","mode": "0644","owner": "root","size": 843,"src": "/root/.ansible/tmp/ansible-tmp-1642011407.72-76313-71345316897038/source","state": "file","uid": 0 } ┌──[root@vms81.liruilongs.github.io]-[~/ansible] └─$ansible 192.168.26.83 -m copy -a "src=./k8s-helm-create/mysql-1.6.4.tgz dest=/data/" 192.168.26.83 | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"},"changed": true,"checksum": "4fddb1c13c71673577570e61f68f926af7255bad","dest": "/data/mysql-1.6.4.tgz","gid": 0,"group": "root","md5sum": "929267de36f9be04e0adfb2f9c9f5812","mode": "0644","owner": "root","size": 11121,"src": "/root/.ansible/tmp/ansible-tmp-1642011437.58-76780-127185287864942/source","state": "file","uid": 0 } ┌──[root@vms81.liruilongs.github.io]-[~/ansible] └─$倉庫索引文件更新
如果添加新的chart包到私有倉庫,需要對于索引文件進(jìn)行更新
helm create 創(chuàng)建一個(gè)自定義的chart包
┌──[root@vms81.liruilongs.github.io]-[~/ansible/k8s-helm-create] └─$helm create liruilonghelm Creating liruilonghelm ┌──[root@vms81.liruilongs.github.io]-[~/ansible/k8s-helm-create] └─$ls index.yaml liruilonghelm mysql mysql-1.6.4.tgz ┌──[root@vms81.liruilongs.github.io]-[~/ansible/k8s-helm-create] └─$helm package liruilonghelm/ Successfully packaged chart and saved it to: /root/ansible/k8s-helm-create/liruilonghelm-0.1.0.tgz ┌──[root@vms81.liruilongs.github.io]-[~/ansible/k8s-helm-create] └─$ls index.yaml liruilonghelm liruilonghelm-0.1.0.tgz mysql mysql-1.6.4.tgz使用同樣的命令跟新索引文件
┌──[root@vms81.liruilongs.github.io]-[~/ansible/k8s-helm-create] └─$helm repo index . --url http://192.168.26.83:8080/charts ┌──[root@vms81.liruilongs.github.io]-[~/ansible/k8s-helm-create] └─$cat index.yaml查看新的索引文件
apiVersion: v1 entries:liruilonghelm:- apiVersion: v2appVersion: 1.16.0created: "2022-01-13T02:22:19.442365047+08:00"description: A Helm chart for Kubernetesdigest: abb491f061cccc8879659149d96c99cbc261af59d5fcf8855c5e86251fbd53c1name: liruilonghelmtype: applicationurls:- http://192.168.26.83:8080/charts/liruilonghelm-0.1.0.tgzversion: 0.1.0mysql:- apiVersion: v1appVersion: 5.7.30created: "2022-01-13T02:22:19.444985984+08:00"description: Fast, reliable, scalable, and easy to use open-source relationaldatabase system.digest: 29153332e509765010c7e5e240a059550d52b01b31b69f25dd27c136dffec40fhome: https://www.mysql.com/icon: https://www.mysql.com/common/logos/logo-mysql-170x115.pngkeywords:- mysql- database- sqlmaintainers:- email: o.with@sportradar.comname: olemarkus- email: viglesias@google.comname: viglesiascename: mysqlsources:- https://github.com/kubernetes/charts- https://github.com/docker-library/mysqlurls:- http://192.168.26.83:8080/charts/mysql-1.6.4.tgzversion: 1.6.4 generated: "2022-01-13T02:22:19.440764685+08:00"會(huì)發(fā)現(xiàn)索引文件已經(jīng)被更新,entries里有兩個(gè)對象,上傳相關(guān)的數(shù)據(jù)
┌──[root@vms81.liruilongs.github.io]-[~/ansible] └─$ansible 192.168.26.83 -m copy -a "src=./k8s-helm-create/index.yaml dest=/data/" 192.168.26.83 | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"},"changed": true,"checksum": "dbdc550a24159764022ede9428b9f11a09ccf291","dest": "/data/index.yaml","gid": 0,"group": "root","md5sum": "b771d8e50dd49228594f8a566117f8bf","mode": "0644","owner": "root","size": 1213,"src": "/root/.ansible/tmp/ansible-tmp-1642012325.1-89511-190591844764611/source","state": "file","uid": 0 } ┌──[root@vms81.liruilongs.github.io]-[~/ansible] └─$ansible 192.168.26.83 -m copy -a "src=./k8s-helm-create/liruilonghelm-0.1.0.tgz dest=/data/" 192.168.26.83 | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"},"changed": true,"checksum": "f7fe8a0a7585adf23e3e23f8378e3e5a0dc13f92","dest": "/data/liruilonghelm-0.1.0.tgz","gid": 0,"group": "root","md5sum": "04670f9b7e614d3bc6ba3e133bddae59","mode": "0644","owner": "root","size": 3591,"src": "/root/.ansible/tmp/ansible-tmp-1642012352.54-89959-104738456182106/source","state": "file","uid": 0 }用私有倉庫chart部署應(yīng)用程序
添加私有源
┌──[root@vms81.liruilongs.github.io]-[~/ansible] └─$helm repo add liruilong_repo http://192.168.26.83:8080/charts "liruilong_repo" has been added to your repositories ┌──[root@vms81.liruilongs.github.io]-[~/ansible] └─$helm repo list NAME URL azure http://mirror.azure.cn/kubernetes/charts/ ali https://apphub.aliyuncs.com liruilong_repo http://192.168.26.83:8080/charts私有源查找安裝的chart
┌──[root@vms81.liruilongs.github.io]-[~/ansible] └─$helm search repo mysql | grep liruilong liruilong_repo/mysql 1.6.4 5.7.30 Fast, reliable, scalable, and easy to use open-... ┌──[root@vms81.liruilongs.github.io]-[~/ansible] └─$安裝私有源chart
┌──[root@vms81.liruilongs.github.io]-[~/ansible] └─$helm list NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION ┌──[root@vms81.liruilongs.github.io]-[~/ansible/k8s-helm-create] └─$helm install liruilongdb liruilong_repo/mysql NAME: liruilongdb LAST DEPLOYED: Thu Jan 13 02:42:41 2022 NAMESPACE: liruilong-network-create STATUS: deployed REVISION: 1 NOTES: MySQL can be accessed via port 3306 on the following DNS name from within your cluster: liruilongdb-mysql.liruilong-network-create.svc.cluster.localTo get your root password run:MYSQL_ROOT_PASSWORD=$(kubectl get secret --namespace liruilong-network-create liruilongdb-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 -il2. Install the mysql client:$ apt-get update && apt-get install mysql-client -y3. Connect using the mysql cli, then provide your password:$ mysql -h liruilongdb-mysql -pTo connect to your database directly from outside the K8s cluster:MYSQL_HOST=127.0.0.1MYSQL_PORT=3306# Execute the following command to route the connection:kubectl port-forward svc/liruilongdb-mysql 3306mysql -h ${MYSQL_HOST} -P${MYSQL_PORT} -u root -p${MYSQL_ROOT_PASSWORD}驗(yàn)證安裝,查看chart列表
┌──[root@vms81.liruilongs.github.io]-[~/ansible/k8s-helm-create] └─$helm list NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION liruilongdb liruilong-network-create 1 2022-01-13 02:42:41.537928447 +0800 CST deployed mysql-1.6.4 5.7.30 ┌──[root@vms81.liruilongs.github.io]-[~/ansible/k8s-helm-create] └─$在helm install命令的執(zhí)行過程中,可以使用helm status命令跟蹤 Release的狀態(tài):Helm不會(huì)等待所有創(chuàng)建過程的完成,這是因?yàn)橛行〤hart的Docker鏡像較大,會(huì)消耗很長的時(shí)間進(jìn)行下載和創(chuàng)建
┌──[root@vms81.liruilongs.github.io]-[~/ansible/k8s-helm-create] └─$helm status liruilongdb NAME: liruilongdb LAST DEPLOYED: Thu Jan 13 02:42:41 2022 NAMESPACE: liruilong-network-create STATUS: deployed REVISION: 1 NOTES: MySQL can be accessed via port 3306 on the following DNS name from within your cluster: liruilongdb-mysql.liruilong-network-create.svc.cluster.localTo get your root password run:MYSQL_ROOT_PASSWORD=$(kubectl get secret --namespace liruilong-network-create liruilongdb-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 -il2. Install the mysql client:$ apt-get update && apt-get install mysql-client -y3. Connect using the mysql cli, then provide your password:$ mysql -h liruilongdb-mysql -pTo connect to your database directly from outside the K8s cluster:MYSQL_HOST=127.0.0.1MYSQL_PORT=3306# Execute the following command to route the connection:kubectl port-forward svc/liruilongdb-mysql 3306mysql -h ${MYSQL_HOST} -P${MYSQL_PORT} -u root -p${MYSQL_ROOT_PASSWORD}在成功安裝Chart后,系統(tǒng)會(huì)在當(dāng)前命名空間內(nèi)創(chuàng)建一個(gè)ConfigMap用于保存Release對象的數(shù)據(jù)
┌──[root@vms81.liruilongs.github.io]-[~/ansible/k8s-helm-create] └─$kubectl get configmaps NAME DATA AGE kube-root-ca.crt 1 12d liruilongdb-mysql-test 1 2d19h ┌──[root@vms81.liruilongs.github.io]-[~/ansible/k8s-helm-create] └─$kubectl describe configmaps liruilongdb-mysql-test Name: liruilongdb-mysql-test Namespace: liruilong-network-create Labels: app=liruilongdb-mysqlapp.kubernetes.io/managed-by=Helmchart=mysql-1.6.4heritage=Helmrelease=liruilongdb Annotations: meta.helm.sh/release-name: liruilongdbmeta.helm.sh/release-namespace: liruilong-network-createData ==== run.sh: ---- @test "Testing MySQL Connection" {mysql --host=liruilongdb-mysql --port=3306 -u root -ptesting }BinaryData ====Events: <none> ┌──[root@vms81.liruilongs.github.io]-[~/ansible/k8s-helm-create] └─$可以通過 helm delete 命令刪除運(yùn)行的Release
┌──[root@vms81.liruilongs.github.io]-[~/ansible/k8s-helm-create] └─$kubectl get pods NAME READY STATUS RESTARTS AGE liruilongdb-mysql-5cbf489f65-6ff4q 1/1 Running 1 (56m ago) 26h ┌──[root@vms81.liruilongs.github.io]-[~/ansible/k8s-helm-create] └─$helm delete liruilongdb release "liruilongdb" uninstalled ┌──[root@vms81.liruilongs.github.io]-[~/ansible/k8s-helm-create] └─$kubectl get pods NAME READY STATUS RESTARTS AGE liruilongdb-mysql-5cbf489f65-6ff4q 1/1 Terminating 1 (57m ago) 26h ┌──[root@vms81.liruilongs.github.io]-[~/ansible/k8s-helm-create] └─$關(guān)于Helm和小伙伴就分享到這里,其實(shí)還有很大,比如chart更新回滾,模板導(dǎo)出等。有遇到的做補(bǔ)充。生活加油
總結(jié)
以上是生活随笔為你收集整理的关于Kubernetes中使用Helm部署应用及私有Helm源搭建的一些笔记的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Learning Visual Comm
- 下一篇: BZOJ 4566 [Haoi2016]