租外国服务器做的网站要备案吗/广东全网推广
因为楼主更改了apollo源码,所以需要重新打包,然后在制作镜像。
1.docker部署Apollo
1. 打包
可以参考上文。
2.制作镜像
1.获取zip包
分别获取打包之后zip包,在/apollo-portal/target/,apollo-adminservice/target/,apollo-configservice/target/中。
2.获取dockerflie
分别在apollo-portal,apollo-adminservice,apollo-configservice中获取dockerflie。
3.将以上两个文件分别放于任意文件夹中并分别执行
docker build -t apollo-portal .
docker build -t apollo-adminservice .
docker build -t apollo-configservice .
3.运行容器
在虚拟机中执行以下命令即可。
adminconfig
docker run -d -p 8090:8090 --net=host -e SPRING_DATASOURCE_URL="jdbc:postgresql://ip:5432/apolloconfig?characterEncoding=utf8" -e SPRING_DATASOURCE_USERNAME=apolloconfig -e SPRING_DATASOURCE_PASSWORD=123 -d -v /tmp/logs:/opt/logs --name apollo-adminservice apollo-adminserviceSPRING_DATASOURCE_URL: 对应环境ApolloConfigDB的地址
SPRING_DATASOURCE_USERNAME: 对应环境ApolloConfigDB的用户名
SPRING_DATASOURCE_PASSWORD: 对应环境ApolloConfigDB的密码
--name apollo-adminservice apollo-adminservice:为镜像同名 下面同理apollo-configservice
docker run -p 8080:8080 --net=host -e SPRING_DATASOURCE_URL="jdbc:postgresql://ip:5432/apolloconfig?characterEncoding=utf8" -e SPRING_DATASOURCE_USERNAME=apolloconfig -e SPRING_DATASOURCE_PASSWORD=123 -d -v /tmp/logs:/opt/logs --name apollo-configservice apollo-configserviceSPRING_DATASOURCE_URL: 对应环境ApolloConfigDB的地址
SPRING_DATASOURCE_USERNAME: 对应环境ApolloConfigDB的用户名
SPRING_DATASOURCE_PASSWORD: 对应环境ApolloConfigDB的密码apollo-portal
docker run -p 8070:8070 --net=host -e SPRING_DATASOURCE_URL="jdbc:postgresql://ip:5432/apolloportal" -e SPRING_DATASOURCE_USERNAME=apolloportal -e SPRING_DATASOURCE_PASSWORD=123 -e APOLLO_PORTAL_ENVS=dev -e DEV_META=http://localhost:8080 -d -v /tmp/logs:/opt/logs --name apollo-portal apollo-portalSPRING_DATASOURCE_URL: 对应环境ApolloPortalDB的地址
SPRING_DATASOURCE_USERNAME: 对应环境ApolloPortalDB的用户名
SPRING_DATASOURCE_PASSWORD: 对应环境ApolloPortalDB的密码
APOLLO_PORTAL_ENVS(可选): 对应ApolloPortalDB中的apollo.portal.envs配置项,如果没有在数据库中配置的话,可以通过此环境参数配置
DEV_META/PRO_META(可选): 配置对应环境的Meta Service地址,以${ENV}_META命名,需要注意的是如果配置了ApolloPortalDB中的apollo.portal.meta.servers配置,则以apollo.portal.meta.servers中的配置为准
如没有定制数据库需求,可以参考官方文档
https://github.com/ctripcorp/apollo/wiki/%E5%88%86%E5%B8%83%E5%BC%8F%E9%83%A8%E7%BD%B2%E6%8C%87%E5%8D%97#2-apolloportalmetaservers—%E5%90%84%E7%8E%AF%E5%A2%83meta-service%E5%88%97%E8%A1%A8
2.k8s部署Apollo
书接上文 楼主定制了oracle版本的apollo,那么怎么使用k8s部署呢,本文只部署dev环境,使用yaml文件在Kubernetes-dashboard部署。
如果有对Kubernetes-dashboard不熟悉的,可以参考k8s专栏 。
1.部署apollo-admin
---
apiVersion: v1
kind: ConfigMap
metadata:namespace: apollo #更改自己的namespacename: configmap-apollo-admin-server
data:application-github.properties: |spring.datasource.url = jdbc:postgresql://ip:5432/apolloconfig?characterEncoding=utf8spring.datasource.username = apolloconfigspring.datasource.password = 123eureka.service.url = ip:5001/eureka
---
apiVersion: v1
kind: Service
metadata:namespace: apolloname: service-apollo-admin-serverlabels:app: service-apollo-admin-server
spec:ports:- protocol: TCPport: 8090nodePort: 8090selector:app: pod-apollo-admin-servertype: NodePort
---
apiVersion: apps/v1
kind: Deployment
metadata:namespace: apolloname: deployment-apollo-admin-serverlabels:app: deployment-apollo-admin-server
spec:replicas: 1selector:matchLabels:app: pod-apollo-admin-serverstrategy:rollingUpdate:maxSurge: 1maxUnavailable: 1type: RollingUpdatetemplate:metadata:labels:app: pod-apollo-admin-serverspec:volumes:- name: volume-configmap-apollo-admin-serverconfigMap:name: configmap-apollo-admin-serveritems:- key: application-github.propertiespath: application-github.propertiescontainers:- image: ip:9000/apollo/apollo-adminservice:latest #镜像地址 楼主这里使用了私人仓库securityContext:privileged: trueimagePullPolicy: IfNotPresentname: container-apollo-admin-serverports:- protocol: TCPcontainerPort: 8090volumeMounts:- name: volume-configmap-apollo-admin-servermountPath: /apollo-admin-server/config/application-github.propertiessubPath: application-github.propertiesenv:- name: APOLLO_ADMIN_SERVICE_NAMEvalue: "service-apollo-admin-server.sre"readinessProbe:tcpSocket:port: 8090initialDelaySeconds: 10periodSeconds: 5livenessProbe:tcpSocket:port: 8090initialDelaySeconds: 120periodSeconds: 10dnsPolicy: ClusterFirstrestartPolicy: AlwaysnodeName: apollo #指定的nodes节点
2.部署apollo-config
---
kind: ConfigMap
apiVersion: v1
metadata:namespace: apollo #更改自己的namespacename: configmap-apollo-config-server
data:application-github.properties: |spring.datasource.url = jdbc:postgresql://ip:5432/apolloconfig?characterEncoding=utf8spring.datasource.username = apolloconfigspring.datasource.password = 123eureka.service.url = ip:5001/eureka
---
kind: Service
apiVersion: v1
metadata:namespace: apolloname: service-apollo-meta-serverlabels:app: service-apollo-meta-server
spec:ports:- protocol: TCPport: 8080targetPort: 8080selector:app: pod-apollo-config-servertype: ClusterIPclusterIP: NonesessionAffinity: ClientIP
---
kind: Service
apiVersion: v1
metadata:namespace: apolloname: service-apollo-config-serverlabels:app: service-apollo-config-server
spec:ports:- protocol: TCPport: 8080targetPort: 8080nodePort: 8080selector:app: pod-apollo-config-servertype: NodePortsessionAffinity: ClientIP
---
kind: StatefulSet
apiVersion: apps/v1
metadata:namespace: apolloname: statefulset-apollo-config-serverlabels:app: statefulset-apollo-config-server
spec:serviceName: service-apollo-meta-serverreplicas: 1selector:matchLabels:app: pod-apollo-config-serverupdateStrategy:type: RollingUpdatetemplate:metadata:labels:app: pod-apollo-config-serverspec:volumes:- name: volume-configmap-apollo-config-serverconfigMap:name: configmap-apollo-config-serveritems:- key: application-github.propertiespath: application-github.propertiescontainers:- image: ip:9000/apollo/apollo-configservice:latest #私人仓库securityContext:privileged: trueimagePullPolicy: IfNotPresentname: container-apollo-config-serverports:- protocol: TCPcontainerPort: 8080volumeMounts:- name: volume-configmap-apollo-config-servermountPath: /apollo-config-server/config/application-github.propertiessubPath: application-github.propertiesenv:- name: APOLLO_CONFIG_SERVICE_NAMEvalue: "service-apollo-config-server.sre"readinessProbe:tcpSocket:port: 8080initialDelaySeconds: 10periodSeconds: 5livenessProbe:tcpSocket:port: 8080initialDelaySeconds: 120periodSeconds: 10dnsPolicy: ClusterFirstrestartPolicy: AlwaysnodeName: apollo #nodes节点名称
3.apollo-portal
---
kind: ConfigMap
apiVersion: v1
metadata:namespace: apolloname: configmap-apollo-portal-server
data:application-github.properties: |spring.datasource.url = jdbc:postgresql://ip:5432/apolloportalspring.datasource.username = apolloportalspring.datasource.password = 123apollo-env.properties: |dev.meta=http://ip:8080 #上文的apollo-config 切记不用写localhost
---
kind: Service
apiVersion: v1
metadata:namespace: apolloname: service-apollo-portal-serverlabels:app: service-apollo-portal-server
spec:ports:- protocol: TCPport: 8070targetPort: 8070nodePort: 8070selector:app: pod-apollo-portal-servertype: NodePortsessionAffinity: ClientIP
---
kind: Deployment
apiVersion: apps/v1
metadata:namespace: apolloname: deployment-apollo-portal-serverlabels:app: deployment-apollo-portal-server
spec:replicas: 1selector:matchLabels:app: pod-apollo-portal-serverstrategy:rollingUpdate:maxSurge: 1maxUnavailable: 1type: RollingUpdatetemplate:metadata:labels:app: pod-apollo-portal-serverspec:volumes:- name: volume-configmap-apollo-portal-serverconfigMap:name: configmap-apollo-portal-serveritems:- key: application-github.propertiespath: application-github.properties- key: apollo-env.propertiespath: apollo-env.propertiescontainers:- image: ip:9000/apollo/apollo-portal:latest #私人仓库securityContext:privileged: trueimagePullPolicy: IfNotPresentname: container-apollo-portal-serverports:- protocol: TCPcontainerPort: 8070volumeMounts:- name: volume-configmap-apollo-portal-servermountPath: /apollo-portal-server/config/application-github.propertiessubPath: application-github.properties- name: volume-configmap-apollo-portal-servermountPath: /apollo-portal-server/config/apollo-env.propertiessubPath: apollo-env.propertiesenv:- name: APOLLO_PORTAL_SERVICE_NAMEvalue: "service-apollo-portal-server.sre"readinessProbe:tcpSocket:port: 8070initialDelaySeconds: 10periodSeconds: 5livenessProbe:tcpSocket:port: 8070initialDelaySeconds: 120periodSeconds: 15dnsPolicy: ClusterFirstrestartPolicy: AlwaysnodeName: apollo #nodes地址
注意:以上yaml 一定注意格式,比如空行,空格,注释,能去掉一定去掉,否则会报各种错误。
注意 ,以下apollo-portal.zip中的配置也需要修改(否则一直会访问localhost)