K8s一键式部署应用----Helm

实验要求:成功部署Kubernetes

基础操作

Helm官方版本大全;下载软件包并解压和移动目录

[root@k8s-master opt]# wget https://get.helm.sh/helm-v3.0.0-linux-amd64.tar.gz
[root@k8s-master opt]# tar -zxf helm-v3.0.0-linux-amd64.tar.gz 
[root@k8s-master opt]# mv linux-amd64/helm /usr/bin/

配置helm仓库地址

微软云的heml;添加仓库地址并查看

[root@k8s-master ~]# helm repo add stable http://mirror.azure.cn/kubernetes/charts
"stable" has been added to your repositories
[root@k8s-master ~]# helm repo list
NAME  	URL                                     
stable	http://mirror.azure.cn/kubernetes/charts
[root@k8s-master ~]# 

查看K8s的UI并部署

[root@k8s-master ~]# helm search repo weave
NAME              	CHART VERSION	APP VERSION	DESCRIPTION                                       
stable/weave-cloud	0.3.9        	1.4.0      	DEPRECATED - Weave Cloud is a add-on to Kuberne...
stable/weave-scope	1.1.12       	1.12.0     	DEPRECATED - A Helm chart for the Weave Scope c...
[root@k8s-master ~]# helm install ui stable/weave-scope

在这里插入图片描述

查看部署好的hlem

[root@k8s-master ~]# helm list
NAME	NAMESPACE	REVISION	UPDATED                                	STATUS  	CHART             	APP VERSION
ui  	default  	1       	2021-12-03 16:47:19.373957437 +0800 CST	deployed	weave-scope-1.1.12	1.12.0     
[root@k8s-master ~]# kubectl get pods,svc

在这里插入图片描述

修改ui-weave-scope中SVC的type: NodePort,使其能够在浏览器中访问

[root@k8s-master ~]# kubectl edit svc/ui-weave-scope
service/ui-weave-scope edited
[root@k8s-master ~]# kubectl get svc
NAME             TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)        AGE
java             NodePort    10.96.187.217   <none>        80:31518/TCP   85m
kubernetes       ClusterIP   10.96.0.1       <none>        443/TCP        168m
nginx            NodePort    10.96.79.79     <none>        80:30003/TCP   68m
ui-weave-scope   NodePort    10.96.153.12    <none>        80:30763/TCP   6m8s
[root@k8s-master ~]# 

在这里插入图片描述

浏览器验证:http://NodeIP:Port
在这里插入图片描述

创建chart

helm create 名字----创建一个chart基础模板

[root@k8s-master ~]# helm create mychar
Creating mychar
[root@k8s-master ~]# cd mychar/
[root@k8s-master mychar]# ls
charts  Chart.yaml  templates  values.yaml

charts:一般不放文件。
Chart.yaml:当前chart的属性信息,如名字。
templates:当前chart的所有模板文件。
values.yaml:所有yaml的全局变量。

使用chart部署应用

#清除原先templates目录下的内容
[root@k8s-master mychar]# rm -rf templates/*
[root@k8s-master mychar]# ls templates/

#将所需要的yaml文件移到当前chart下的templates目录中
[root@k8s-master mychar]# mv /opt/tomcat-java-demo-master/nginx.yaml templates/
[root@k8s-master mychar]# mv /opt/tomcat-java-demo-master/nginx-svc.yaml templates/

#直接使用chart安装应用;web是名字可以随便起
[root@k8s-master ~]# helm install web mychar/
NAME: web
LAST DEPLOYED: Fri Dec  3 17:08:39 2021
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
[root@k8s-master ~]# helm list
NAME	NAMESPACE	REVISION	UPDATED                                	STATUS  	CHART             	APP VERSION
ui  	default  	1       	2021-12-03 16:47:19.373957437 +0800 CST	deployed	weave-scope-1.1.12	1.12.0     
web 	default  	1       	2021-12-03 17:08:39.060358707 +0800 CST	deployed	mychar-0.1.0      	1.16.0     

#查看当前创建的svc和容器
[root@k8s-master ~]# kubectl get svc,pods

升级

动态传参:helm upgrade helm名字 --set 需要修改的内容 chart名字

[root@k8s-master ~]# helm upgrade web --set replicas=3 mychar/
Release "web" has been upgraded. Happy Helming !NAME: web1
LAST DEPLOYED: Fri Dec 3 17:10:56 2021NAMESPACE: default
STATUS: deployedREVISION :2
TEST SUITE: None
[root@k8s-master ~]# helm list
[root@k8s-master ~]# kubectl get pods

回滚

helm rollback helm名字 版本号

[root@k8s-master ~]# helm history web
REVISION	UPDATED						STATUS		CHART		  APP VERSION  DESCRIPTION
1			Fri Dec 3 17:08:42 2021		superseded  	mychar-0.1.0  1.16.0
Install complete
2			Fri Dec 3 17:10:56 2021		deployed		mychart-0.1.0 1.16.0
Upgrade complete
[root@k8s-master ~]# helm rollback web 1
Rollback was a success! Happy Helming!

猜你喜欢

转载自blog.csdn.net/weixin_46329906/article/details/121790855
今日推荐