参考链接https://blog.csdn.net/jerry00713/article/details/123220938
apiVersion: v1
kind: Secret
metadata:
name: secret1
data:
#REDISPASSWORD: redis654321
REDISPASSWORD: cmVkaXM2NTQzMjE=
也可以通过命令行kubectl get secret -o yaml来查看。
可以使用环境变量
env:
- name: REDIS_LOCATION
valueFrom:
configMapKeyRef:
name: config1
key: REDIS_LOCATION
- name: DJANGO_DEBUG
valueFrom:
configMapKeyRef:
name: config1
key: DJANGO_DEBUG
- name: REDISPASSWORD
valueFrom:
secretKeyRef:
name: secret1
key: REDISPASSWORD
完整的web的yaml档案
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
kompose.cmd: kompose convert
kompose.version: 1.24.0 (7c629530)
creationTimestamp: null
labels:
io.kompose.service: web
name: web
spec:
replicas: 1
selector:
matchLabels:
io.kompose.service: web
strategy:
type: Recreate
template:
metadata:
annotations:
kompose.cmd: kompose convert
kompose.version: 1.24.0 (7c629530)
creationTimestamp: null
labels:
io.kompose.service: web
spec:
containers:
- command:
- /bin/sh
- /code/package/start.sh
image: seasonzhang/gaga_meeting:0.9.16
imagePullPolicy: IfNotPresent
name: gaga-meeting-web
ports:
- containerPort: 8000
resources:
requests:
cpu: 500m
memory: 500Mi
limits:
cpu: 500m
memory: 500Mi
env:
- name: REDIS_LOCATION
valueFrom:
configMapKeyRef:
name: config1
key: REDIS_LOCATION
- name: DJANGO_DEBUG
valueFrom:
configMapKeyRef:
name: config1
key: DJANGO_DEBUG
- name: REDISPASSWORD
valueFrom:
secretKeyRef:
name: secret1
key: REDISPASSWORD
- command:
- /bin/sh
- /code/package/start-beat.sh
image: seasonzhang/gaga_meeting:0.9.16
name: gaga-meeting-beat
resources:
requests:
cpu: 100m
memory: 100Mi
limits:
cpu: 200m
memory: 200Mi
- command:
- /bin/sh
- /code/package/start-celery.sh
image: seasonzhang/gaga_meeting:0.9.16
name: gaga-meeting-celery
resources:
requests:
cpu: 100m
memory: 100Mi
limits:
cpu: 200m
memory: 200Mi
---
apiVersion: v1
kind: Service
metadata:
annotations:
kompose.cmd: kompose convert
kompose.version: 1.24.0 (7c629530)
creationTimestamp: null
labels:
io.kompose.service: web
name: web
spec:
type: LoadBalancer
ports:
- name: "8000"
port: 8000
targetPort: 8000
rotocol: TCP
selector:
io.kompose.service: web
externalIPs: #集群内互访
- 10.0.8.10
- 10.43.207.93
status:
loadBalancer: {}
# 只是引用,但是没有使用
REDISPASSWORD = os.environ.get('REDISPASSWORD',"redis654321")