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" }}}}}'

  • 相关阅读:
    iframe的两种通信方式,iframe的history的优先级
    React-router 将弹框Modal嵌入路由(create a modal route with react-router)
    vue 项目构建 + webpack
    vue 生命周期,v-bind 和 v-on的区别(或 : 和 @的区别),以及父传子、子传父的值传递方式
    linux上配置Sonar代码扫描
    玩转jenkins
    程序小猿的rpa----艺赛旗阶段
    学习完level3加入了uipath家庭,欢迎交流学习。小清风的rpa
    程序员小时光的rpa成长之路(艺赛旗)
    数学期望
  • 原文地址:https://www.cnblogs.com/litzhiai/p/15021619.html
Copyright © 2011-2022 走看看