惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
G
Google Developers Blog
aimingoo的专栏
aimingoo的专栏
罗磊的独立博客
博客园 - 【当耐特】
M
MIT News - Artificial intelligence
D
Docker
博客园 - 三生石上(FineUI控件)
博客园 - 司徒正美
人人都是产品经理
人人都是产品经理
博客园 - 叶小钗
月光博客
月光博客
S
SegmentFault 最新的问题
Jina AI
Jina AI
Blog — PlanetScale
Blog — PlanetScale
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - Franky
L
LangChain Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Microsoft Azure Blog
Microsoft Azure Blog
阮一峰的网络日志
阮一峰的网络日志
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Last Week in AI
Last Week in AI

mafeifan 的编程技术分享

mafengwo-mp3-downloader | mafeifan 的编程技术分享 示例页面 | mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 查看 default namespace 下的 default service account名称 mafeifan 的编程技术分享 检查日志 | mafeifan 的编程技术分享 bridge fdb show dev flannel.1 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享
mafeifan 的编程技术分享
2026-01-16 · via mafeifan 的编程技术分享

作用 ​

数据键值对,作为Pod的配置文件或环境变量。

configmap的数据可以来自三种类型:字面量,文件和目录

bash

mkdir primary
echo g > primary/green
echo r > primary/red
echo y > primary/yellow
echo k > primary/black
echo "known as key" >> primary/black
echo blue > favorite

kubectl create configmap colors \
     --from-literal=text=black  \
     --from-file=./favorite  \
     --from-file=./primary/
     
kubectl get configmap colors
kubectl get configmap colors -o yaml

configMap作为环境变量传入Pod ​

simpleshell.yaml

yaml

apiVersion: v1
kind: Pod
metadata:
  name: shell-demo
spec:
  containers:
  - name: nginx
    image: nginx
    env:
      - name: ilike
        valueFrom:
          configMapKeyRef:
            name: colors
            key: favorite

bash

kubectl create -f simpleshell.yaml
kubectl exec shell-demo -- /bin/bash -c 'echo $ilike'
kubectl delete pod shell-demo

也可以把全部的文件内容作为环境变量传入Pod。稍微修改下simpleshell2.yaml

yaml

apiVersion: v1
kind: Pod
metadata:
  name: shell-demo2
spec:
  containers:
  - name: nginx
    image: nginx
#    env:
#      - name: ilike
#        valueFrom:
#          configMapKeyRef:
#            name: colors
#            key: favorite
    envFrom:
      - configMapRef:
          name: colors

kubectl exec shell-demo -- /bin/bash -c 'env'

作为挂载卷 ​

yaml

kind: ConfigMap
apiVersion: v1
metadata:
  name: redis-conf
  namespace: iot-ningxia
  annotations:
    kubesphere.io/creator: admin
data:
  redis.conf: |-
    appendonly yes
    port 6379
    bind 0.0.0.0

挂载到StatefulSet的Pod中

yaml

kind: StatefulSet
apiVersion: apps/v1
metadata:
  name: redis
  namespace: iot-ningxia
  labels:
    app: redis
  annotations:
    kubesphere.io/creator: mafei
spec:
  serviceName: redis
  replicas: 1
  selector:
    matchLabels:
      app: redis
  template:
    metadata:
      labels:
        app: redis
    spec:
      volumes:
        - name: volume-redis-conf
          configMap:
            name: redis-conf
      containers:
        - name: redis
          image: 'redis:6'
          command:
            - redis-server
          args:
            - /etc/redis/redis.conf
          ports:
            - name: tcp-6379
              containerPort: 6379
              protocol: TCP
          volumeMounts:
            - name: volume-redis-conf
              readOnly: true
              mountPath: /etc/redis
          imagePullPolicy: IfNotPresent