kubernetes(五)--存储之configmap/secret/volume/Persistent Volume

一、configmap

1.1、configmap简介

ConfigMap 功能在 Kubernetes1.2 版本中引入,许多应用程序会从配置文件、命令行参数或环境变量中读取配置信息。ConfigMap API 给我们提供了向容器中注入配置信息的机制,ConfigMap 可以被用来保存单个属性,也可以用来保存整个配置文件或者 JSON 二进制对象

1.2、ConfigMap 的创建

1.2.1、使用目录创建

[[email protected] dir]# ls
game.propertie  ui.propertie
[[email protected] dir]# cat game.propertie
enemies=aliens
lives=3
enemies.cheat=true
enemies.cheat.level=noGoodRotten
secret.code.passphrase=UUDDLRLRBABAS
secret.code.allowed=true
secret.code.lives=30
[[email protected] dir]# cat ui.propertie
color.good=purple
color.bad=yellow
allow.textmode=true
how.nice.to.look=fairlyNice

#从目录创建configmap
#—from-file指定在目录下的所有文件都会被用在 ConfigMap 里面创建一个键值对,键的名字就是文件名,值就是文件的内容
[[email protected] dir]# kubectl create configmap game-config --from-file=./
configmap/game-config created
[[email protected] dir]# kubectl get configmap
NAME          DATA   AGE
game-config   2      14s
[[email protected] dir]# kubectl get cm
NAME          DATA   AGE
game-config   2      18s
[[email protected] dir]# kubectl get cm game-config -o yaml
apiVersion: v1
data:
  game.propertie: |
    enemies=aliens
    lives=3
    enemies.cheat=true
    enemies.cheat.level=noGoodRotten
    secret.code.passphrase=UUDDLRLRBABAS
    secret.code.allowed=true
    secret.code.lives=30
  ui.propertie: |
    color.good=purple
    color.bad=yellow
    allow.textmode=true
    how.nice.to.look=fairlyNice
kind: ConfigMap
metadata:
  creationTimestamp: "2020-02-04T05:13:30Z"
  name: game-config
  namespace: default
  resourceVersion: "144337"
  selfLink: /api/v1/namespaces/default/configmaps/game-config
  uid: 0fc2df14-d5ee-4092-ba9e-cc733e8d5893
[[email protected]r01 dir]# kubectl describe cm game-config
Name:         game-config
Namespace:    default
Labels:       <none>
Annotations:  <none>

Data
====
game.propertie:
----
enemies=aliens
lives=3
enemies.cheat=true
enemies.cheat.level=noGoodRotten
secret.code.passphrase=UUDDLRLRBABAS
secret.code.allowed=true
secret.code.lives=30

ui.propertie:
----
color.good=purple
color.bad=yellow
allow.textmode=true
how.nice.to.look=fairlyNice

Events:  <none>

1.2.2、使用文件创建

只要指定为一个文件就可以从单个文件中创建 ConfigMap

—from-file这个参数可以使用多次,你可以使用两次分别指定上个实例中的那两个配置文件,效果就跟指定整个目录是一样的

[[email protected] dir]# kubectl create configmap game-config-2 --from-file=./game.propertie
configmap/game-config-2 created
[[email protected] dir]# kubectl get cm game-config-2
NAME            DATA   AGE
game-config-2   1      16s
[[email protected] dir]# kubectl get cm game-config-2 -o yaml
apiVersion: v1
data:
  game.propertie: |
    enemies=aliens
    lives=3
    enemies.cheat=true
    enemies.cheat.level=noGoodRotten
    secret.code.passphrase=UUDDLRLRBABAS
    secret.code.allowed=true
    secret.code.lives=30
kind: ConfigMap
metadata:
  creationTimestamp: "2020-02-04T05:25:13Z"
  name: game-config-2
  namespace: default
  resourceVersion: "145449"
  selfLink: /api/v1/namespaces/default/configmaps/game-config-2
  uid: df209574-202d-4564-95ca-19532abd6b7b

1.2.3、使用字面值创建

使用文字值创建,利用—from-literal参数传递配置信息,该参数可以使用多次

[[email protected] dir]# kubectl create configmap special-config --from-literal=special.how=very --from-literal=special.type=charm
configmap/special-config created
[[email protected] dir]# kubectl get cm special-config -o yaml
apiVersion: v1
data:
  special.how: very
  special.type: charm
kind: ConfigMap
metadata:
  creationTimestamp: "2020-02-04T05:27:43Z"
  name: special-config
  namespace: default
  resourceVersion: "145688"
  selfLink: /api/v1/namespaces/default/configmaps/special-config
  uid: 72b58e0e-f055-43dd-aa04-a7b2e9007227

原文地址:https://www.cnblogs.com/hujinzhong/p/12258966.html

时间: 2024-07-31 07:46:09

kubernetes(五)--存储之configmap/secret/volume/Persistent Volume的相关文章

Kubernetes的存储之Volume

