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. Java中的静态方法能否被重写

    能重写,但没有多态:https://blog.csdn.net/ghgzczxcvxv/article/details/43966243

  2. python绘图踩的坑

    踩的坑 pyecharts安装地图包 pip install echarts-countries-pypkg 报错Unknown or unsupported command 'install' 这可 ...

  3. Web 漏洞分析与防御之 CSRF(二)

    原文地址:Web 漏洞分析与防御之 CSRF(二) 博客地址:http://www.extlight.com 一.全称 跨站请求伪造(Cross-site Request Forgery) 二.原理 ...

  4. Java API 操作Zookeeper

    一.依赖 <dependency> <groupId>org.apache.zookeeper</groupId> <artifactId>zookee ...

  5. undefined vs. null

    undefined vs. null 一.相似性 在JavaScript中,将一个变量赋值为undefined或null,老实说,几乎没区别. var a = undefined; var a = n ...

  6. 小峰Hibernate简介与HelloWorld

    一.Hibernate简介: 二.Hibernate4 版Hello World 实现 工程结构: com.cy.model.Student: package com.cy.model; public ...

  7. Java-Runoob:Java Stream、File、IO

    ylbtech-Java-Runoob:Java Stream.File.IO 1.返回顶部 1. Java 流(Stream).文件(File)和IO Java.io 包几乎包含了所有操作输入.输出 ...

  8. Ajax显示隐藏

    $(function(){ $('#search').click(function(){ if($(".search_div").is(":visible")) ...

  9. ALSA声卡09_从零编写之参数设置_学习笔记

    1.参数设置分析 (1)open: soc_pcm_open 依次调用cpu_dai, dma, codec_dai, machine的open或startup函数 只在dma的open函数里添加参数 ...

  10. ALSA声卡笔记3--ASoC驱动重要结构体关系图

    1.ASoC中重要的数据结构之间的关联方式 (1)Kernel-2.6.35-ASoC中各个结构的静态关系 ASoC把声卡实现为一个Platform Device,然后利用Platform_devic ...