ConfigMaps允许您将配置工件与image内容分离,以保持容器化应用程序的便携性。 本页面提供了一系列使用示例,演示如何使用ConfigMaps中存储的数据创建ConfigMaps和配置Pod。

Create ConfigMaps from directories

[root@mhc config_dir]# ls
a.cnf  b.cnf

kubectl create configmap test-config --from-file=`pwd`

[root@mhc config_dir]# kubectl describe configmaps test-config
Name:         test-config
Namespace:    default
Labels:       <none>
Annotations:  <none>

Data
====
a.cnf:
----
haha
lala
balabala

b.cnf:
----
you are stupid!
heng heng

Events:  <none>
===================================

kubectl create configmap test-config2 --from-file=`pwd`/a.cnf

kubectl create configmap test-config3 --from-file=`pwd`/a.cnf --from-file=`pwd`/b.cnf

[root@mhc config_dir]# kubectl create configmap test-config4 --from-file=key1=`pwd`/a.cnf --from-file=key2=`pwd`/b.cnf
configmap "test-config4" created
[root@mhc config_dir]#
[root@mhc config_dir]#
[root@mhc config_dir]# kubectl describe configmap test-config4
Name:         test-config4
Namespace:    default
Labels:       <none>
Annotations:  <none>

Data
====
key1:
----
haha
lala
balabala

key2:
----
you are stupid!
heng heng

Events:  <none>
===================================

[root@mhc config_dir]# kubectl create configmap special-config --from-literal=special.how=very --from-literal=special.type=charm
configmap "special-config" created
[root@mhc config_dir]# kubectl get configmaps special-config -o yaml
apiVersion: v1
data:
  special.how: very
  special.type: charm
kind: ConfigMap
metadata:
  creationTimestamp: 2018-02-27T08:21:36Z
  name: special-config
  namespace: default
  resourceVersion: "61698"
  selfLink: /api/v1/namespaces/default/configmaps/special-config
  uid: 3a4a0483-1b97-11e8-a9e9-dcfe07d61067
========================================

kubectl create configmap consul-config --from-literal=datacenter=haha

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
labels:
io.kompose.service: consul2
name: consul
spec:
replicas: 1
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
io.kompose.service: consul2
name: consul2
spec:
containers:
- args:
- agent
- -server
- -client=0.0.0.0
- -ui
- -bootstrap
- -bind=0.0.0.0
image: consul:0.8.4
name: consul
ports:
- containerPort: 8500
- containerPort: 8300
- containerPort: 8301
- containerPort: 8302
- containerPort: 8400
resources:
limits:
memory: "134217728"
env:
- name: DATACENTER
valueFrom:
configMapKeyRef:
name: consul-config
key: datacenter
restartPolicy: Always
status: {} ====================================================
apiVersion: v1
kind: Pod
metadata:
name: dapi-test-pod
spec:
containers:
- name: test-container
image: k8s.gcr.io/busybox
command: [ "/bin/sh", "-c", "env" ]
envFrom:
- configMapRef:
name: special-config
restartPolicy: Never

=============================

Add ConfigMap data to a Volume

[root@mhc config_dir]# kubectl create configmap consul-config2 --from-file=`pwd`/my.cnf
configmap "consul-config2" created
[root@mhc config_dir]#
[root@mhc config_dir]# kubectl describe configmaps consul-config2
Name:         consul-config2
Namespace:    default
Labels:       <none>
Annotations:  <none>

Data
====
my.cnf:
----
[mysqld]
aa = bb
cc= ee

[client]
user = root
password = root.123

Events:  <none>

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
labels:
io.kompose.service: consul3
name: consul
spec:
replicas: 2
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
io.kompose.service: consul3
name: consul3
spec:
containers:
- args:
- agent
- -server
- -client=0.0.0.0
- -ui
- -bootstrap
- -bind=0.0.0.0
image: consul:0.8.4
name: consul
resources:
limits:
memory: "134217728"
volumeMounts:
- name: config-volume
mountPath: /etc/myconfig
volumes:
- name: config-volume
configMap:
name: consul-config2
restartPolicy: Always
status: {}

[root@mhc config_dir]# kubectl exec -ti consul-7b7bddfff6-9rmbw sh
/ # ls /etc/myconfig/
my.cnf
/ # cat /etc/myconfig/my.cnf
[mysqld]
aa = bb
cc= ee

[client]
user = root
password = root.123

===========================================================

volumes:
- name: config-volume
configMap:
name: consul-config2
items:
- key: my.cnf
path: mysql/my.cnf

/ # ls /etc/myconfig/mysql/
my.cnf
====================================

kind: PodPreset
apiVersion: settings.k8s.io/v1alpha1
metadata:
name: consul-setting2
spec:
selector:
matchLabels:
name: consul
envFrom:
- configMapRef:
name: test-config

