• 【K8S】secret来配置K8S应用(环境变量)--20220916


    参考链接https://blog.csdn.net/jerry00713/article/details/123220938

    步骤1:Base64加密

    http://www.jsons.cn/base64/

    步骤2:创建secret

    方法1:yaml档来设定secret
    apiVersion: v1
    kind: Secret
    metadata:
      name: secret1
    data:
      #REDISPASSWORD: redis654321
      REDISPASSWORD: cmVkaXM2NTQzMjE=
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    方法2:racher直接keyin secret

    在这里插入图片描述

    步骤3:查看或修改secret

    在这里插入图片描述

    也可以通过命令行kubectl get secret -o yaml来查看。

    步骤3:使用configmap来配置

    可以使用环境变量

          env:
          - name: REDIS_LOCATION
            valueFrom:
              configMapKeyRef:
                name: config1
                key: REDIS_LOCATION
          - name: DJANGO_DEBUG
            valueFrom:
              configMapKeyRef:
                name: config1
                key: DJANGO_DEBUG
          - name: REDISPASSWORD
            valueFrom:
              secretKeyRef:
                name: secret1
                key: REDISPASSWORD
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16

    完整的web的yaml档案

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      annotations:
        kompose.cmd: kompose convert
        kompose.version: 1.24.0 (7c629530)
      creationTimestamp: null
      labels:
        io.kompose.service: web
      name: web
    spec:
      replicas: 1
      selector:
        matchLabels:
          io.kompose.service: web
      strategy:
        type: Recreate
      template:
        metadata:
          annotations:
            kompose.cmd: kompose convert
            kompose.version: 1.24.0 (7c629530)
          creationTimestamp: null
          labels:
            io.kompose.service: web
        spec:
          containers:
            - command:
                - /bin/sh
                - /code/package/start.sh
              image: seasonzhang/gaga_meeting:0.9.16
              imagePullPolicy: IfNotPresent
              name: gaga-meeting-web
              ports:
                - containerPort: 8000
              resources:
                requests:
                  cpu: 500m
                  memory: 500Mi
                limits:
                  cpu: 500m
                  memory: 500Mi
              env:
              - name: REDIS_LOCATION
                valueFrom:
                  configMapKeyRef:
                    name: config1
                    key: REDIS_LOCATION
              - name: DJANGO_DEBUG
                valueFrom:
                  configMapKeyRef:
                    name: config1
                    key: DJANGO_DEBUG
              - name: REDISPASSWORD
                valueFrom:
                  secretKeyRef:
                    name: secret1
                    key: REDISPASSWORD
            - command:
                - /bin/sh
                - /code/package/start-beat.sh
              image: seasonzhang/gaga_meeting:0.9.16
              name: gaga-meeting-beat
              resources:
                requests:
                  cpu: 100m
                  memory: 100Mi
                limits:
                  cpu: 200m
                  memory: 200Mi
            - command:
                - /bin/sh
                - /code/package/start-celery.sh
              image: seasonzhang/gaga_meeting:0.9.16
              name: gaga-meeting-celery
              resources:
                requests:
                  cpu: 100m
                  memory: 100Mi
                limits:
                  cpu: 200m
                  memory: 200Mi
    ---
    apiVersion: v1
    kind: Service
    metadata:
      annotations:
        kompose.cmd: kompose convert
        kompose.version: 1.24.0 (7c629530)
      creationTimestamp: null
      labels:
        io.kompose.service: web
      name: web
    spec:
      type: LoadBalancer
      ports:
        - name: "8000"
          port: 8000
          targetPort: 8000
          rotocol: TCP
      selector:
        io.kompose.service: web
      externalIPs: #集群内互访
        - 10.0.8.10
        - 10.43.207.93
    status:
      loadBalancer: {}
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108

    步骤4:Django web应用的settings中需要预留环境变量栏位

    # 只是引用,但是没有使用
    REDISPASSWORD = os.environ.get('REDISPASSWORD',"redis654321")
    
    • 1
    • 2
  • 相关阅读:
    LeetCode 周赛 347(2023/05/28)二维空间上的 LIS 最长递增子序列问题
    LeetCode 63. 不同路径 II
    单片机的智能垃圾桶设计
    ruoyi-vue-pro 项目安装使用过程中的问题解决
    js-聊聊低代码平台
    2023年数维杯国际大学生数学建模挑战赛A题
    BOA服务器和CGI程序移植中遇到的问题及解决方案
    28岁功能测试被辞,最后结局令人感慨...
    ClickHouse 语法优化规则
    今天步行数4000
  • 原文地址:https://blog.csdn.net/m0_46629123/article/details/126891240