我使用命令行 kubectl 创建 configmap,如下所示:
kubectl create configmap nginx-config --from-file=./site.conf
在我的site.conf
我有一个简单的 nginx conf:
server {
listen 80;
index index.php index.html;
location / {
try_files $uri $uri/ /index.php?$args;
access_log off;
expires max;
}
}
在我的nginx-pod.yaml
我有正常的吊舱设置:
apiVersion: v1
kind: Pod
metadata:
name: www
labels:
app: nginx
spec:
containers:
- name: proxy
image: nginx
ports:
- containerPort: 80
volumeMounts:
- mountPath: /etc/nginx/conf.d
name: nginx-config
volumes:
- name: nginx-config
configMap:
name: nginx-config
当像这样启动 pod 时:
kubectl create -f nginx-pod.yaml
我的 pod 已创建,但他的状态在CrashLoopBackOff
2-3 秒后,但如果我删除此行:
volumeMounts:
- mountPath: /etc/nginx/conf.d
name: nginx-config
volumes:
- name: nginx-config
configMap:
name: nginx-config
我没有问题。
我最近遇到的问题似乎是site.conf。当 nginx 加载她的 conf 您的 nginx 崩溃结束您的 pod 崩溃时,您的 pod 会正确加载您的配置映射。检查您的 site.conf 结束添加默认值,如下所示
server {
listen 80;
listen [::]:80;
root /var/www/html/quickstart/public;
index index.php index.html index.htm index.nginx-debian.html;
server_name example.com www.example.com;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句