我将使用K8S来编排Docker容器。在k8s中,我需要将文件从主机目录(/configs/nginx/cas-server.conf)复制到pod容器目录(/etc/nginx/nginx.conf),但是当前的k8s仅允许装入目录,而不允许装入/复制文件。如何解决这个问题呢?
以下是我的nginx-cas-server-deply.yaml文件。
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: nginx-cas-server-depl
spec:
replicas: 1
template:
metadata:
labels:
app: nginx-cas-server-pod
spec:
containers:
- name: nginx-cas-server-pod
image: nginx
imagePullPolicy: Never
ports:
- containerPort: 100
volumeMounts:
- mountPath: /etc/nginx/nginx.conf
name: nginx-cas-server-conf
- mountPath: /app/cas-server/public
name: nginx-cas-server-public
volumes:
- name: nginx-cas-server-conf
hostPath:
path: /configs/nginx/cas-server.conf
- name: nginx-cas-server-public
hostPath:
path: /cas-server/public
Run Code Online (Sandbox Code Playgroud)
在您部署的配置,你需要使用mountPath与目录和文件名和subPath字段文件名。同样,重要的是,您需要在节点上完全按照要挂载的/etc/nginx/nginx.conf方式命名文件,因此,如果要挂载到,则文件应命名为nginx.conf
这是示例:
节点上目录的内容:
# ls /config/
nginx.conf some_dir
Run Code Online (Sandbox Code Playgroud)
Nginx部署的配置文件
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
labels:
run: nginx
name: nginx
namespace: default
spec:
replicas: 1
selector:
matchLabels:
run: nginx
template:
metadata:
labels:
run: nginx
spec:
containers:
- image: nginx
name: nginx
volumeMounts:
- mountPath: /etc/nginx/nginx.conf
name: test
subPath: nginx.conf
volumes:
- hostPath:
path: /config
name: test
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3073 次 |
| 最近记录: |