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. 转发 GSLB概要和实现原理

    What is GSLB Global Server Load Balancing 中文:全局负载均衡 SLB(Server load balancing)是对集群内物理主机的负载均衡,而GSLB是对 ...

  2. saas 系统租户自助网站

    1. 原理       类似github 的自定义页面,使用jekyll 进行租户自助网站的生成,系统使用jenkins 进行租户的网站构建    同时结合租户的个性化域名系统,进行租户页面的发布管理 ...

  3. Windows Server 2008 R2远程协助选项灰色

    管理工具——〉服务器管理器——〉功能——〉添加功能     窗口中"远程服务器管理工具"下边的"远程协助"打上对钩"再点击"下一步" ...

  4. bzoj1025(SCOI2009)游戏——唯一分解的思路与应用

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1025 可以认为对应的值之间连边,就连成了一个有一个或几个环的图.列数就是每个环里点数的lcm ...

  5. 1072. Gas Station (30) 多源最短路

    A gas station has to be built at such a location that the minimum distance between the station and a ...

  6. 在Mac OS上搭建Python的开发环境

    本文转载自:http://www.jb51.net/article/76931.htm 一. 安装python mac系统其实自带了一个python的执行执行环境,用来运行python还行,但是开发可 ...

  7. 干货:这也许是最全面透彻的一篇RabbitMQ指南!

    本文大纲: RabbitMQ 历史 RabbitMQ 应用场景 RabbitMQ 系统架构 RabbitMQ 基本概念 RabbitMQ 细节阐明 历史-从开始到现在 RabbitMQ是一个Erlan ...

  8. nested exception is com.mysql.jdbc.PacketTooBigException: Packet for query is too large (1109 > 1024

    MySQL的一个系统参数:max_allowed_packet >mysql -u root -p //root登录 1. 查看系统参数:show VARIABLES like '%max_al ...

  9. Angular2 如何使用jquery

    网上找了很多版本尝试都不行,最后在stackoverflow上找到一个,尝试完美解决 具体操作步骤如下 1. 安装jquery npm install jquery 2.安装 type for jqu ...

  10. Oracle调优之buffer pool相关

    一个oracle block与data buffer中的一个buffer对应.用户进程(server process)负责读取磁盘上的block到data buffer cache中,DEWn进程负责 ...