zoukankan      html  css  js  c++  java
  • 使用Configmap 配置 springboot的application.yaml文件的方式部署环境的方法

    Configmap部署k8s下Springboot服务的办法


    前提

    • 日常工作中需要使用k8s部署微服务环境, 但是内部的数据库连接和redis等连接非常麻烦,使用helm chart 进行变量替换时非常繁琐,要求也比较高.
    • 与同事沟通发现可以使用configmap的方式进行替换,内部文件, 最近进行了实验,总结如下.

    获取配置文件

    • 使用产品在需要部署的环境下,或者是客户现场进行修改
    修改redis的配置信息, 主要是 host port password 等.
    修改rabbitmq等的信息,主要是 host password 以及virtual_host等.
    修改数据库连接信息, 建议使用 tools/setup的方式进行注册,避免异常.
    
    • 修改好注册好后,放到特定目录备用.

    重建configmap

    • 注意congfigmap的方式有多种,这里因为仅是进行文件替换,所以选择from file的方式.
    kubectl create configmap appconfig --from-file=application.yaml
    
    注意创建完成后可以使用
    kubectl get configmap  dappconfig -o yaml
    的方式进行查看.
    

    修改部署服务的deployment 配置节

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      labels:
        app: test
      name: test-deployment
      namespace: default
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: test
      template:
        metadata:
          labels:
            app: test
        spec:
          containers:
          - image: images:tag
            volumeMounts:
              - mountPath: /yourapp/server/runtime/application.yaml
                name: dapplication
                subPath: application.yaml
            ports:
            - containerPort: 5200
            name: igix
          volumes:
            - name: application
              configMap:
                name: appconfig
    

    修改部署服务的deployment 配置节

    • 注意需要在 volumeMounts 内添加描述信息
    • name 必须与创建的configmap 名字保持一致.
    • mountPath 指向的你要使用configmap替换的具体的配置文件.
    • subPath 需要执行需要替换的文件名, 如果不输入会报错,
    • volumes 里面需要添加 configMap的配置信息, 注意需要与 定义的configmap保持一致.

    部署deployment 然后部署serveice 使用nodePort的方式验证即可.

    • 使用configmap 比较简单, 避免变量替换, 可以省下很多时间.
  • 相关阅读:
    进程与线程
    the art of seo(chapter seven)
    the art of seo(chapter six)
    the art of seo(chapter five)
    the art of seo(chapter four)
    the art of seo(chapter three)
    the art of seo(chapter two)
    the art of seo(chapter one)
    Sentinel Cluster流程分析
    Sentinel Core流程分析
  • 原文地址:https://www.cnblogs.com/jinanxiaolaohu/p/15643937.html
Copyright © 2011-2022 走看看