一、单文件挂载到空目录
实例演示要求:
- 基于nginx.conf配置文件创建一个ConfigMap配置
- 把该ConfigMap配置,挂载到/etc/application目录
1、nginx.conf配置文件如下:
[root@k8s-master cm]# cat nginx.conf
user nginx;
worker_processes 4; #修改了这个位置
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 2048; #修改了这个位置
}
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;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
2、基于该nginx.conf文件创建的ConfigMap
[root@k8s-master cm]# kubectl create cm nginx-conf --from-file=nginx.conf
configmap/nginx-conf created
3、创建相应的deployment,并挂载该ConfigMap
apiVersion: apps/v1
kind: Deployment
metadata:
name: demo
namespace: default
spec:
selector:
matchLabels:
app: demo
template:
metadata:
labels:
app: demo
spec:
volumes:
- configMap:
name: nginx-conf #指定使用ConfigMap的名称
name: config #volumes的名称
containers:
- name: nginx
image: nginx:alpine
imagePullPolicy: IfNotPresent
volumeMounts:
- mountPath: "/etc/application" #容器挂载的目录(空的)
name: config #指定上面的volumes名称
4、我们尝试将ConfigMap为nginx-conf配置挂载到/etc/profile.d/非空目录的情况
修改挂载路径
重新创建并验证结果