二、在templates的yaml文件中使用values.yaml定义的变量
通过表达式形式使用全局变量
{{.Values.变量名称}}
{{.Release.Name}}
[root@master mychart]# cd templates/[root@master templates]# ls
deployment.yaml service.yaml
[root@master templates]# vim deployment.yaml
[root@master templates]# vim service.yaml
[root@master ~]# helm install --dry-run web2 mychart/
NAME: web2
LAST DEPLOYED: Fri Jun 11 19:01:27 2021
NAMESPACE: default
STATUS: pending-install
REVISION: 1
TEST SUITE: None
HOOKS:
MANIFEST:
---
# Source: mychart/templates/service.yaml
apiVersion: v1
kind: Service
metadata:
creationTimestamp: null
labels:
app: nginx
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:
creationTimestamp: null
labels:
app: nginx
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: {}
#因为我前面使用web2创建时出错了,使得这个web2已被使用,所以出错换个名字就行
[root@master ~]# helm install web2 mychart/
Error: cannot re-use a name that is still in use
[root@master ~]# helm install web3 mychart/
NAME: web3
LAST DEPLOYED: Fri Jun 11 19:02:33 2021
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
[root@master ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
ds-test-489bb 1/1 Running 0 47h
ds-test-4rvcr 1/1 Running 0 47h
ds-test-nx6kt 1/1 Running 0 47h
web3-deploy-6799fc88d8-p74vt 1/1 Running 0 114s
[root@master ~]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 5d22h
web3-svc NodePort 10.99.114.106 <none> 80:32379/TCP 2m22s
B站学习网址:k8s教程由浅入深-尚硅谷哔哩哔哩bilibili