关于k8s配置nginx并创建本地目录
首先分享一下yaml文件
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
namespace: default
labels:
app: nginx-test
spec:
selector:
matchLabels:
app: nginx-test
replicas: 3
template:
metadata:
name: nginx-test
labels:
app: nginx-test
spec:
containers:
- name: nginx-container
image: nginx
imagePullPolicy: IfNotPresent
ports:
- containerPort: 80
volumeMounts:
- mountPath: /etc/nginx/conf.d/default.conf
name: nginx-conf
subPath: default.conf
volumeMounts:
- mountPath: /usr/share/nginx/html/
name: data
volumes:
- name: nginx-conf
configMap:
name: nginx-configmap
volumes:
- name: data
hostPath:
path: /opt/data
---
apiVersion: v1
kind: Service
spec:
ports:
- nodePort: 30030
port: 8080
targetPort: 80
type: NodePort
selector:
app: nginx-test
metadata:
namespace: default
labels:
app: nginx-test
name: nginx-service
---
apiVersion: v1
data:
default.conf: |-
server {
listen 80;
server_name localhost;
location / {
root /files;
autoindex on;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
kind: ConfigMap
metadata:
name: nginx-configmap
这里通过hostoath的方式映射两个目录
usr/share/nginx/html ----/opt/data /etc/nginx/ ----opt/conf 注意点: 在node节点需要往映射目录创建index.html
疑问: 只创建data目录 cm未生效
明天处理
|