通過tar包安裝,命令舉例:helm install xxx-1.tgz(不推薦使用);
通過chart本地目錄安裝,命令舉例:helm install xxx/xxx(一般是使用helm fetch stable/xxxxx 下載相應(yīng)的模板,然后使用tar zxf 解壓,修改解壓后的目錄中的valumes.yaml文件中的值,就是自定義服務(wù)了,這種方式比較常用);
通過URL安裝,不太常用,命令舉例:helm install https://xxxx/charts/xxx-1.gz 。

二、自定義Chart包舉例

[root@master ~]# helm create testchart     #創(chuàng)建testchar包
#如果沒有“tree”命令,可以使用“yum -y install tree”進(jìn)行安裝
[root@master ~]# tree -C testchart/        #可以看到生成的目錄下各種模板都有了,根據(jù)業(yè)務(wù)需求進(jìn)行更改即可
testchart/
├── charts
├── Chart.yaml
├── templates
│ ├── deployment.yaml
│ ├── _helpers.tpl
│ ├── ingress.yaml
│ ├── NOTES.txt
│ ├── service.yaml
│ └── tests
│     └── test-connection.yaml
└── values.yaml
[root@master ~]# helm install testchart/ --dry-run --debug
#“--dry-run”:模擬安裝;“--debug” :檢測(cè)輸出
#執(zhí)行上述命令后,即可輸出該目錄模板的yaml文件內(nèi)容
[root@master ~]# helm lint testchart/    #對(duì)該目錄的內(nèi)容進(jìn)行語(yǔ)法檢測(cè),testchart是目錄名
==> Linting testchart/
[INFO] Chart.yaml: icon is recommended

1 chart(s) linted, no failures

附加:https://hub.helm.sh/ ,這是一個(gè)helm模板倉(cāng)庫(kù)的網(wǎng)站,上面有大量的helm模板,可以自行查看。

三、運(yùn)行一個(gè)mysql服務(wù)進(jìn)行示例
1、部署NFS服務(wù)

[root@master ~]# yum -y install nfs-utils
[root@master ~]# vim /etc/exports
/nfsdata *(rw,sync,no_root_squash)
[root@master ~]# systemctl start rpcbind
[root@master ~]# systemctl start nfs-server
[root@master ~]# showmount -e
Export list for master:
/nfsdata *

2、創(chuàng)建一個(gè)PV

[root@master ~]# vim Mysql-pv.yaml        #編寫yaml文件

apiVersion: v1
kind: PersistentVolume
metadata:
  name: MYSQL-pv
spec:
  accessModes:
    - ReadWriteOnce
  capacity:
    storage: 8Gi
  persistentVolumeReclaimPolicy: Retain
  nfs:
    path: /nfsdata/mysql-pv     #指定本地的掛載目錄
    server: 192.168.20.6
[root@master ~]# mkdir -p /nfsdata/mysql-pv   #創(chuàng)建nfs的本地目錄
[root@master ~]# kubectl apply -f mysql-pv.yaml      #執(zhí)行yaml文件
[root@master ~]# kubectl get pv       #確定pv狀態(tài)正常
NAME       CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS      CLAIM   STORAGECLASS   REASON   AGE
mysql-pv   8Gi        RWO            Retain           Available                                   73s
#狀態(tài)為“Available”表示pv正常

3、helm部署MySQL

[root@master ~]# helm install stable/mysql --set mysqlRootPassword=123.com -n test-mysql
#在線安裝MySQL,并設(shè)置mysql的root密碼為123.com,“-n”表示指定其名稱
#查看其pod
[root@master ~]# helm list    #使用helm查看
NAME        REVISION    UPDATED                     STATUS      CHART       APP VERSION NAMESPACE
test-mysql  1           Sun Dec  1 21:22:56 2019    DEPLOYED    mysql-0.3.5             default  
[root@master ~]# kubectl get pod -o wide     #查看mysql所對(duì)應(yīng)的pod
NAME                               READY   STATUS    RESTARTS   AGE     IP           NODE     NOMINATED NODE   READINESS GATES
test-mysql-mysql-dfb9b6944-4kmgv   1/1     Running   0          9m16s   10.244.2.2   node02   <none>           <none>
 #可以登錄數(shù)據(jù)庫(kù)進(jìn)行測(cè)試
