我想在deployment初始化成功后运行特定命令:
这是我的 yaml 文件:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: auth
spec:
replicas: 1
template:
metadata:
labels:
app: auth
spec:
containers:
- name: auth
image: {{my-service-image}}
env:
- name: NODE_ENV
value: "docker-dev"
resources:
requests:
cpu: 100m
memory: 100Mi
ports:
- containerPort: 3000
然而,我想在deployment成功初始化和pod运行之后(而不是之前)运行数据库迁移的命令。
我可以为每个pod手动操作(使用kubectl exec),但这太傻了。
用lifecycles(生命周期)可以实现:
apiVersion: extensions/v1beta1 kind: Deployment metadata: name: auth spec: replicas: 1 template: metadata: labels: app: auth spec: containers: - name: auth image: {{my-service-image}} env: - name: NODE_ENV value: "docker-dev" resources: requests: cpu: 100m memory: 100Mi ports: - containerPort: 3000 lifecycle: postStart: exec: command: ["/bin/sh", "-c", {{cmd}}]
你的答案