首先,附上最终版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: /usr/share/nginx/html/
name: data
- mountPath: /etc/nginx/
name: nginxconf
volumes:
- name: data
hostPath:
path: /opt/nginxdata/
type: Directory
- name: nginxconf
hostPath:
path: /opt/nginxconf/
type: Directory
---
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
注意点:
- type: Directory这个好像是必填的,之前做的实验都失败了,不确定是不是因为这个
- 这里的hostPath要提前到节点上去创建,否则是不会创建的
- 这里要写成数组的形式,不确定是不是因为这个
- nginx配置文件location字段中,要加autoindex on;否则会默认找index.html 找不到就403了
- mountPath: /usr/share/nginx/html/
name: data
- mountPath: /etc/nginx/
name: nginxconf
volumes:
- name: data
hostPath:
path: /opt/nginxdata/
type: Directory
- name: nginxconf
hostPath:
path: /opt/nginxconf/
type: Directory
验证
到了愉快的验证环节 不容易啊,describe一下看看 这里也是没问题的~
实现目标
- 实现共享存储,即本地与容器共享存储,后续可本地修改配置文件,?持久化存储,NONO,持久化存储还是上pvc,pv吧,后续会学习这一方面
- 关机睡觉~
|