Less than 1 minute
apiVersion: apps/v1
kind: Deployment
metadata:
name: hellok8s-go-http
spec:
strategy:
type: Recreate # 因为下面使用hostPort进行测试,所以更新时只能先销毁再创建
replicas: 1
selector:
matchLabels:
app: hellok8s
template:
metadata:
labels:
app: hellok8s
spec:
containers:
- image: leigg/hellok8s:v4_secret
name: hellok8s
ports:
- containerPort: 3000
hostPort: 3000
env:
- name: DB_PASSWD
valueFrom:
secretKeyRef:
name: hellok8s-secret
key: DB_PASSWD
- name: LOG_LEVEL
valueFrom:
secretKeyRef:
name: hellok8s-secret # name必须是有效且存在的
key: not_found_key
optional: true # 允许key不存在,这样在key找不到时不会影响Pod启动
volumeMounts:
- name: secret-volume
mountPath: "/etc/secret_vol"
volumes:
- name: secret-volume
secret:
secretName: hellok8s-secret