I have Kubernetes set up in a home lab and I am able to get a vanilla implementation of nginx running from a deployment.
The next step is to have a custom nginx.conf file for the configuration of nginx. For this, I am using a ConfigMap.
When I do this, I no longer receive the nginx index page when I navigate to http://192.168.1.10:30008 (my local ip address for the node the nginx server is running on). If I try to use the ConfigMap, I receive the nginx 404 page/message.
I am not able to see what I am doing incorrectly here. Any direction would be much appreciated.
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