本次使用configmap配置文件的方式部署nginx
步骤:
一、编写configmap
二、编写service
三、编写deployment
以下是详细操作步骤
一、编写configmap
apiVersion: v1
kind: ConfigMap
metadata:
name: nginx-configmap
namespace: dev
data:
default.conf: |
server {
listen 80;
listen [::]:80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
二、编写service
---
apiVersion: v1
kind: Service
metadata:
labels:
app: nginx-svc
name: nginx-svc
namespace: dev
spec:
ports:
- nodePort: 30012
port: 80
protocol: TCP
targetPort: 80
selector:
app: nginx-pod
type: NodePort
三、编写deployment
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: nginx-deploy
name: nginx-deploy
namespace: dev
spec:
replicas: 3
selector:
matchLabels:
app: nginx-pod
strategy: {}
template:
metadata:
labels:
app: nginx-pod
namespace: dev
spec:
containers:
- image: nginx:1.22.0
name: nginx
ports:
- containerPort: 80
resources: {}
volumeMounts:
- name: nginx-config
mountPath: "/etc/nginx/conf.d/"
readOnly: true
volumes:
- name: nginx-config
configMap:
name: nginx-configmap
访问成功