zoukankan      html  css  js  c++  java
  • Kubernetes

    ConfifigMap 的创建
     
    Ⅰ、使用目录创建
    Ⅱ、使用文件创建
    Ⅲ、使用字面值创建
     
    使用目录创建
       在/root/test/configmap下创建两个文件,内容如下
      
    [root@xgcloud-ops-k8s-cluster-2 configmap]# cat game.properties 
    enemies=aliens
    lives=3
    enemies.cheat=true
    enemies.cheat.level=noGoodRotten
    secret.code.passphrase=UUDDLRLRBABAS
    secret.code.allowed=true
    secret.code.lives=30
    
    
    [root@xgcloud-ops-k8s-cluster-2 configmap]# cat ui.properties 
    color.good=purple
    color.bad=yellow
    allow.textmode=true
    how.nice.to.look=fairlyNice

      创建命令:

    kubectl create configmap game-config --from-file=/root/test/configmap

     使用文件创建 
      创建命令:
    kubectl create configmap game-config-2 --from-file=/root/test/configmap/game.properties

    使用字面值创建

    kubectl create configmap special-config --from-literal=special.how=very --from-literal=special.type=charm

    Pod 中使用 ConfifigMap
     
    通过数据卷插件使用ConfifigMap
    pod.yaml:
    apiVersion: v1
    kind: Pod
    metadata:
      name: pod-cm-2
      namespace: default
      labels:
        app: myapp
        tier: frontend
      annotations:
        test.com/created-by: "cluster admin"
    spec:
      containers:
      - name: myapp
        image: ikubernetes/myapp:v1
        ports:
        - name: http
          containerPort: 80
        volumeMounts:
        - name: nginxconf
          mountPath: /etc/nginx/config.d/   #挂载点不存在,Pod会自动创建.
          readOnly: true       #不能让容器修改配置的内容。
      volumes:
      -  name: nginxconf        #定义存储卷的名字为nginxconf
         configMap:
           name: game-config   #要挂载nginx-config这个configMap

    kubectl apply -f pod.yaml 

    kubectl exec -it pod/pod-cm-2 sh

    相当于已文件的形式引入进去了

    使用 ConfifigMap 来替代环境变量

     pod1.yaml:

    apiVersion: v1
    kind: Pod
    metadata:
      name: pod-cm-1
      namespace: default
      labels:
         app: myapp
         tier: frontend
      annotations:
         test.com/created-by: "cluster admin"
    spec:
      containers:
      - name: myapp
        image: ikubernetes/myapp:v1
        ports:
        - name: http
          containerPort: 80
        env:
          - name: NGINX_SERVER_PORT
            valueFrom:
              configMapKeyRef:
                 name: special-config
                 key: special.type
          - name: NGINX_SERVER_NAME
            valueFrom:
              configMapKeyRef:
                name: special-config
                key: special.how

     kubectl apply -f pod1.yaml

    kubectl exec -it pod/pod-cm-1 sh

     
    ConfifigMap 的热更新
    修改configmap
     
    kubectl edit configmap log-config

    kubectl patch deployment my-nginx --patch '{"spec": {"template": {"metadata": {"annotations": {"version/config": "20190411" }}}}}'

  • 相关阅读:
    LeetCode 81 Search in Rotated Sorted Array II(循环有序数组中的查找问题)
    LeetCode 80 Remove Duplicates from Sorted Array II(移除数组中出现两次以上的元素)
    LeetCode 79 Word Search(单词查找)
    LeetCode 78 Subsets (所有子集)
    LeetCode 77 Combinations(排列组合)
    LeetCode 50 Pow(x, n) (实现幂运算)
    LeetCode 49 Group Anagrams(字符串分组)
    LeetCode 48 Rotate Image(2D图像旋转问题)
    LeetCode 47 Permutations II(全排列)
    LeetCode 46 Permutations(全排列问题)
  • 原文地址:https://www.cnblogs.com/litzhiai/p/15021619.html
Copyright © 2011-2022 走看看