K8S中数据存储之配置存储

server/2025/2/4 11:12:28/

配置存储

  • 在Kubernetes中,ConfigMapSecret是两种核心资源,用于存储和管理应用程序的配置数据和敏感信息。理解它们的功能和最佳实践对于提高Kubernetes应用程序的安全性和配置管理的效率至关重要。

 ConfigMap

  • ConfigMap是一种API对象,允许你存储非敏感配置数据,如环境变量、数据库URL等。它以键值对的形式存储数据,便于应用程序访问必要的配置。ConfigMap可以直接挂载到容器中或作为环境变量注入到容器中,从而使得应用程序能够访问存储的配置数据,而无需修改应用程序代码。

[root@k8s-master ~]#  vim configmap.yaml
[root@k8s-master ~]# kubectl apply -f configmap.yaml 
configmap/configmap created
[root@k8s-master ~]#  kubectl get configmaps configmap -n test
NAME        DATA   AGE
configmap   1      8s
[root@k8s-master ~]# vim pod-configmap.yaml
[root@k8s-master ~]# kubectl apply -f pod-configmap.yaml 
pod/pod-configmap created
[root@k8s-master ~]# kubectl get pod -n test -o wide
NAME            READY   STATUS              RESTARTS   AGE   IP               NODE        NOMINATED NODE   READINESS GATES
pod-configmap   0/1     ContainerCreating   0          6s    <none>           k8s-node1   <none>           <none>
pod1            1/1     Running             0          22m   10.244.169.129   k8s-node2   <none>           <none>
pod2            1/1     Running             0          22m   10.244.36.74     k8s-node1   <none>           <none>
[root@k8s-master ~]# kubectl get pod -n test -w
NAME            READY   STATUS              RESTARTS   AGE
pod-configmap   0/1     ContainerCreating   0          11s
pod1            1/1     Running             0          22m
pod2            1/1     Running             0          22m
^C[root@k8s-master ~]# kubectl get pod -n test -w
NAME            READY   STATUS              RESTARTS   AGE
pod-configmap   0/1     ContainerCreating   0          14s
pod1            1/1     Running             0          23m
pod2            1/1     Running             0          23m
pod-configmap   1/1     Running             0          25s
^C[root@k8s-master ~]# kubectl exec -it pod-configmap -n test /bin/bash
kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl exec [POD] -- [COMMAND] instead.
root@pod-configmap:/# 
root@pod-configmap:/# 
root@pod-configmap:/# cd /configmap/config/
root@pod-configmap:/configmap/config# ll
bash: ll: command not found
root@pod-configmap:/configmap/config# ls
msg
root@pod-configmap:/configmap/config# cat msg 
username: root
address: meiguo
root@pod-configmap:/configmap/config# ex  
bash: ex: command not found
root@pod-configmap:/configmap/config# 
root@pod-configmap:/configmap/config# 
root@pod-configmap:/configmap/config# 
root@pod-configmap:/configmap/config# exit
exit
command terminated with exit code 127
[root@k8s-master ~]# cat pod-configmap.yaml 
---
apiVersion: v1
kind: Pod
metadata:name: pod-configmapnamespace: test
spec:containers:- name: nginximage: nginx:1.17.1volumeMounts:- name: configmountPath: /configmap/configvolumes:- name: configconfigMap:name: configmap

Secret

  • 在 Kubernetes 中,Secret 对象确实是用来存储敏感信息的一种资源例如密码、秘钥、证书等等。它与 ConfigMap 类似,但设计目的不同。

 

  • Opaque

    • 这种类型的 Secret 用于存储少量的敏感数据,如密码、令牌或密钥。

    • 数据以 Base64 编码格式存储,这意味着虽然数据在存储时被编码,但仍然可以通过 Base64 解码来查看原始数据,因此安全性相对较低。

