Kubernetes configmap 崩溃吊舱
Kubernetes configmap crash pod
我使用命令行 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
中,我有正常的 pod 设置:
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
我没有问题。
有其他事情让您感到困惑。我只是从字面上复制了你的 conf 和 yaml 文件(除了 运行 它带有 -n test-namespace 用于分隔)并且它工作完美。
运行 好的,跳转到 pod,并且 site.conf 很高兴按预期安装在 /etc/nginx/conf.d 文件夹中。我使用的 Baremetal k8s 版本是 1.9.2 并且配置明智这是正确的。
编辑:刚刚也在 Mac 上用 minikube 试过了(客户端 1.9.3 服务器 1.9.0),它也能正常工作(甚至没有命名空间,正是你描述的步骤)。
您能看到 scheduler/api 或 pod 处于失败状态的日志吗?也许它可以更清楚地说明阻止它启动的原因?您没有 RBAC 配置错误或跨命名空间的某些东西会阻止配置映射被读取?
我最近似乎遇到了问题,问题是 site.conf。当 nginx 加载她的 conf 你的 pod 加载你的 configmap 时你的 nginx 崩溃结束你的 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;
}
}
我使用命令行 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
中,我有正常的 pod 设置:
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
我没有问题。
有其他事情让您感到困惑。我只是从字面上复制了你的 conf 和 yaml 文件(除了 运行 它带有 -n test-namespace 用于分隔)并且它工作完美。
运行 好的,跳转到 pod,并且 site.conf 很高兴按预期安装在 /etc/nginx/conf.d 文件夹中。我使用的 Baremetal k8s 版本是 1.9.2 并且配置明智这是正确的。
编辑:刚刚也在 Mac 上用 minikube 试过了(客户端 1.9.3 服务器 1.9.0),它也能正常工作(甚至没有命名空间,正是你描述的步骤)。
您能看到 scheduler/api 或 pod 处于失败状态的日志吗?也许它可以更清楚地说明阻止它启动的原因?您没有 RBAC 配置错误或跨命名空间的某些东西会阻止配置映射被读取?
我最近似乎遇到了问题,问题是 site.conf。当 nginx 加载她的 conf 你的 pod 加载你的 configmap 时你的 nginx 崩溃结束你的 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;
}
}