k8s-helm-v3安装管理

k8s-helm-v3安装管理

Helm | Helm 3.0.0 has been released! 官网介绍helm3

Artifact Hub 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版本不存在彻底删除,也不能查看被删除的

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值