kubernetes configmap的更多相关文章

  1. Kubernetes configMap(配置文件存储)

    Kubernetes configMap(配置文件存储) 官方文档:https://kubernetes.io/docs/tasks/configure-pod-container/configure ...

  2. kubernetes Configmap secret的使用

    kubernetes configmap 核心作用是让配置信息和镜像解耦,pod可以使用configmap的数据生成配置文件.如果后端的pod配置文件要改变时,只需要更改下configmap里面的数据 ...

  3. kubernetes ConfigMap和Secret:配置应用程序

    7.1.配置容器化应用程序 7.2.向容器传递命令行参数 7.2.1.待Docker中定义命令与参数 1.了解ENTRYPOINT与CMD ENTRYPOINT定义容器启动时被调用的可以执行程序 CM ...

  4. (十)Kubernetes ConfigMap和Secret

    ConfigMap资源 介绍 ConfigMap是让配置文件从镜像中解耦,让镜像的可移植性和可复制性.许多应用程序会从配置文件.命令行参数或环境变量中读取配置信息.这些配置信息需要与docker im ...

  5. Kubernetes ConfigMap详解,多种方式创建、多种方式使用

    我最新最全的文章都在南瓜慢说 www.pkslow.com,欢迎大家来喝茶! 1 简介 配置是程序绕不开的话题,在Kubernetes中使用ConfigMap来配置,它本质其实就是键值对.本文讲解如何 ...

  6. Kubernetes ConfigMap热更新

    ConfigMap是用来存储配置文件的kubernetes资源对象,所有的配置内容都存储在etcd中. 总结 更新 ConfigMap 后: 使用该 ConfigMap 挂载的 Env 不会同步更新 ...

  7. kubernetes 一些基本的概念

    k8s 原理 kubernetes API server 作为集群的核心,负责集群各功能之间的通信, 集群内的各个功能模块通过API Server将信息存入etcd,当需要获取和操作这些数据的时候 通 ...

  8. 微服务Spring Cloud与Kubernetes比较

    转 http://www.tuicool.com/articles/VnMf2y3 Spring Cloud或Kubernetes都宣称它们是开发运行微服务的最好环境,哪个更好?答案是两个都是,但他们 ...

  9. Kubernetes 在网易云中的落地优化实践

    本文来自网易云社区 今天我跟大家讲的是 Kubernetes 在网易的一些实践,目的是抛砖引玉,看看大家在这个方向有没有更好的实践方法.简单介绍一下网易云.网易云是从最早 Kubernetes 1.0 ...

随机推荐

  1. Cocos2d-x第一次调试出现的问题

    1.无法打开包括文件:“CCStdC.h“ http://blog.csdn.net/jbboy/article/details/9773087 2.无法打开文件“libcocos2d.lib” 用v ...

  2. RabbitMQ消息的消费与持久化

    作为消费者的客户端要消费Rabbitmq的消息,首先要建立与它某个队列的连接,具体连接时可指定队列的BindingKey和关系的exchange标识,Rabbitmq判断若已有队列通过BindingK ...

  3. [LeetCode系列]N皇后问题递归解法 -- 位操作方式

    N皇后问题: 给定8*8棋盘, 放置n个皇后, 使其互相不能攻击(即2个皇后不能放在同一行/列/正反对角线上), 求解共有多少种放置方式? 这个问题的解答网上有不少, 但是位操作解法的我看到的不多. ...

  4. wordpress上传文件,插件无法建立目录(根本原因解决)

    刚建立的wp网站经常遇到上传图片或者下载插件“无法建立目录”的问题,肯定是权限的问题,网上大部分解决方案都是把uploads或者 plugins权限手动改成777, 有一部分人成功了,有一部分没成功, ...

  5. [转][Java]Maven使用阿里云镜像

    本文来自:http://www.cnblogs.com/justforcon/p/6792039.html <settings xmlns="http://maven.apache.o ...

  6. python的可变数据类型和不可变类型

    python里面一切皆对象 ython的每个对象都分为可变类型和不可变类型 整形,浮点型,字符串,元组属于不可变类型,列表,字典是可变类型 不可变数据类型 对不可变类型的变量重新赋值,实际上是重新创建 ...

  7. C语言实现Base64编码/解码

    Bse64是一种以64个可打印字符对二进制数据进行编码的编码算法.base64在对数据进行编码时以三个8位字符型数据为一组,取这三个字符型数据的ASCII码,然后以6位为一组组成4个新的数据,这4个新 ...

  8. 【UVa】1606 Amphiphilic Carbon Molecules(计算几何)

    题目 题目 分析 跟着lrj学的,理解了,然而不是很熟,还是发上来供以后复习 代码 #include <bits/stdc++.h> using namespace std; ; stru ...

  9. 安卓权限处理 PermissionDog

    PermissionDog 简介 权限狗 权限申请 最近在一家公司实习,项目中需要用到适配安卓6.0以上的系统,我本来是想用其他人已经写好的权限申请框架来实现的,但是发现跟我的需求有点小区别,所以就自 ...

  10. Druid.io系列(一):简介

    原文链接: https://blog.csdn.net/njpjsoftdev/article/details/52955676 Druid.io(以下简称Druid)是面向海量数据的.用于实时查询与 ...