|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
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通