当前位置:网站首页>kubernetes资源对象介绍及常用命令(五)-(ConfigMap&Secret)
kubernetes资源对象介绍及常用命令(五)-(ConfigMap&Secret)
2022-07-05 20:06:00 【傻啦猫@[email protected]】
一、ConfitMap
配置集,抽取应用配置。
ConfigMap保存在kubernetes的etcd中。
ConfigMap可以将文件直接挂载到Pod内,区别于上篇文章中的PV&PVC挂载目录。
创建ConfigMap
命令行方式
[[email protected] ~]# vi redis.conf
[[email protected] ~]# cat redis.conf
appendonly yes
[[email protected] ~]# kubectl create cm redis-conf --from-file=redis.conf
configmap/redis.conf created
[[email protected] ~]#
首先有redis.conf文件,然后将文件做成ConfigMap。
yaml方式,redis-conf.yml
apiVersion: v1
data:
redis.conf: |
appendonly yes
kind: ConfigMap
metadata:
name: redis-conf
namespace: default
data是所有真正的数据,key:默认是文件名,value:配置文件的内容
[[email protected] ~]# kubectl apply -f redis-conf.yml
configmap/redis-conf created
[[email protected] ~]#
查看ConfigMap
[[email protected] ~]# kubectl get cm
NAME DATA AGE
kube-root-ca.crt 1 2d1h
redis-conf 1 53s
[[email protected] ~]#
扩展: 查看redis-conf的yaml文件
kubectl get cm redis-conf -oyaml
创建pod
redis.yml
apiVersion: v1
kind: Pod
metadata:
name: redis
spec:
containers:
- name: redis
image: redis
command:
- redis-server
- "/redis-master/redis.conf" #指的是redis容器内部的位置
ports:
- containerPort: 6379
volumeMounts:
- mountPath: /data
name: data
- mountPath: /redis-master
name: config
volumes:
- name: data
emptyDir: {}
- name: config
configMap:
name: redis-conf
items:
- key: redis.conf
path: redis.conf
说明:一个ConfigMap文件可能有多个配置,items会遍历每个配置,key中定义这里要取哪个配置,path表示将取出来的配置文件内容放到容器内的哪个文件中。
关系图参考如下:

[[email protected] ~]# kubectl apply -f redis.yml
pod/redis created
[[email protected] ~]#
# 进入到容器内部验证
[[email protected] ~]# kubectl exec -it redis -c redis -- /bin/bash
[email protected]:/data# cd /redis-master/
[email protected]:/redis-master# ls
redis.conf
[email protected]:/redis-master# cat redis.conf
appendonly yes
[email protected]:/redis-master#
修改ConfigMap
[[email protected] ~]# kubectl edit cm redis-conf
configmap/redis-conf edited
[[email protected] ~]#
添加了一行配置requirepass 123456。
[[email protected] ~]# kubectl exec -it redis -c redis -- /bin/bash
[email protected]:/data# cd /redis-master/
[email protected]:/redis-master# ls
redis.conf
[email protected]:/redis-master# cat redis.conf
appendonly yes
requirepass 123456
[email protected]:/redis-master#
ConfigMap被自动更新了。
重点说明:这里的自动更新只是容器内部的文件跟随ConfigMap的改变而改变,但是并不一定真正生效,主要看应用有没有热部署能力,没有热部署能力的应用需要重启才能生效。
删除ConfigMap
kubectl delete cm redis-conf
二、Secret
Secret保存在kubernetes的etcd中。
Secret对象类型用来保存敏感信息,例如密码、OAuth令牌和SSH密钥。将这些信息放在secret中比放在Pod的定义或者容器镜像中来说更加安全和灵活。
创建Secret
# 命令格式
kubectl create secret docker-registry jiangnan \
--docker-server=<你的镜像仓库服务器> \
--docker-username=<你的用户名> \
--docker-password=<你的密码> \
--docker-email=<你的邮箱地址>
查看Secret
[[email protected] ~]# kubectl get secret
NAME TYPE DATA AGE
default-token-ssmvn kubernetes.io/service-account-token 3 2d2h
jiangnan kubernetes.io/dockerconfigjson 1 2m6s
[[email protected] ~]#
删除Secret
[[email protected] ~]# kubectl delete secret jiangnan
secret "jiangnan" deleted
[[email protected] ~]#
本文由 mdnice 多平台发布
版权声明
本文为[傻啦猫@[email protected]]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_45842494/article/details/125610143
边栏推荐
- Go language | 01 wsl+vscode environment construction pit avoidance Guide
- Is it safe for CICC fortune to open an account online?
- Multi branch structure
- 什么是pyc文件
- Is the education of caiqiantang reliable and safe?
- 图嵌入Graph embedding学习笔记
- 关于BRAM IP复位的优先级
- Process file and directory names
- Database logic processing function
- Fundamentals of deep learning convolutional neural network (CNN)
猜你喜欢

图嵌入Graph embedding学习笔记

Force buckle 729 My schedule I
![[OBS] qstring's UTF-8 Chinese conversion to blog printing UTF-8 char*](/img/cc/172684664a9115943d45b0646ef110.png)
[OBS] qstring's UTF-8 Chinese conversion to blog printing UTF-8 char*

浅浅的谈一下ThreadLocalInsecureRandom

Win10 x64环境下基于VS2017和cmake-gui配置使用zxing以及opencv,并实现data metrix码的简单检测

Using repositoryprovider to simplify the value passing of parent-child components
![[hard core dry goods] which company is better in data analysis? Choose pandas or SQL](/img/70/a79c4a1724c11e208814de2d9cf553.png)
[hard core dry goods] which company is better in data analysis? Choose pandas or SQL

Leetcode brush question: binary tree 13 (the same tree)

Leetcode brush question: binary tree 14 (sum of left leaves)

淺淺的談一下ThreadLocalInsecureRandom
随机推荐
Process file and directory names
解决Thinkphp框架应用目录下数据库配置信息修改后依然按默认方式连接
Redis cluster simulated message queue
Is it safe for Galaxy Securities to open an account online?
Ffplay document [easy to understand]
js方法传Long类型id值时会出现精确损失
[hard core dry goods] which company is better in data analysis? Choose pandas or SQL
- Oui. Net Distributed Transaction and Landing Solution
浅浅的谈一下ThreadLocalInsecureRandom
BZOJ 3747 POI2015 Kinoman 段树
Leetcode skimming: binary tree 16 (path sum)
leetcode刷题:二叉树11(平衡二叉树)
The difference between ID selector and class selector
【obs】libobs-winrt :CreateDispatcherQueueController
Is it safe for CICC fortune to open an account online?
[C language] merge sort
Based on vs2017 and cmake GUI configuration, zxing and opencv are used in win10 x64 environment, and simple detection of data matrix code is realized
leetcode刷题:二叉树17(从中序与后序遍历序列构造二叉树)
leetcode刷题:二叉树14(左叶子之和)
Win10 x64环境下基于VS2017和cmake-gui配置使用zxing以及opencv,并实现data metrix码的简单检测