k8s_Helm 基本使用(部署,升级,回滚,删除)
1,创建一个chart[root@k8s-master ~]# helm create mychartCreating mychart2,删除默认文件[root@k8s-master templates]# pwd/root/mychart/templates[root@k8s-master templates]# lsdeployment.yaml_helpers...
·
1,创建一个chart
[root@k8s-master ~]# helm create mychart
Creating mychart
2,删除默认文件
[root@k8s-master templates]# pwd
/root/mychart/templates
[root@k8s-master templates]# ls
deployment.yaml _helpers.tpl ingress.yaml NOTES.txt serviceaccount.yaml service.yaml tests
[root@k8s-master templates]# rm -rf *
3.新建测试文件
[root@k8s-master templates]# cat NOTES.txt
hello
4,把项目文件deployment 和 service yaml 文件拷贝过来
[root@k8s-master templates]# cp /root/xiangmu/zhiyue.yaml .
5,安装新建的mychart
[root@k8s-master ~]# helm install zhiyueadmin mychart/
NAME: zhiyueadmin
LAST DEPLOYED: Sun May 3 22:57:45 2020
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
hello
6,查看
[root@k8s-master templates]# helm list
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
zhiyueadmin default 1 2020-05-03 22:57:45.79447501 +0800 CST deployed mychart-0.1.0 1.16.0
[root@k8s-master templates]# kubectl get pods
NAME READY STATUS RESTARTS AGE
echowebvue-69467b45f7-svbqx 1/1 Running 0 4d1h
jenkins-fcc9d45fc-v97hx 1/1 Running 0 4d12h
nfs-client-provisioner-75b84f8458-cjq28 1/1 Running 0 11d
zhiyueadmin-7bb864f5df-sp9zn 1/1 Running 0 8m33s
7,开始用变量文件,values.yaml,那么一套yaml 部署差异化的地方
a,资源名称 b,镜像地址 c, pv/pvc 目录位置 d,端口 e, 命名空间 f,标签 g,service端口,服务类型 h,副本数
[root@k8s-master ~]# cat mychart/values.yaml
image: 10.1.1.11/library/zhiyueadmin
tag: 7
replicas: 2
8,让项目文件引用变量文件
[root@k8s-master xiangmu]# cat /root/mychart/templates/zhiyue.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: zhiyueadmin
name: zhiyueadmin
spec:
replicas: {{ .Values.replicas }}
selector:
matchLabels:
app: zhiyueadmin
template:
metadata:
creationTimestamp: null
labels:
app: zhiyueadmin
spec:
containers:
- name: zhiyueadmin
image: {{ .Values.image }}:{{ .Values.tag }}
ports:
- containerPort: 80
resources:
limits:
cpu: 1
memory: 2Gi
requests:
cpu: 0.5
memory: 1Gi
volumeMounts:
- name: zhiyueadmin
mountPath: /usr/share/nginx/html/
volumes:
- name: zhiyueadmin
persistentVolumeClaim:
claimName: zhiyueadmin-pvc
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: zhiyueadmin-pvc
spec:
storageClassName: managed-nfs-storage
accessModes:
- ReadWriteMany
resources:
requests:
storage: 1Gi
---
apiVersion: v1
kind: Service
metadata:
name: zhiyueadmin
spec:
type: NodePort
selector:
app: zhiyueadmin
ports:
- protocol: TCP
port: 80
targetPort: 80
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: zhiyueadmin
namespace: default
spec:
rules:
- host: zhiyueadmin.rpdns.com
http:
paths:
- path: /
backend:
serviceName: zhiyueadmin
servicePort: 80
9,安装
[root@k8s-master xiangmu]# helm install zhiyuemy /root/mychart/
NAME: zhiyuemy
LAST DEPLOYED: Sun May 3 23:43:21 2020
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
hello
10,查看
[root@k8s-master xiangmu]# kubectl get pods
NAME READY STATUS RESTARTS AGE
echowebvue-69467b45f7-svbqx 1/1 Running 0 4d2h
jenkins-fcc9d45fc-v97hx 1/1 Running 0 4d12h
nfs-client-provisioner-75b84f8458-cjq28 1/1 Running 0 11d
zhiyueadmin-7bb864f5df-5dr97 1/1 Running 0 2m5s
zhiyueadmin-7bb864f5df-drw22 1/1 Running 0 2m5s
11,用helm 动态更新
[root@k8s-master xiangmu]# helm list
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
zhiyueadmin default 1 2020-05-03 22:57:45.79447501 +0800 CST deployed mychart-0.1.0 1.16.0
zhiyuemy default 1 2020-05-03 23:43:21.088297068 +0800 CST deployed mychart-0.1.0 1.16.0
[root@k8s-master xiangmu]# helm upgrade zhiyuemy --set replicas=3 /root/mychart/
Release "zhiyuemy" has been upgraded. Happy Helming!
NAME: zhiyuemy
LAST DEPLOYED: Sun May 3 23:48:13 2020
NAMESPACE: default
STATUS: deployed
REVISION: 2
TEST SUITE: None
NOTES:
hello
12,再次查看,可以看到副本数增加了
[root@k8s-master xiangmu]# kubectl get pods
NAME READY STATUS RESTARTS AGE
jenkins-fcc9d45fc-v97hx 1/1 Running 0 4d12h
nfs-client-provisioner-75b84f8458-cjq28 1/1 Running 0 11d
zhiyueadmin-7bb864f5df-5dr97 1/1 Running 0 6m9s
zhiyueadmin-7bb864f5df-9spgt 1/1 Running 0 77s
zhiyueadmin-7bb864f5df-drw22 1/1 Running 0 6m9s
13,回滚到版本 1
[root@k8s-master xiangmu]# helm list
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
zhiyueadmin default 1 2020-05-03 22:57:45.79447501 +0800 CST deployed mychart-0.1.0 1.16.0
zhiyuemy default 2 2020-05-03 23:48:13.651886259 +0800 CST deployed mychart-0.1.0 1.16.0
[root@k8s-master xiangmu]# helm rollback zhiyuemy 1
Rollback was a success! Happy Helming!
更多推荐
已为社区贡献29条内容
所有评论(0)