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

 

posted @ 2020-04-15 14:29  huningfei  阅读(804)  评论(0编辑  收藏  举报
levels of contents