(2022版)一套教程搞定k8s安装到实战 | Secret

视频来源:B站《(2022版)最新、最全、最详细的Kubernetes(K8s)教程,从K8s安装到实战一套搞定》

一边学习一边整理老师的课程内容及试验笔记,并与大家分享,侵权即删,谢谢支持!

附上汇总贴:(2022版)一套教程搞定k8s安装到实战 | 汇总_COCOgsta的博客-CSDN博客


Secret用来保存敏感信息的,比如密码、令牌或者key、Redis、MySQL密码。

Secret介绍地址:kubernetes.io/docs/concep…

$ * \ 特殊字符单引号无需转义

ImagePullSecret:Pod拉取私有镜像仓库时使用的账号密码,里面的帐号信息,会传递给kubelet,然后kubelet就可以拉去有密码的仓库里面的镜像。

创建一个docker registry的secret

[root@k8s-master-lb ~]# kubectl create secret docker-registry docker-secret2 --docker-server=hub.docker.com --docker-username=DOCKER_USER --docker-password=DOCKER_PASSWORD --docker-email=DOCKER_EMAIL
secret/docker-secret2 created
复制代码

test-env-pod.yaml

apiVersion: v1
kind: Pod
metadata:
  name: dapi-test-pod
spec:
  nodeName: k8s-node01
  imagePullSecrets:
    - name: docker-secret2
  containers:
    - name: test-container
      image: busybox:1.28
      imagePullPolicy: IfNotPresent
      command: [ "/bin/sh", "-c", "sleep 3600" ]
      volumeMounts:
      - name: config-volume
        mountPath: /mnt
      envFrom:
      - configMapRef:
          name: special-config
      env:
        # Define the environment variable
        # - name: SPECIAL_LEVEL_KEY
        #   valueFrom:
        #     configMapKeyRef:
        #       # The ConfigMap containing the value you want to assign to SPECIAL_LEVEL_KEY
        #       name: special-config
        #       # Specify the key associated with the value
        #       key: special.how
        - name: test
          value: test-value
        - name: mysqlHostAddress
          value: 10.10.10.10
        - name: mysqlPort
          value: "3306" # only string
  restartPolicy: Never
  volumes:
    - name: config-volume
      configMap:
        name: special-config
复制代码

subPath解决目录覆盖的问题

apiVersion: v1
kind: Pod
metadata:
  name: dapi-test-pod
spec:
  nodeName: k8s-node01
  imagePullSecrets:
    - name: docker-secret2
  containers:
    - name: test-container
      image: busybox:1.28
      imagePullPolicy: IfNotPresent
      command: [ "/bin/sh", "-c", "sleep 3600" ]
      volumeMounts:
      - mountPath: /etc/nginx/nginx.conf
        name: config-volume
        subPath: etc/nginx/nginx.conf
      envFrom:
      - configMapRef:
          name: special-config
      env:
        # Define the environment variable
        # - name: SPECIAL_LEVEL_KEY
        #   valueFrom:
        #     configMapKeyRef:
        #       # The ConfigMap containing the value you want to assign to SPECIAL_LEVEL_KEY
        #       name: special-config
        #       # Specify the key associated with the value
        #       key: special.how
        - name: test
          value: test-value
        - name: mysqlHostAddress
          value: 10.10.10.10
        - name: mysqlPort
          value: "3306" # only string
  restartPolicy: Never
  volumes:
    - configMap:
        defaultMode: 420
        items:
        - key: nginx.conf
          path: etc/nginx/nginx.conf
        name: nginx-conf
      name: config-volume
复制代码

ConfigMap和Secret如果是以subPath的形式挂载的,那么Pod是不会感知到ConfigMap和Secret的更新的。

如果Pod的变量来自于ConfigMap和Secret中定义的内容,那么ConfigMap和Secret更新后,也不会更新Pod中的变量。

解决办法

apiVersion: v1
kind: Pod
metadata:
  name: dapi-test-pod