[root@master ~]# kubectl exec -it test-mysql-mysql-dfb9b6944-4kmgv -- mysql -uroot -p123.com        

當(dāng)install安裝后,會(huì)輸出一些提示信息,其中就包括了查看MySQL數(shù)據(jù)庫(kù)密碼的命令,如果沒有使用“–set”命令設(shè)置數(shù)據(jù)庫(kù)的root密碼,那么可以通過此命令查看出默認(rèn)的數(shù)據(jù)庫(kù)root與用戶密碼,提示命令如下:

也可以通過以下命令查看到關(guān)于test-mysql實(shí)例的詳細(xì)狀態(tài)信息

[root@master ~]# helm status test-mysql   #查看test-mysql的實(shí)例信息

在線升級(jí)MySQL鏡像操作

[root@master ~]# helm upgrade --set imageTag=5.7.16 test-mysql stable/mysql
#其中test-mysql是實(shí)例名稱;
# 還是需要指定初次運(yùn)行時(shí)指定的stable/mysql文件,如果初次運(yùn)行時(shí)指定的是目錄,那么這里就換成目錄
#驗(yàn)證鏡像是否更新成功
[root@master ~]# kubectl describe pod test-mysql-mysql-68484cd8db-59wm5 

上述命令執(zhí)行后,輸出的結(jié)果如下(可以看到鏡像的版本已經(jīng)更新):

[root@master ~]# helm list      #再次查看實(shí)例,可以發(fā)現(xiàn)“REVISION”字段為2,而初次創(chuàng)建實(shí)例時(shí),該列為1,
#每更新一次,該數(shù)值就會(huì) 1.
NAME        REVISION    UPDATED                     STATUS      CHART       APP VERSION NAMESPACE
test-mysql  2           Sun Dec  1 21:53:00 2019    DEPLOYED    mysql-0.3.5             default  

[root@master ~]# helm history test-mysql     #查看該實(shí)例的歷史版本
REVISION    UPDATED                     STATUS      CHART       DESCRIPTION     
1           Sun Dec  1 21:22:56 2019    SUPERSEDED  mysql-0.3.5 Install complete
2           Sun Dec  1 21:53:00 2019    DEPLOYED    mysql-0.3.5 Upgrade complete

進(jìn)行test-mysql實(shí)例的版本回滾

[root@master ~]# helm rollback test-mysql 1    #回滾到版本1
Rollback was a success.

[root@master ~]# helm list   #再次查看,可以看到“REVISION”的值變成了3
NAME        REVISION    UPDATED                     STATUS      CHART       APP VERSION NAMESPACE
test-mysql  3           Sun Dec  1 22:12:25 2019    DEPLOYED    mysql-0.3.5             default  
#查看MySQL對(duì)應(yīng)的容器詳細(xì)信息
[root@master ~]# kubectl describe pod test-mysql-mysql-dfb9b6944-8hfj4 

返回的信息如下,可以看到鏡像的版本已經(jīng)回滾到初次創(chuàng)建的版本了,如下:

———————— 本文至此結(jié)束,感謝閱讀 ————————

更多關(guān)于云服務(wù)器域名注冊(cè),虛擬主機(jī)的問題,請(qǐng)?jiān)L問三五互聯(lián)官網(wǎng):www.shinetop.cn

贊(0)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享網(wǎng)絡(luò)內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。郵箱:3140448839@qq.com。本站原創(chuàng)內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明出處:三五互聯(lián)知識(shí)庫(kù) » K8s之helm工具使用舉例

登錄

找回密碼

注冊(cè)