此部署創建 1 個包含 init 容器的 pod。容器將卷掛載到 tmp/web-content 中,并將 1 行“check this out”寫入 index.html
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-init-container
namespace: mars
spec:
replicas: 1
selector:
matchLabels:
id: test-init-container
template:
metadata:
labels:
id: test-init-container
spec:
volumes:
- name: web-content
emptyDir: {}
initContainers:
- name: init-con
image: busybox:1.31.0
command: ['sh', '-c' ,"echo 'check this out' > /tmp/web-content/index.html"]
volumeMounts:
- name: web-content
mountPath: /tmp/web-content/
containers:
- image: nginx:1.17.3-alpine
name: nginx
volumeMounts:
- name: web-content
mountPath: /usr/share/nginx/html
ports:
- containerPort: 80
我啟動臨時 pod 以檢查是否可以使用 curl 看到這條“check this out”行。
k run tmp --restart=Never --rm -i --image=nginx:alpine -- curl 10.0.0.67
它確實顯示了這條線。但是,curl怎么知道要進入哪個目錄呢?我沒有指定它應該明確地轉到 /tmp/web-content
uj5u.com熱心網友回復:
這是因為mountPath:
root 指令指示虛擬主機的資產(HTML、影像、CSS 等)所在的硬碟驅動器上的實際路徑,即 /usr/share/nginx/html。index 設定告訴 Nginx 在被要求顯示目錄時要提供哪些檔案或哪些檔案
當您 curl 到默認埠 80 時,curl 會為您回傳 html 目錄的內容。.
uj5u.com熱心網友回復:
只是對@P.... answer 的詳細說明。
- 以下是創建一個名為“web-content”的公共存盤空間“標記”
?volumes:
?- name: web-content
?emptyDir: {}
- web-content 掛載在
/tmp/web-content/名為 init 的容器上,init-con該容器正在寫入check this outindex.html
initContainers:
- name: init-con
image: busybox:1.31.0
command: ['sh', '-c' ,"echo 'check this out' > /tmp/web-content/index.html"]
volumeMounts:
- name: web-content
mountPath: /tmp/web-content/
- 具有 的同一
web-content卷index.html被掛載為目錄/usr/share/nginx/html,因此該index.html位置將被視為/usr/share/nginx/html/index.html. (nginx 的默認登錄頁面)用于容器,nginx因此它會check this out在您卷曲到它時顯示。
containers:
- image: nginx:1.17.3-alpine
name: nginx
volumeMounts:
- name: web-content
mountPath: /usr/share/nginx/html
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/416756.html
標籤:
上一篇:curlPOST在命令列中作業,但不適用于Python
下一篇:PHPCURLSFTP讀取檔案?
