我最近了解到Kubernetes有一个名为Init Containers的功能.太棒了,因为我可以使用此功能等待我的postgres服务,并在我的Web应用程序服务运行之前创建/迁移数据库.
但是,似乎只能在Pod yaml文件中配置Init Containers.有没有办法通过部署yaml文件来做到这一点?或者我必须选择?
小智 6
为避免混乱,请您回答您的具体问题。我同意oswin,您可能要考虑另一种方法。
是的,您可以在部署中使用初始化容器。这是使用旧样式(1.6之前的版本)的示例,但它应该可以工作
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'
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6608 次 |
| 最近记录: |