k8s安装部署apollo配置中心

一、文章大纲

二、安装MySQL5.7
三、创建apollo-config
四、创建apollo-admin
五、创建apollo-portal
六、查看apollo各个组件服务状态
七、访问apollo
八、nginx代理配置转发

#注意
一定要先启动apollo-config,再启动apollo-admin,最后启动apollo-portal

二、安装MySQL5.7

1、安装过程参考:离线安装mysql5.7_韩帅平的博客-CSDN博客

2、sql文件下载

apolloportaldb.sql​下载地址:https://github.com/nobodyiam/apollo-build-scripts/blob/master/sql/apolloportaldb.sql
apolloconfigdb.sql​下载地址:https://github.com/nobodyiam/apollo-build-scripts/blob/master/sql/apolloconfigdb.sql
#修改apolloconfigdb.sql文件
VALUES
    ('eureka.service.url', 'default', 'http://10.96.69.115:32109/eureka/', 'Eureka服务Url,多个service以英文逗号分隔'),   #修改localhost:8080为apollo-config的Service Ip+NodePort端口,可在apollo-config服务创建好之后再修改导入库表
    ('namespace.lock.switch', 'default', 'false', '一次发布只能有一个人修改开关'),
    ('item.key.length.limit', 'default', '128', 'item key 最大长度限制'),
    ('item.value.length.limit', 'default', '20000', 'item value最大长度限制'),
    ('config-service.cache.enabled', 'default', 'false', 'ConfigService是否开启缓存,开启后能提高性能,但是会增大内存消耗!');

3、数据库内导入config、admin数据库表

mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5048
Server version: 5.7.20 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> source /usr/local/apolloconfigdb.sql;
mysql> source /usr/local/apolloportaldb.sql;

三、创建apollo-config(以下是我在环境中已生成的服务yaml文件,可按需修改)

1、apollo-config-deployment.yaml文件

apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    deployment.kubernetes.io/revision: "2"
  creationTimestamp: "2023-04-19T08:38:44Z"
  generation: 2
  labels:
    appName: apollo
  name: apollo-config
  namespace: apollo
spec:
  progressDeadlineSeconds: 600
  replicas: 1
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      name: apollo-config
  strategy:
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
    type: RollingUpdate
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: apollo
        ccse_app_name: apollo
        name: apollo-config
        source: CCSE
    spec:
      containers:
      - env:
        - name: SPRING_DATASOURCE_URL
          value: jdbc:mysql://IP:3306/ApolloConfigDB?characterEncoding=utf8  #IP为已创建好的数据库IP
        - name: SPRING_DATASOURCE_USERNAME
          value: root
        - name: SPRING_DATASOURCE_PASSWORD
          value: ******  #数据库密码
        image: apolloconfig/apollo-configservice:latest
        imagePullPolicy: Always
        name: apollo-config
        resources:
          limits:
            cpu: "4"
            memory: 4Gi
          requests:
            cpu: 100m
            memory: 128Mi
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
        volumeMounts:
        - mountPath: /etc/localtime
          name: localtime
          readOnly: true
      dnsPolicy: ClusterFirst
      imagePullSecrets:
      - name: apollo
      nodeSelector:
        apollo: "151"
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 30
      volumes:
      - hostPath:
          path: /etc/localtime
          type: ""
        name: localtime

2、apollo-config-service.yaml文件

apiVersion: v1
kind: Service
metadata:
  creationTimestamp: "2023-04-19T08:41:39Z"
  labels:
    appName: apollo
    workloadKind: Deployment
    workloadName: apollo-config
  name: apollo-config
  namespace: apollo
spec:
  clusterIP: 10.96.69.115
  externalTrafficPolicy: Cluster
  ports:
  - name: "8080"
    nodePort: 32109
    port: 32109
    protocol: TCP
    targetPort: 8080
  selector:
    name: apollo-config
  sessionAffinity: None
  type: NodePort

四、创建apollo-admin

1、apollo-admin-deployment.yaml文件

apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    deployment.kubernetes.io/revision: "1"
  creationTimestamp: "2023-04-19T08:53:03Z"
  generation: 1
  labels:
    appName: apollo
  name: apollo-admin
  namespace: apollo
spec:
  progressDeadlineSeconds: 600
  replicas: 1
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      name: apollo-admin
  strategy:
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
    type: RollingUpdate
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: apollo
        ccse_app_name: apollo
        name: apollo-admin
        source: CCSE
    spec:
      containers:
      - env:
        - name: SPRING_DATASOURCE_URL
          value: jdbc:mysql://IP:3306/ApolloConfigDB?characterEncoding=utf8   #修改数据库地址
        - name: SPRING_DATASOURCE_USERNAME
          value: root
        - name: SPRING_DATASOURCE_PASSWORD
          value: ******    #数据库密码
        image: apolloconfig/apollo-adminservice:latest
        imagePullPolicy: Always
        name: apollo-admin
        resources:
          limits:
            cpu: "4"
            memory: 4Gi
          requests:
            cpu: 100m
            memory: 128Mi
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
        volumeMounts:
        - mountPath: /etc/localtime
          name: localtime
          readOnly: true
      dnsPolicy: ClusterFirst
      imagePullSecrets:
      - name: apollo
      nodeSelector:
        apollo: "151"
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 30
      volumes:
      - hostPath:
          path: /etc/localtime
          type: ""
        name: localtime

