kubernetes:从init容器中装入卷
我试图利用init容器在主容器启动之前准备一些文件。在init容器中,我想挂载一个kubernetes:从init容器中装入卷,kubernetes,Kubernetes,我试图利用init容器在主容器启动之前准备一些文件。在init容器中,我想挂载一个hostPath卷,以便为主容器共享和准备一些文件 我的集群使用的是kubernetes的1.6之前版本,因此我使用的是meta.annotation语法: pod.beta.kubernetes.io/init-containers: '[ { "name": "init-myservice", "image": "busybox", "command":
hostPath
卷,以便为主容器共享和准备一些文件
我的集群使用的是kubernetes的1.6之前版本,因此我使用的是meta.annotation
语法:
pod.beta.kubernetes.io/init-containers: '[
{
"name": "init-myservice",
"image": "busybox",
"command": ["sh", "-c", "mkdir /tmp/jack/ && touch cd /tmp/jack && touch a b c"],
"volumeMounts": [{
"mountPath": "/tmp/jack",
"name": "confdir"
}]
}
]'
但它似乎不起作用。添加volumeMounts
会导致容器init myserver
进入崩溃循环。如果没有它,pod会成功创建,但它无法实现我想要的
在中,您是否不需要执行
hostPath
volume来与Pod的容器共享init容器生成的数据。您可以使用emptyDir
获得相同的结果。使用emptyDir
的好处是,您不需要在主机上执行任何操作,即使您无法访问该群集上的节点,这也适用于任何类型的群集
使用hostPath
的另一个问题是在主机上的该文件夹上设置适当的权限。如果您使用的是任何启用SELinux的发行版,则必须在该目录上设置正确的上下文
apiVersion: v1
kind: Pod
metadata:
name: init
labels:
app: init
annotations:
pod.beta.kubernetes.io/init-containers: '[
{
"name": "download",
"image": "axeclbr/git",
"command": [
"git",
"clone",
"https://github.com/mdn/beginner-html-site-scripted",
"/var/lib/data"
],
"volumeMounts": [
{
"mountPath": "/var/lib/data",
"name": "git"
}
]
}
]'
spec:
containers:
- name: run
image: docker.io/centos/httpd
ports:
- containerPort: 80
volumeMounts:
- mountPath: /var/www/html
name: git
volumes:
- emptyDir: {}
name: git
检查上面的示例,其中init容器和pod中的容器共享名为git
的相同卷。卷的类型是emptyDir
。我只希望init容器在每次这个pod出现时都会提取数据,然后从pod的httpd
容器中提供数据
嗯