zoukankan      html  css  js  c++  java
  • 【k8s】Volume-ConfigMap-file

    环境

    1. kubernetes 1.20.6
    2. Spring Boot 2.5.0-RC1

    目标

    使用文件的方式创建 cm 然后进行挂载。

    示例

    创建 cm

    [root@master ~]# kubectl create cm cm-file --from-file=config/
    configmap/cm-file created
    [root@master ~]# kubectl describe cm cm-file
    Name:         cm-file
    Namespace:    default
    Labels:       <none>
    Annotations:  <none>
    
    Data
    ====
    test.json:
    ----
    {
      "name": "jiangbo",
      "age": 44
    }
    
    test.properties:
    ----
    name=jiangbo
    age=4444
    
    Events:  <none>
    

    绑定到 Pod

    apiVersion: v1
    kind: Pod
    metadata:
      name: spring-k8s
    spec:
      containers:
        - name: spring-k8s
          image: jiangbo920827/spring-k8s:liveness
          volumeMounts:
            - mountPath: /opt/cfg
              name: v1
          ports:
            - containerPort: 8080
      volumes:
        - name: v1
          configMap:
            name: cm-file
    

    查看

    [root@master ~]# kubectl exec spring-k8s -- sh -c "ls -l /opt/cfg/"
    total 0
    lrwxrwxrwx    1 root     root            16 May 16 05:58 test.json -> ..data/test.json
    lrwxrwxrwx    1 root     root            22 May 16 05:58 test.properties -> ..data/test.properties
    

    挂载单个

    apiVersion: v1
    kind: Pod
    metadata:
      name: spring-k8s
    spec:
      containers:
        - name: spring-k8s
          image: jiangbo920827/spring-k8s:liveness
          volumeMounts:
            - mountPath: /opt/cfg
              name: v1
          ports:
            - containerPort: 8080
      volumes:
        - name: v1
          configMap:
            name: cm-file
            items:
              - key: test.properties
                path: test/1.properties
    
    [root@master ~]# kubectl exec spring-k8s -- sh -c "ls -l /opt/cfg/test/"
    total 4
    -rw-r--r--    1 root     root            22 May 16 06:00 1.properties
    [root@master ~]#
    

    总结

    使用文件的方式创建了 cm 的数据,然后挂载到 Pod 中,其中可以选择只挂载 cm 数据中的一部分 key。

    附录

  • 相关阅读:
    xgboost中XGBClassifier()参数详解
    xgboost使用经验总结
    特征选择之Chi卡方检验
    ldd 查看程序依赖库
    paddle——docker实践
    paddle实践
    java常用设计模式
    Java内存模型
    什么是线程?
    MySQL数据库提供了那些函数?
  • 原文地址:https://www.cnblogs.com/jiangbo44/p/14956953.html
Copyright © 2011-2022 走看看