2、apollo-admin-service.yaml文件

apiVersion: v1
kind: Service
metadata:
  creationTimestamp: "2023-04-19T08:56:52Z"
  labels:
    appName: apollo
    workloadKind: Deployment
    workloadName: apollo-admin
  name: apollo-admin
  namespace: apollo
spec:
  clusterIP: 10.96.178.0
  externalTrafficPolicy: Cluster
  ports:
  - name: "8090"
    nodePort: 32108
    port: 32108
    protocol: TCP
    targetPort: 8090
  selector:
    name: apollo-admin
  sessionAffinity: None
  type: NodePort

五、创建apollo-portal

1、apollo-portal-deployment.yaml文件

apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    deployment.kubernetes.io/revision: "1"
  creationTimestamp: "2023-04-19T08:43:15Z"
  generation: 1
  labels:
    appName: apollo
  name: apollo-portal
  namespace: apollo
spec:
  progressDeadlineSeconds: 600
  replicas: 1
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      name: apollo-portal
  strategy:
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
    type: RollingUpdate
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: apollo
        ccse_app_name: apollo
        name: apollo-portal
        source: CCSE
    spec:
      containers:
      - env:
        - name: SPRING_DATASOURCE_URL
          value: jdbc:mysql://IP:3306/ApolloPortalDB?characterEncoding=utf8   #数据库地址
        - name: SPRING_DATASOURCE_USERNAME
          value: root
        - name: SPRING_DATASOURCE_PASSWORD
          value: ******   #数据库密码
        - name: APOLLO_PORTAL_ENVS
          value: dev
        - name: DEV_META
          value: http://10.96.69.115:32109   #apollo-config的Service Ip+NodePort端口
        image: apolloconfig/apollo-portal:latest
        imagePullPolicy: Always
        name: apollo-portal
        resources:
          limits:
            cpu: "4"
            memory: 4Gi
          requests:
            cpu: 100m
            memory: 128Mi
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
        volumeMounts:
        - mountPath: /etc/localtime
          name: localtime
          readOnly: true
      dnsPolicy: ClusterFirst
      imagePullSecrets:
      - name: apollo
      nodeSelector:
        apollo: "151"
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 30
      volumes:
      - hostPath:
          path: /etc/localtime
          type: ""
        name: localtime

2、apollo-portal-service.yaml文件

apiVersion: v1
kind: Service
metadata:
  creationTimestamp: "2023-04-19T08:55:49Z"
  labels:
    appName: apollo
    workloadKind: Deployment
    workloadName: apollo-portal
  name: apollo-portal
  namespace: apollo
spec:
  clusterIP: 10.96.210.42
  externalTrafficPolicy: Cluster
  ports:
  - name: "8070"
    nodePort: 32110
    port: 32115
    protocol: TCP
    targetPort: 8070
  selector:
    name: apollo-portal
  sessionAffinity: None
  type: NodePort

六、查看Apollo各个服务组件状态

kubectl get pods,svc,deployment -n apollo -o wide | grep apollo

pod/apollo-admin-946b849fc-t77jj                      1/1     Running            0          21h     172.26.20.166    IP   <none>           <none>
pod/apollo-config-547c79c5d6-nrdns                    1/1     Running            0          21h     172.26.20.190    IP   <none>           <none>
pod/apollo-portal-9694d748c-4mzpq                     1/1     Running            0          21h     172.26.20.182    IP   <none>           <none>
service/apollo-admin                     NodePort    10.96.178.0     <none>        32108:32108/TCP              22h     name=apollo-admin
service/apollo-config                    NodePort    10.96.69.115    <none>        32109:32109/TCP              22h     name=apollo-config
service/apollo-portal                    NodePort    10.96.210.42    <none>        32115:32110/TCP              22h     name=apollo-portal
deployment.apps/apollo-admin                        1/1     1            1           22h     apollo-admin                     apolloconfig/apollo-adminservice:latest                          name=apollo-admin
deployment.apps/apollo-config                       1/1     1            1           22h     apollo-config                    apolloconfig/apollo-configservice:latest                         name=apollo-config
deployment.apps/apollo-portal                       1/1     1            1           22h     apollo-portal                    apolloconfig/apollo-portal:latest                                name=apollo-portal

七、访问apollo,网址:http://IP:32110/

1、apollo前端页面,默认账号密码:apollo/admin

八、nginx代理配置转发

1、内网可通过nginx代理暴露服务,conf文件配置如下:

upstream nodes2.apollo-portal {
    server IP:32110;
    server IP:32110;
    server IP:32110;
    server IP:32110;
    server IP:32110;
    server IP:32110;
    server IP:32110;
    server IP:32110;
    server IP:32110;
    server IP:32110;
}   
   location / {
        proxy_pass http://nodes2.apollo-portal/;
        proxy_http_version 1.1;
        proxy_redirect off;
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header X-Forwarded-Port 80;

        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    limit_conn one 10000;
    limit_rate 40960k;

    }

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值