在虚拟化的一系列解决方案中,数据的持久化都是需要我们非常关心的问题,dokcer是这样,Kubernetes也是这样.不过在Kubernetes中,有一个数据卷的概念. 一.Volume简介 我们经常都会说:容器.Pod都是很短暂的!其含义就是容器和Pod的生命周期都是很短暂的,会被频繁地销毁和创建.容器销毁时,保存在容器内部文件系统中的数据都会被清除. Volume的生命周期独立于容器,Pod中的容器可能被销毁和重启,但Volume会被保留. Kubernetes Volume主要解决了以下两

kubernetes中的local persistent volume

什么是Local Persistent Volumes 在kubernetes 1.14版本中, Local Persistent Volumes已变为正式版本(GA),Local PV的概念在1.7中被首次提出(alpha),并在1.10版本中升级到beat版本.现在用户终于可以在生产环境中使用Local PV的功能和API了.首先:Local Persistent Volumes代表了直接绑定在计算节点上的一块本地磁盘.kubernetes提供了一套卷插件(volume plugin)标准,

Kubernetes之存储卷

存储卷概述 容器磁盘上的文件的生命周期是短暂的,这就使得在容器中运行重要应用时会出现一些问题.首先,当容器崩溃时,kubelet 会重启它,但是容器中的文件将丢失--容器以干净的状态(镜像最初的状态)重新启动.其次,在 Pod 中同时运行多个容器时,这些容器之间通常需要共享文件.Kubernetes 中的 Volume 抽象就很好的解决了这些问题.在原docker环境中也有存储卷的概念,但docker环境的存储卷调度在宿主机上的目录,当docker重新创建的时候存储卷还会挂载统一宿主机上,但我们

20.Kubernetes共享存储

Kubermetes对于有状态的容器应用或者对数据需要持久化的应用,不仅需要将容器内的目录挂载到宿主机的目录或者emptyDir临时存储卷,而且需要更加可靠的存储来保存应用产生的重要数据,以便容器应用在重建之后,仍然可以使用之前的数据.不过,存储资源和计算资源(CPU/内存)的管理方式完全不同.为了能够屏蔽底层存储实现的细节,让用户方便使用,同时能让管理员方便管理, Kubernetes从v1.0版本就引入PersistentVolume和PersistentVolumeClaim两个资源对象来

kubernetes pv pvc configmap secret 使用

pv pvc使用 1.概述,我们可以这样来组织我们的存储,在pod中我们只需要定义一个存储卷并且定义的时候我只需要说明我需要多大的存储卷就行了,这个存储卷叫pvc类型的存储卷,而pvc类型的存储卷必须与当前名称空间中的pvc建立直接绑定关系,而pvc必须与pv建立绑定关系,而pv应该是真正某个存储设备上的存储空间,所以pv和pvc是k8s系统之上的抽象的但也算是标准的资源,pvc是一种资源,pv也是一种资源,他的创建方式和我们此前创建其它资源方式是一样的,但是用户需要怎么做呢?存储工程师把每个存

kubernetes持久化存储,静态存储【pv】,动态存储【StorageClass】(5)

在开始介绍k8s持久化存储前,我们有必要了解一下k8s的emptydir和hostpath.configmap以及secret的机制和用途 1.EmptydirEmptyDir是一个空目录,他的生命周期和所属的 Pod 是完全一致的,pod删掉目录消失 2.HostpathHostpath会把宿主机上的指定卷加载到容器之中,如果 Pod 发生跨主机的重建,其内容就难保证了 3.ConfigmapConfigMap跟Secrets类似,但是ConfigMap可以更方便的处理不包含敏感信息的字符串.

Kubernetes中,两种常见类型的Volume深度实践

一.背景 存储资源在所有计算资源中扮演着十分重要的角色,大部分业务场景下都有可能使用到各类存储资源.在Kubernetes中,系统通过Volume对集群中的容器动态或静态提供存储资源.通常情况下,我们可以认为容器或者Pod的生命周期时短暂的,当容器被销毁时,容器内部的数据也同时被清除.为了持久化保存容器的数据,Kubernetes引入了Volume,类似于Docker的Volume(Docker also has a concept of volumes, though it is somewh

kubernetes的Service Account和secret

系列目录 Service Account Service Account概念的引入是基于这样的使用场景:运行在pod里的进程需要调用Kubernetes API以及非Kubernetes API的其它服务.Service Account它并不是给kubernetes集群的用户使用的,而是给pod里面的进程使用的,它为pod提供必要的身份认证. kubectl get sa --all-namespaces NAMESPACE NAME SECRETS AGE default build-robo

Kubernetes 持久化存储之GlusterFS

GlusterFS是一个开源的分布式文件,具有强大的横向扩展能力,可支持数PB存储容量和数千客户端,通过网络互连成一个并行的网络文件系统.具有扩展性.高性能.高可用性等特点. 前提:必须要在实验环境中部署了Gluster FS集群,文中创建了名为:gv0的存储卷 1.创建endpoint,文件名为glusterfs_ep.yaml $ vi glusterfs_ep.yaml apiVersion: v1 kind: Endpoints metadata: name: glusterfs nam