[root@k8s-master ~]# echo -n "root"  | base64
cm9vdA==
[root@k8s-master ~]# echo -n "123456"  | base64
MTIzNDU2
[root@k8s-master ~]#  vim secret.yaml
[root@k8s-master ~]# kubectl apply -f secret.yaml 
secret/mysecret created
[root@k8s-master ~]# kubetcl describe secret mysecret 
-bash: kubetcl: command not found
[root@k8s-master ~]# kubectl describe secret mysecret 
Name:         mysecret
Namespace:    default
Labels:       <none>
Annotations:  <none>Type:  OpaqueData
====
pass:  6 bytes
user:  4 bytes
[root@k8s-master ~]# kubectl get secret | grep Opaque
mysecret              Opaque                                2      40s
[root@k8s-master ~]# cat secret.yaml 
apiVersion: v1
kind: Secret
metadata:name: mysecret
type: Opaque
data:user: cm9vdA==  # base64编码的"root"pass: MTIzNDU2  # base64编码的"123456"

 


http://www.ppmy.cn/server/164870.html

相关文章

【Numpy核心编程攻略:Python数据处理、分析详解与科学计算】1.27 线性代数王国:矩阵分解实战指南

1.27 线性代数王国&#xff1a;矩阵分解实战指南 #mermaid-svg-JWrp2JAP9qkdS2A7 {font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-svg-JWrp2JAP9qkdS2A7 .error-icon{fill:#552222;}#mermaid-svg-JWrp2JAP9qkdS2A7 .erro…

Java开发vscode环境搭建

1 几个名词 JDK Java Development Kit JRE Java Runtion Environment JVM JDK 包括 Compiler,debugger,JRE等。JRE包括JVM和Runtime Library。 2 配置环境 2.1 安装JDK 类比 C/C的 g工具 官网&#xff1a;https://www.oracle.com/java/technologies/downloads/ 根据自己使…

ARM内核:嵌入式时代的核心引擎

引言 在当今智能设备无处不在的时代&#xff0c;ARM&#xff08;Advanced RISC Machines&#xff09;处理器凭借其高性能、低功耗的特性&#xff0c;成为智能手机、物联网设备、汽车电子等领域的核心引擎。作为精简指令集&#xff08;RISC&#xff09;的典范&#xff0c;ARM核…

selenium记录Spiderbuf例题C02

防止自己遗忘&#xff0c;故作此为记录。 这套题牵扯到滑块。 步骤&#xff1a; &#xff08;1&#xff09;进入例题&#xff0c;需要找到滑块与滑条。 需要注意的是&#xff0c;只能通过css选择器来筛选。 WebDriverWait(driver, 15).until(expected_conditions.visibilit…

数据库和数据表的创建、修改、与删除

1.标识符命名规则 数据库名、表名不得超过30个字符&#xff0c;变量名限制为29个 必须只能包含A-Z,a-z,0-9,_共63个字符 数据库名、表名、字段名等对象名中间不能包含空格 同一个MySQL软件中&#xff0c;数据库不能同名&#xff1b;同一个库中&#xff0c;表不能重名&#…

一个开源 GenBI AI 本地代理(确保本地数据安全),使数据驱动型团队能够与其数据进行互动,生成文本到 SQL、图表、电子表格、报告和 BI

一、GenBI AI 代理介绍&#xff08;文末提供下载&#xff09; github地址&#xff1a;https://github.com/Canner/WrenAI 本文信息图片均来源于github作者主页 在 Wren AI&#xff0c;我们的使命是通过生成式商业智能 &#xff08;GenBI&#xff09; 使组织能够无缝访问数据&…

Unity游戏(Assault空对地打击)开发(4) 碰撞体和刚体的添加

前言 飞机和世界的大小关系不太对&#xff0c;我稍微缩小了一下飞机。 详细步骤 选中所有地形对象&#xff0c;如果没有圈起的部分&#xff0c;点击Add Component搜索添加。 接着选中Player对象&#xff0c;添加这两个组件&#xff0c;最好&#xff08;仅对于本项目开发&#x…

2025最新版MySQL安装使用指南

2025最新版MySQL安装使用指南 The Installation and Usage Guide of the Latest Version of Oracle MySQL in 2025 By JacksonML 1. 获取MySQL 打开Chrome浏览器&#xff0c;访问官网链接&#xff1a;https://www.mysql.com/ &#xff0c;随即打开MySQL官网主页面&#xff…