- 影射的nginx配置文件:
加好了狀態(tài)碼顯示/stub_status
路由
vi nginx-test.conf
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
location /stub_status {
allow 127.0.0.1;
stub_status on;
}
}
- 編寫yaml文件
vi nginx-deployment.yaml
apiVersion: v1
kind: Pod
metadata:
name: test-configmap-nginx
spec:
containers:
- name: nginx # 容器的名字
image: nginx:alpine # 鏡像的名字
ports:
- containerPort: 80
volumeMounts:
- name: nginxcfmap
mountPath: "/etc/nginx/conf.d" # 掛載到容器中目錄萍程,這個目錄>會自動>創(chuàng)建
livenessProbe:
httpGet:
path: /
port: 80
httpHeaders:
- name: X-Custom-Header
value: Awesome
initialDelaySeconds: 3
periodSeconds: 3
volumes:
- name: nginxcfmap
configMap:
name: nginxcfmap # 創(chuàng)建 configmap 對象的名稱
items:
- key: nginx-test.conf # 創(chuàng)建 configmap 對象時指定的 key
path: nginx-test.conf # 容器 a 目錄中的文件名
-
創(chuàng)建configmap
注意configmap對象名稱nginxcfmap
和yaml文件中保持一致
kubectl create configmap nginxcfmap --from-file=nginx-test.conf=./nginx-test.conf
image.png -
啟動容器
kubectl create -f nginx-deployment.yaml
kubectl get pods
查看是否啟動成功
image.png -
查看部署nginx容器的ip
kubectl describe pod test-liveness-exec
image.png -
訪問默認跟路由
curl 192.168.122.51/
會出現(xiàn)nginx默認首頁的代碼
image.png -
訪問配置的狀態(tài)碼路由
curl 10.100.5.210/stub_status/
image.png