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. Redis 列表 List 主要操作函数

    /** * redis 列表 List Redis列表是简单的字符串列表,按照插入顺序排序.你可以添加一个元素导列表的头部(左边)或者尾部(右边) */ //lpush 新增一个列,多个列可以用空格隔 ...

  2. vs2013环境下boost配置

    编译boost库的过程这里暂时不写.  先写在vs2013下的boost配置. 新建一个工程, 1, 属性->C/C++,在附加包含目录添加或编辑Boost的文件路径, D:\boost_1_5 ...

  3. cockroachdb 安装试用(单机伪分布式)

    1. 下载 以下地址,选择对应的操作系统版本即可 https://www.cockroachlabs.com/docs/stable/install-cockroachdb.html 2. 启动 // ...

  4. [LeetCode系列]括号生成问题

    给定n, 返回所有匹配的n对括号的可能形式. 如 给定 n = 3, 一个解集是: "((()))", "(()())", "(())()" ...

  5. 搭建Spring Cloud+Dubbo

    公司要测试一下zipkin是否可以跟踪全流程,项目的架构比较复杂,不要问我为什么,基本架构如下:前端门户,调用spring cloud组件,spring cloud在调用dubbo,这样一套流程.于是 ...

  6. TOMCATE8下面项目启动问题

    1.将servlet-api.jar替换项目中的servlet-api2.4 2.<servlet>           <servlet-name>dwr-invoker&l ...

  7. Log4j配置概述

    一.Log4j 简介 Log4j有三个主要的组件:Loggers(记录器),Appenders (输出源)和Layouts(布局).这里可简单理解为日志类别,日志要输出的地方和日志以何种形式输出.综合 ...

  8. python 函数名的应用(第一类对象),闭包,迭代器

    1.函数名的应用(第一类对象) 函数名的命名规范和变量是一样的 函数名其实就是变量名 可以作为列表中的元素进行储存. def func1(): pass def func2(): pass lst = ...

  9. 导航条且手机版.html——仿照官网例子

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  10. Velocity基本常用语法

    Velocity是一个基于java的模板引擎(template engine),它允许任何人仅仅简单的使用模板语言(template language)来引用由java代码定义的对象.作为一个比较完善 ...