CC00022.CloudKubernetes——|Kubernetes&RBAC介绍.V04|——|helm-chart高效复用|

一、helm-chart高效复用(动态渲染yaml文件部署)
二、helm-chart高效复用实验
### --- 定义全局变量的配置文件

[root@k8s-master ~]# cd mychart/
[root@k8s-master mychart]# ls
values.yaml
### --- 在values.yaml定义变量和值

[root@k8s-master ~]# cd mychart/
[root@k8s-master mychart]# vim values.yaml 
replicas: 1
image: nginx
tag: 1.16
label: nginx
port: 80
### --- 在具体yaml文件,获取变量定义值
~~~     yaml文件大体有几个地方不同
~~~     image:镜像不一致
~~~     tag:镜像版本
~~~     label:label名称不一致
~~~     port:端口号不一致
~~~     replicats:副本数不一致

~~~     #在templates的yaml文件使用values.yaml定义变量
~~~     通过表达式形式使用全局变量
~~~     {{ .Values.变量名称}}
~~~     {{ .Release.Names}}
~~~     #第二种方案,取到当前版本的名称

[root@k8s-master mychart]# cd templates/
[root@k8s-master templates]# vim deployment.yaml 
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ .Release.Name}}-deploy
spec:
  replicas: 1
  selector:
    matchLabels:
      app: {{ .Values.label}}
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: {{ .Values.label}}
    spec:
      containers:
      - image: {{ .Values.image}}
        name: nginx
        resources: {}
status: {}
[root@k8s-master templates]# vim service.yaml
apiVersion: v1
kind: Service
metadata:
  name: {{ .Release.Name}}-svc
spec:
  ports:
  - port: {{ .Values.port}}
    protocol: TCP
    targetPort: 80
  selector:
    app: {{ .Values.label}}
  type: NodePort
status:
  loadBalancer: {}
### --- 创建生成yaml文件,

[root@k8s-master ~]# helm install --dry-run web2 mychart/
NAME: web2
LAST DEPLOYED: Tue Feb 23 21:39:51 2021
NAMESPACE: default
STATUS: pending-install
REVISION: 1
TEST SUITE: None
HOOKS:
MANIFEST:
---
# Source: mychart/templates/service.yaml
apiVersion: v1
kind: Service
metadata:
  name: web2-svc
spec:
  ports:
  - port: 80
    protocol: TCP
    targetPort: 80
  selector:
    app: nginx
  type: NodePort
status:
  loadBalancer: {}
---
# Source: mychart/templates/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: web2-deploy
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: nginx
    spec:
      containers:
      - image: nginx
        name: nginx
        resources: {}
status: {}
### --- 通过动态渲染yaml文件,部署应用

[root@k8s-master ~]# helm install web2 mychart
NAME: web2
LAST DEPLOYED: Tue Feb 23 21:41:50 2021
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
[root@k8s-master ~]# kubectl get pods
web2-deploy-f89759699-q2hzd                     1/1     Running     0          32s

[root@k8s-master ~]# kubectl get svc
web2-svc         NodePort    10.111.251.89   <none>        80:31700/TCP   74s
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

yanqi_vip

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值