k8s-helm-v3安裝管理


k8s-helm-v3安裝管理

https://helm.sh/blog/helm-3-released/ 官網介紹helm3

https://hub.helm.sh/ helm倉庫

一 常用命令

1 helm安裝

https://github.com/helm/helm/releases/tag/v3.1.2 下載地址

1 下載3.0的版本,然后解壓,把helm命令移動到/usr/local/bin目錄下面

2 查看helm版本

helm version

 

2 配置下載源

 

helm repo add stable https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts

移除

helm repo remove 127854-hnf

3 查看下載源

 

[root@k8s-master01 helm-v3]# helm repo list
NAME  	URL                                                   
stable	https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts

 

4 查詢要安裝的pod

helm search repo weave #后面跟你要查找的軟件名字

helm search repo weave
NAME              	CHART VERSION	APP VERSION	DESCRIPTION                                       
stable/weave-cloud	0.1.2        	           	Weave Cloud is a add-on to Kubernetes which pro...
stable/weave-scope	0.9.2        	1.6.5      	A Helm chart for the Weave Scope cluster visual...

 

5 安裝一個鏡像(服務)

helm install ui stable/weave-scope # 其中ui為名字

 

[root@k8s-master01 helm-v3]# helm install ui stable/weave-scope
NAME: ui
LAST DEPLOYED: Fri Apr  3 18:15:36 2020
NAMESPACE: default
STATUS: deployed
REVISION: 1
NOTES:
You should now be able to access the Scope frontend in your web browser, by
using kubectl port-forward:

kubectl -n default port-forward $(kubectl -n default get endpoints \
ui-weave-scope -o jsonpath='{.subsets[0].addresses[0].targetRef.name}') 8080:4040

then browsing to http://localhost:8080/.
For more details on using Weave Scope, see the Weave Scope documentation:

https://www.weave.works/docs/scope/latest/introducing/

然后去更改下svc的類型,nodeport,然后去瀏覽器訪問:nodeip+端口

 

二 創建自己的mychart

1 創建mychart

 

helm create mychart

然后進去 mychart/templates/ 這個目錄下面,去創建基本的兩個文件,deployment和service

 

2 helm 安裝tomcat

  • 安裝

返回到跟mychart同級目錄下執行

[root@k8s-master01 helm-v3]# helm install tomcat mychart/
NAME: tomcat
LAST DEPLOYED: Fri Apr  3 18:40:18 2020
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None

 

然后去查看pod和svc去瀏覽器里面訪問tomcat頁面

  • 刪除

helm delete -f mychart/templtes

 

  • 升級(改完yaml文件之后重新應用)

helm upgrade tomcat mychart/

 

  • 擴容

helm upgrade web1 --set replicas=3 mychart/

 

三 用變量渲染模板

1 測試自己模板是否正常

 

helm install --dry-run tomcat mychart

 

2 模板在templates里面,

 

values.yaml 為變量:

 

[root@k8s-master01 helm-v3]# cat mychart/values.yaml 
replicas: 2

image: huningfei/tomcat8
tag: v1
label: tomcat
port: 8080

deployment.yaml

 

[root@k8s-master01 templates]# cat tomcat.yaml 
apiVersion: apps/v1
kind: Deployment #控制器名稱
metadata:
  name: {{ .Release.Name }}-dp
spec:
  replicas: {{ .Values.replicas }} #副本數量
  selector:
    matchLabels:
      app:  {{ .Values.label }}
  template:
    metadata:
      labels:
        app: {{ .Values.label }}
    spec:
      containers:
      - name: tomcat
        image:  {{ .Values.image }}:{{ .Values.tag }} #鏡像

svc模板

 

[root@k8s-master01 templates]# cat service_tomcat.yaml 
apiVersion: v1
kind: Service
metadata:
  name: {{ .Release.Name }}-svc
spec:
  type: NodePort
  ports:
   - port: 8080
     targetPort: {{ .Values.port}}
  selector:
    app: {{ .Values.label }}

兩個文件的變量都是從values.yaml里面傳遞過來的

Release.Name 代表helm install 后面的那個名字

 

3 擴容縮容回滾

helm upgrade web1 --set replicas=3 mychart/

 

回滾之前先helm list查看下版本,然后在回滾

helm rollback tomcat1 1 #名字加版本

 

4 刪除

helm delete name

3版本不存在徹底刪除,也不能查看被刪除的

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM