需求,
3个容器访问的数据是一样的, (数据共享 nfs)
修改一个配置后, 不需要每一个都修改, (configMap 配置文件共享)
cat 20-pods-volumes-nfs-cm.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: nginx.conf
data:
nginx.conf: |
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
keepalive_timeout 65;
include /etc/nginx/conf.d/*.conf;
}
---
apiVersion: v1
kind: Pod
metadata:
name: dashu-volumes-nfs-cm-004
spec:
volumes:
- name: data
nfs:
server: master231
path: /baimei/data/kubernetes
- name: etc
configMap:
name: nginx.conf
items:
- key: nginx.conf
path: nginx.conf
containers:
- name: web
image: harbor.baimei.com/baimei-web/nginx:1.25.1-alpine
volumeMounts:
- name: data
mountPath: /usr/share/nginx/html
- name: etc
mountPath: /etc/nginx/nginx.conf
subPath: nginx.conf
---
apiVersion: v1
kind: Pod
metadata:
name: dashu-volumes-nfs-cm-005
spec:
volumes:
- name: data
nfs:
server: master231
path: /baimei/data/kubernetes
- name: etc
configMap:
name: nginx.conf
items:
- key: nginx.conf
path: nginx.conf
containers:
- name: web
image: harbor.baimei.com/baimei-web/nginx:1.25.1-alpine
volumeMounts:
- name: data
mountPath: /usr/share/nginx/html
- name: etc
mountPath: /etc/nginx/nginx.conf
subPath: nginx.conf
---
apiVersion: v1
kind: Pod
metadata:
name: dashu-volumes-nfs-cm-006
spec:
volumes:
- name: data
nfs:
server: master231
path: /baimei/data/kubernetes
- name: etc
configMap:
name: nginx.conf
items:
- key: nginx.conf
path: nginx.conf
containers:
- name: web
image: harbor.baimei.com/baimei-web/nginx:1.25.1-alpine
volumeMounts:
- name: data
mountPath: /usr/share/nginx/html
- name: etc
mountPath: /etc/nginx/nginx.conf
subPath: nginx.conf
这种比较麻烦的 , 接下来看看 rc资源实现控制器 : 连接
欢迎来撩 : 汇总all