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

2021-04-20 10:28

阅读:586

标签:quick   special   ===   resource   --   ras   yellow   内容   config   

一、configmap

1.1、configmap简介

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

1.2、ConfigMap 的创建

1.2.1、使用目录创建

[root@k8s-master01 dir]# ls
game.propertie  ui.propertie
[root@k8s-master01 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
[root@k8s-master01 dir]# cat ui.propertie 
color.good=purple
color.bad=yellow
allow.textmode=true
how.nice.to.look=fairlyNice

#从目录创建configmap
#—from-file指定在目录下的所有文件都会被用在 ConfigMap 里面创建一个键值对,键的名字就是文件名,值就是文件的内容
[root@k8s-master01 dir]# kubectl create configmap game-config --from-file=./
configmap/game-config created
[root@k8s-master01 dir]# kubectl get configmap
NAME          DATA   AGE
game-config   2      14s
[root@k8s-master01 dir]# kubectl get cm
NAME          DATA   AGE
game-config   2      18s
[root@k8s-master01 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
[root@k8s-master01 dir]# kubectl describe cm game-config
Name:         game-config
Namespace:    default
Labels:       
Annotations:  

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:  

1.2.2、使用文件创建

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

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

[root@k8s-master01 dir]# kubectl create configmap game-config-2 --from-file=./game.propertie
configmap/game-config-2 created
[root@k8s-master01 dir]# kubectl get cm game-config-2
NAME            DATA   AGE
game-config-2   1      16s
[root@k8s-master01 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参数传递配置信息,该参数可以使用多次

[root@k8s-master01 dir]# kubectl create configmap special-config --from-literal=special.how=very --from-literal=special.type=charm
configmap/special-config created
[root@k8s-master01 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

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

标签:quick   special   ===   resource   --   ras   yellow   内容   config   

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


评论


亲,登录后才可以留言!