spec:
  nodeName: k8s-node01
  imagePullSecrets:
    - name: docker-secret2
  containers:
    - name: test-container
      image: busybox:1.28
      imagePullPolicy: IfNotPresent
      command: [ "/bin/sh", "-c", "sleep 3600" ]
      volumeMounts:
      - mountPath: /etc/nginx/nginx.conf
        name: config-volume
        subPath: etc/nginx/nginx.conf
      - mountPath: /mnt/
        name: config-volume-non-subpath
      envFrom:
      - configMapRef:
          name: special-config
      env:
        # Define the environment variable
        # - name: SPECIAL_LEVEL_KEY
        #   valueFrom:
        #     configMapKeyRef:
        #       # The ConfigMap containing the value you want to assign to SPECIAL_LEVEL_KEY
        #       name: special-config
        #       # Specify the key associated with the value
        #       key: special.how
        - name: test
          value: test-value
        - name: mysqlHostAddress
          value: 10.10.10.10
        - name: mysqlPort
          value: "3306" # only string
  restartPolicy: Never
  volumes:
    - configMap:
        defaultMode: 420
        items:
        - key: nginx.conf
          path: etc/nginx/nginx.conf
        name: nginx-conf
      name: config-volume
    - configMap:
        defaultMode: 420
        name: nginx-conf
      name: config-volume-non-subpath
复制代码

postStart:容器启动之前执行的命令

preStop:容器停止之前执行的命令

热更新ConfigMap或Secret:

kubectl create cm nginx-conf --from-file=nginx.conf --dry-run -oyaml | kubectl replace -f-
复制代码

immutable:在ConfigMap和Secret的最后加上如下内容,则不再可以edit该ConfigMap或Secret

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Kubernetes指南-倪朋飞.pptx 1-唐继元Kubernetes Master High Availability 高级实践.pdf 2、刘淼-基于 DevOps、微服务及k8s的高可用架构探索与实现.pdf ArchSummit北京2016-《网易蜂巢基于万节点Kubernets支撑大规模云应用实践》-刘超.pdf Azure Service Broker_cn - Rita Zhang.pdf google/ HPE李志霄 Kubernetes企业级容器云:加速数字创新-20170407.pdf IBM马达:Kubernetes 中基于策略的资源分配.pdf k8s资料.rar Kubernetes Cookbook-Packt Publishing(2016).pdf Kubernetes Microservices with Docker-Apress2016.pdf Kubernetes on Azure - Gabe Monroy.pdf Kubernetes1.6集群部署完全指南——二进制文件部署开启TLS基于CentOS7.pdf Kubernetes1-4本新增加功能介绍.pdf Kubernetes监控与日志.pdf kubernetes容器云平台实践-李志伟v1.0.pdf Kubernetes生态系统现状报告.pdf Kubernetes下API网关的微服务实践 长虹集团-李玮演讲PPT.pdf Kubernetes与EcOS的碰撞结合 成都精灵云-张行才演讲PPT.pdf Kubernetes与OpenStack融合支撑企业级微服务架构.pdf Kubernetes在华为全球IT系统中的实践.pdf Kubernetes在企业中的场景运用及管理实践.pdf Kubernetes指南-倪朋飞.pdf Kubernetes指南-倪朋飞.pptx l.txt Lessons+learned+and+challenges+faced+while+running+Kubernetes+at+scale.pdf rkt与Kubernetes的深度融合.pdf rkt与Kubernetes的深度融合.pptx SACC2017FabricOnKubernetesChinese.pdf ThoughtWorks林帆-白话Kubernetes网络.pdf 百度云PaddlePaddle on kubernetes-周倜.pdf 从Borg到Kubernetes-PaaS产品设计-华为-钟成.pdf 改造Kuberntetes打造SAE容器云.pdf 跟谁学-基于容器的持续集成平台建设.pdf 谷歌深度学习在Kubernetes上的实践.pptx 惠普基于Kubernetes容器私有云平台实践.pdf 基于Kubernetes的模板化应用编排.pdf 基于kubernetes容器云平台设计与实践-邓德源.pdf 基于Kubernetes的私有容器云建设实践-易宝支付.pdf 基于Kubernetes构建AI业务生态.pdf 李波:小米生态云应用引擎实践.pdf 魅族容器云平台基于 k8s 的自动化运维实践-曾彬.pdf 欧昌华-基于 Nginx 的负载均衡器在 K8S 中的实践.pdf 彭超:瓜子云的落地.pdf 如何落地TensorFlow on Kubernetes.pdf 如何用OpenStack和Kubernetes快速搭建一个容器和虚拟机组合服务的云平台.pptx 孙杰:大型企业云平台架构演进的实践之路.pdf 微服务道与术-敖小剑.pdf 微软Azure云助力微服务-赵文婧.pdf 颜卫-腾讯云容器服务基于kubernetes的应用编排实践-final-v1.0.pptx 有容云邓绍军-Kubernetes落地实践.pptx 折800如何用Docker&Kubernetes;构建自动化测环境.pdf

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值