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

  • 相关阅读:
    第二次作业——结对项目需求分析与原型设计
    调研《构建之法》指导下的历届作品
    软件工程的实践项目课程的自我目标
    使用@Scheduled注解做定时任务
    ng2中的百度echarts3.0使用——(echarts-ng2)
    angular-cli.json配置参数解释,以及依稀常用命令的通用关键参数解释
    SpringData实现Mongodb的CRUD:MongoTemplate框架
    idea利用jdbc连接ORACLE数据库实现一个查询显示
    dbvisualizer的使用
    DUBBO开发问题:添加无法生成主键
  • 原文地址:https://www.cnblogs.com/litzhiai/p/15021619.html
Copyright © 2020-2023  润新知