stardust-shadow

导航

k8s - ConfigMap

apiVersion: v1
kind: ConfigMap
metadata:
  name: my-config
data:
  key1: value1
  key2: value2
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: app-config
data:
  application.yaml

通过文件加载

kubectl create configmap myconfigmap --from-file=./username --from-file=./password

kubectl create configmap my-config --from-env-file=xxx

kubectl create cm redis-conf --from-file=redis.conf

kubectl get cm -oyaml

redis Pod:


apiVersion: v1
kind: Pod
metadata:
   name: redis
spec:
  containers:
  - name: redis
    image: redis
    command:
      - redis-server
      - "/redis-master/redis.conf"
    ports:
    - containerPort: 6739
    volumeMounts:
    - mountPath: /data
      name: data
    - mountPath: /redis-master
      name: config
  volumes:
    - name: data
      emptyDir: {}
    - name: config
      configMap:
        name: redis-conf
        items:
        - key: redis.conf
          path: redis.conf

kubectl exec -it redis -- redis-cli
kubectl edit cm redis-conf

posted on 2025-07-19 16:57  阡年  阅读(4)  评论(0)    收藏  举报