我在家庭实验室中设置了Kubernetes,并能够从部署中运行vanilla实现的nginx。
下一步是为nginx的配置使用自定义nginx.conf文件。为此,我正在使用ConfigMap。
当我这样做时,当我导航到http://192.168.1.10:30008(nginx服务器正在其上运行的节点的本地IP地址)时,不再收到nginx索引页面。如果我尝试使用ConfigMap,则会收到nginx 404页面/消息。
我无法看到我在这里做错了什么。任何方向都将不胜感激。
下一步是为nginx的配置使用自定义nginx.conf文件。为此,我正在使用ConfigMap。
当我这样做时,当我导航到http://192.168.1.10:30008(nginx服务器正在其上运行的节点的本地IP地址)时,不再收到nginx索引页面。如果我尝试使用ConfigMap,则会收到nginx 404页面/消息。
我无法看到我在这里做错了什么。任何方向都将不胜感激。
nginx-deploy.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: nginx-conf
data:
nginx.conf: |
user nginx;
worker_processes 1;
events {
worker_connections 10240;
}
http {
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
}
}
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
spec:
selector:
matchLabels:
app: nginx
replicas: 1
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
volumeMounts:
- name: nginx-conf
mountPath: /etc/nginx/nginx.conf
subPath: nginx.conf
readOnly: true
volumes:
- name: nginx-conf
configMap:
name: nginx-conf
items:
- key: nginx.conf
path: nginx.conf
---
apiVersion: v1
kind: Service
metadata:
name: nginx
spec:
type: NodePort
ports:
- port: 80
protocol: TCP
targetPort: 80
nodePort: 30008
selector:
app: nginx