[英]Kubernetes - easy way to declaratively include a config file?
嘗試復制一個Nginx conf文件供我的pod使用(位於<project>/nginx.conf
)。 使用Docker compose我可以簡單地執行以下操作...
image: "nginx:alpine"
ports:
- "80:80"
volumes:
- ./nginx.conf:/etc/nginx/conf.d/default.conf
最佳實踐? 不確定,因為這對我來說是新事物。 看起來效果不錯。 我想通過kubernetes部署實現相同的目的,但是沒有找到一種直接的方式來聲明性地做到這一點。 我在ConfigMap上遇到了一些問題,但是當遇到以下問題時有點耐心 ...
使用kubectl create configmap命令從目錄,文件或文字值創建configmap
我不希望在文本文件中分散記住很多這些命令,而更喜歡使用compose所示的文件方法。 這可以實現嗎? 到目前為止我的規格看起來像這樣...
spec:
containers:
- name: nginx
image: nginx:alpine
ports:
- containerPort: 80
name: http
幫助我在這里獲取配置?
ConfigMap是絕對可行的方法。 您可以使用如下規格創建configmap:
apiVersion: v1
kind: ConfigMap
metadata:
name: nginx
namespace: default
data:
nginx.conf: |-
user www;
worker_processes 5;
...
# all nginx.conf file contents goes here
使用kubectl應用configmap后,可以通過在PodSpec中指定以下內容將其掛載到容器中:
containers:
- name: ...
...
volumeMounts:
- name: nginx-volume
mountPath: <path where you want to put nginx.conf>
volumes:
- name: nginx-volume
configMap:
name: nginx
請注意,您將選擇作為nginx.conf文件安裝點的目錄僅包含該文件(隱藏該目錄中已經存在的所有其他文件),與在Linux中將設備安裝在非空目錄上時的情況完全相同。
有關configmap的更多詳細信息,請參見: https ://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.