我最近了解到 Kubernetes 有一个名为 Init Containers 的功能。这很棒,因为我可以使用该功能在我的 Web 应用程序服务运行之前等待我的 postgres 服务并创建/迁移数据库。
然而,似乎只能在 Pod yaml 文件中配置 Init Containers。我是否可以通过 Deployment yaml 文件来实现这一点?还是我必须做出选择?
我最近了解到 Kubernetes 有一个名为 Init Containers 的功能。这很棒,因为我可以使用该功能在我的 Web 应用程序服务运行之前等待我的 postgres 服务并创建/迁移数据库。
然而,似乎只能在 Pod yaml 文件中配置 Init Containers。我是否可以通过 Deployment yaml 文件来实现这一点?还是我必须做出选择?
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: 'nginx'
spec:
replicas: 1
selector:
matchLabels:
app: 'nginx'
template:
metadata:
labels:
app: 'nginx'
annotations:
pod.beta.kubernetes.io/init-containers: '[
{
"name": "install",
"image": "busybox",
"imagePullPolicy": "IfNotPresent",
"command": ["wget", "-O", "/application/index.html", "http://kubernetes.io/index.html"],
"volumeMounts": [
{
"name": "application",
"mountPath": "/application"
}
]
}
]'
spec:
volumes:
- name: 'application'
emptyDir: {}
containers:
- name: webserver
image: 'nginx'
ports:
- name: http
containerPort: 80
volumeMounts:
- name: 'application'
mountPath: '/application'
initContainers
了。 - Mitkins