Kubernetes部署Apollo多环境

创建K8s命名空间

namespace.yaml

apiVersion: v1
kind: Namespace
metadata:
  name: apollo

apollo-portal的web界面管理端

portal-configmap.yaml

apiVersion: v1
kind: ConfigMap
metadata:
  name: apollo-portal
  namespace: apollo
data:
  application-github.properties: |
    spring.datasource.url = jdbc:mysql://172.30.20.31:3306/apolloportaldb?characterEncoding=utf8
    spring.datasource.username = root
    spring.datasource.password = 123123
  apollo-env.properties: |
    local.meta=http://apollo-portal:8080
    dev.meta = http://apollo-dev-configservice:8080 #环境的端口,如果下面的fat,pro环境
    eureka.service.url = http://apollo-dev-configservice:8080
    #fat.meta=http://apollo-fat-configservice:8080
    #pro.meta=http://apollo-pro-configservice:8080
    #eureka.service.url = http://apollo-dev-configservice:8080,http://apollo-pro-configservice:8080,http://apollo-fat-configservice:8080

portal-deploy.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: apollo-portal
  namespace: apollo
  labels:
    app: apollo-portal
spec:
  replicas: 1
  selector:
    matchLabels:
      app: apollo-portal
  template:
    metadata:
      labels:
        app: apollo-portal
    spec:
      containers:
        - name: apollo-portal
          image: apolloconfig/apollo-portal:latest
          imagePullPolicy: IfNotPresent
          ports:
            - name: http
              containerPort: 8070
              protocol: TCP
          env:
            - name: SPRING_PROFILES_ACTIVE
              value: "github,auth"
          resources:
            limits:
              cpu: "1000m"
              memory: "1024Mi"
            requests:
              cpu: "1000m"
              memory: "1024Mi"
          volumeMounts:
            - name: apollo-portal-config
              mountPath: /apollo-portal/config/application-github.properties
              subPath: application-github.properties
            - name: apollo-portal-config
              mountPath: /apollo-portal/config/apollo-env.properties
              subPath: apollo-env.properties
      volumes:
        - name: apollo-portal-config
          configMap:
            name: apollo-portal
            items:
              - key: application-github.properties
                path: application-github.properties
              - key: apollo-env.properties
                path: apollo-env.properties
            defaultMode: 420

portal-svc.yaml

apiVersion: v1
kind: Service
metadata:
  name: apollo-portal
  namespace: apollo
  labels:
    app: apollo-portal
spec:
  selector:
    app: apollo-portal
  ports:
    - name: http
      protocol: TCP
      port: 8070
      targetPort: 8070

DEV环境的admin和config

adminservice-configmap.yaml

apiVersion: v1
kind: ConfigMap
metadata:
  name: apollo-dev-adminservice
  namespace: apollo
data:
  application-github.properties: |
    spring.datasource.url = jdbc:mysql://172.30.20.31:3306/apolloconfigdb_dev?characterEncoding=utf8
    spring.datasource.username = root
    spring.datasource.password = 123123
    eureka.service.url = http://apollo-dev-configservice:8080/eureka/

configservice-configmap.yaml

apiVersion: v1
kind: ConfigMap
metadata:
  name: apollo-dev-configservice
  namespace: apollo
data:
  application-github.properties: |
    spring.datasource.url = jdbc:mysql://172.30.20.31:3306/apolloconfigdb_dev?characterEncoding=utf8
    spring.datasource.username = root
    spring.datasource.password = 123123
    apollo.config-service.url = http://apollo-dev-configservice:8080
    apollo.admin-service.url = http://apollo-dev-adminservice:8090
    eureka.service.url = http://apollo-dev-configservice:8080/eureka/

adminservice-deploy.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: apollo-dev-adminservice
  namespace: apollo
  labels:
    app: apollo-dev-adminservice
spec:
  replicas: 1
  selector:
    matchLabels:
      app: apollo-dev-adminservice
  template:
    metadata:
      labels:
        app: apollo-dev-adminservice
    spec:
      containers:
        - name: apollo-dev-adminservice
          image: apolloconfig/apollo-adminservice:latest
          imagePullPolicy: IfNotPresent
          ports:
            - name: http
              containerPort: 8090
              protocol: TCP
          env:
            - name: SPRING_PROFILES_ACTIVE
              value: "github,kubernetes"
          resources:
            limits:
              cpu: "1000m"
              memory: "1024Mi"
            requests:
              cpu: "1000m"
              memory: "1024Mi"
          volumeMounts:
            - name: apollo-adminservice-config
              mountPath: /apollo-adminservice/config/application-github.properties
              subPath: application-github.properties
      volumes:
        - name: apollo-adminservice-config
          configMap:
            name: apollo-dev-adminservice
            items:
              - key: application-github.properties
                path: application-github.properties
            defaultMode: 420

configserivce-deploy.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: apollo-dev-configservice
  namespace: apollo
  labels:
    app: apollo-dev-configservice
spec:
  replicas: 1
  selector:
    matchLabels:
      app: apollo-dev-configservice
  template:
    metadata:
      labels:
        app: apollo-dev-configservice
    spec:
      containers:
        - name: apollo-dev-configservice
          image: apolloconfig/apollo-configservice:latest
          imagePullPolicy: IfNotPresent
          ports:
            - name: http
              containerPort: 8080
              protocol: TCP
          env:
            - name: SPRING_PROFILES_ACTIVE
              value: "github,kubernetes"
          resources:
            limits:
              cpu: "1000m"
              memory: "1024Mi"
            requests:
              cpu: "1000m"
              memory: "1024Mi"
          volumeMounts:
            - name: apollo-configservice-config
              mountPath: /apollo-configservice/config/application-github.properties
              subPath: application-github.properties
      volumes:
        - name: apollo-configservice-config
          configMap:
            name: apollo-dev-configservice
            items:
              - key: application-github.properties
                path: application-github.properties
            defaultMode: 420

 adminservice-svc.yaml

apiVersion: v1
kind: Service
metadata:
  name: apollo-dev-adminservice
  namespace: apollo
  labels:
    app: apollo-dev-adminservice
spec:
  selector:
    app: apollo-dev-adminservice
  ports:
    - name: http
      protocol: TCP
      port: 8090
      targetPort: 8090

configservice-svc.yaml

apiVersion: v1
kind: Service
metadata:
  name: apollo-dev-configservice
  namespace: apollo
  labels:
    app: apollo-dev-configservice
spec:
  selector:
    app: apollo-dev-configservice
  ports:
    - name: http
      protocol: TCP
      port: 8080
      targetPort: 8080

注:如果有其他环境配置需要对照dev环境的配置修改一下数据库连接地址,再配置一下portal,即可

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值