CKA考试知识点分享(12)---configmap
CKA 版本:1.32
第十二套题是涉及configmap相关。
实验操作:通过configmap 给nginx deployment外挂配置,实现修改configmap后,配置动态更新。
注意:本文不是题目,只是为了学习相关知识点做的实验。仅供参考
实验开始
创建nginx的deployment
apiVersion: apps/v1
kind: Deployment
metadata:name: nginx
spec:selector:matchLabels:run: nginxtemplate:metadata:labels:run: nginxspec:containers:- name: nginximage: docker.m.daocloud.io/library/nginx:stable-alpineports:- containerPort: 80---
apiVersion: v1
kind: Service
metadata:name: nginxlabels:run: nginx
spec:ports:- port: 80selector:run: nginx
访问pod 查看nginx版本:
创建nginx的配置文件
vim nginx.conf
user nginx;
worker_processes auto;error_log /var/log/nginx/error.log notice;
pid /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;#tcp_nopush on;keepalive_timeout 65;#gzip on;server_tokens off;include /etc/nginx/conf.d/*.conf;
}
创建configmap
kubectl create configmap nginx.conf --from-file=nginx.conf
查看configmap
针对deployment 进行修改使用这个configmap
volumeMounts:- name: config-volumemountPath: /etc/nginx/nginx.confsubPath: nginx.conf # 以子文件nginx.conf挂载到/etc/nginx/ 目录,不加的话当前目录下只有nginx.conf这一个文件volumes:- name: config-volumeconfigMap:name: nginx.conf
应用后,pod重启,再次查看版本
发现nginx的版本隐藏,配置文件生效。
注意:使用subpath 当configmap变动时,不会自动更新。 所以需要重启pod才能实现配置文件更新。