- 影射的nginx配置文件:
加好了状态码显示/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" # 挂载到容器中目录,这个目录>会自动>创建
livenessProbe:
httpGet:
path: /
port: 80
httpHeaders:
- name: X-Custom-Header
value: Awesome
initialDelaySeconds: 3
periodSeconds: 3
volumes:
- name: nginxcfmap
configMap:
name: nginxcfmap # 创建 configmap 对象的名称
items:
- key: nginx-test.conf # 创建 configmap 对象时指定的 key
path: nginx-test.conf # 容器 a 目录中的文件名
-
创建configmap
注意configmap对象名称nginxcfmap
和yaml文件中保持一致
kubectl create configmap nginxcfmap --from-file=nginx-test.conf=./nginx-test.conf
-
启动容器
kubectl create -f nginx-deployment.yaml
kubectl get pods
查看是否启动成功
-
查看部署nginx容器的ip
kubectl describe pod test-liveness-exec
-
访问默认跟路由
curl 192.168.122.51/
会出现nginx默认首页的代码
-
访问配置的状态码路由
curl 10.100.5.210/stub_status/