美文网首页
Deployment volumes configMap

Deployment volumes configMap

作者: Yellowtail | 来源:发表于2019-07-23 22:33 被阅读0次

    概述

    本文大部分内容来自 博客

    加了一些个人的理解

    场景

    希望把 ConfigMap 映射为 pod 的 配置文件,通过修改 ConfigMap 的方式 来达到 修改容器内配置文件的效果

    ConfigMap示例

    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: traefik-conf
      namespace: nginx
    data:
      traefik.toml: |
        [entryPoints]
          [entryPoints.http]
          address = ":80"
        traefikLogsFile = "log/traefik.log"
        [accessLog]
        filePath = "/logs/traefik.access.log"
        format = "json"
    

    Deployment

    kind: Deployment
    apiVersion: extensions/v1beta1
    metadata:
      name: traefik-ingress-controller
      namespace: nginx
      labels:
        k8s-app: traefik-ingress-lb
    spec:
      replicas: 1
      selector:
        matchLabels:
          k8s-app: traefik-ingress-lb
      template:
        metadata:
          labels:
            k8s-app: traefik-ingress-lb
            name: traefik-ingress-lb
        spec:
          serviceAccountName: traefik-ingress-controller
          terminationGracePeriodSeconds: 60
          volumes:
          - name: traefik-config
            configMap:
              name: traefik-conf
          containers:
          - image: traefik:1.7
            name: traefik-ingress-lb
            volumeMounts:
            - name: traefik-config
              mountPath: /etc/traefik/
            ports:
            - name: http
              containerPort: 80
            - name: admin
              containerPort: 8080
            args:
            - --api
            - --kubernetes
            - --logLevel=INFO
    

    语法理解

    先来看下 spec.volumes的内容

    volumes:
          - name: traefik-config
            configMap:
              name: traefik-conf
    

    定义了一个 nametraefik-config 的这么一个 volume
    它的值来自于 configMapnametraefik-conf 的项的 data
    (个人理解,所以其实是一个文件列表,第一个文件名叫 traefik.toml)

    再看下 spec.containers

    containers:
          - image: traefik:1.7
            name: traefik-ingress-lb
            volumeMounts:
            - name: traefik-config
              mountPath: /etc/traefik/
    

    volume 里面取出 nametraefik-config 的项(文件列表), 映射到 路径 /etc/traefik/

    items

    今天看到了items 用法
    也搜了博客
    记录一下

      - name: ymir-agent
        image: hub.c.163.com/u2takey/ymir:v-agent-test11
        imagePullPolicy: IfNotPresent
        volumeMounts:
        - name: config
          mountPath: /go/src/github.com/arlert/ymir/taskset
        - mountPath: /etc/localtime
          name: tz-config
          readOnly: true
      volumes:
      - name: config
        configMap:
          name: name12
          items:
          - key: script
            path: testtask.go
      - hostPath:
          path: /usr/share/zoneinfo/Asia/Shanghai
        name: tz-config
    

    新建了一个 configvolumn
    值来自 name12configMap,
    取出 key-value 键值对, keyscript, 也就是生成了一个名字为 script内容为 value 的文件
    因为有items 存在,可以对这个文件进行改名操作,把script 改成了 testtask.go

    相关文章

      网友评论

          本文标题:Deployment volumes configMap

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