|NO.Z.00022|——————————|CloudNative|——|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

 
 
 
 
 
 
 
 
 

Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart
                                                                                                                                                   ——W.S.Landor

 

 

posted on   yanqi_vip  阅读(23)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示