美文网首页K8s安装
2.4、深入pod-configMap

2.4、深入pod-configMap

作者: yezide | 来源:发表于2019-06-16 14:01 被阅读0次

    1、 创建configMap

    1.1 yaml文件方式

    太长,详见此

    创建命令
    kubectl create -f cm-appconfigfiles.yaml 
    

    1.2 命令行方式

    kubectl create cm cm_test --from-literal=k1=v1
    

    1.3 pod通过环境变量使用cm

    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: cm-appvars
    data:
      appLogLevel: info
      appDataDir: /var/data
    

    创建个容器使用cm

    apiVersion: v1
    kind: Pod
    metadata:
      name: cm-test-pod
    spec:
      containers:
      - name: cm-test-container
        image: busybox
        command: ["/bin/sh", "-c", "env | grep APP"]
        env:
        - name: APPLOGLEVEL
          valueFrom:
            configMapKeyRef:
              name: cm-appvars
              key: appLogLevel
        - name: APPDATADIR
          valueFrom:
            configMapKeyRef:
              name: cm-appvars
              key: appDataDir
    

    1.4 通过volumeMount方式使用

    apiVersion: v1
    kind: Pod
    metadata:
      name: cm-test-app
    spec:
      containers:
      - name: cm-test-app
        image: kubeguide/tomcat-app:v1
        ports:
        - containerPort: 80
        volumeMounts:
        - name: v-serverxml #引用的volume名
          mountPath: /configs
      volumes:
      - name: v-serverxml
        configMap:
          name: cm-appconfigfiles #使用这个名字的cm
          items:
          - key: key-svr-xml
            path: server.xml
          - key: key-log4j-pro
            path: logging.properties
    

    登陆容器,看/configs目录下是否有2个文件server.xml和logging.properties

    kubectl exec -it cm-test-app -- bash
    cd /configs
    ls -l
    

    相关文章

      网友评论

        本文标题:2.4、深入pod-configMap

        本文链接:https://www.haomeiwen.com/subject/glzffctx.html