Kubernetes安装 Apollo 电脑版发表于:2022/10/21 22:53 ![Kubernetes](https://img.tnblog.net/arcimg/hb/274ef6f115de4c9b8e40ded5deb2f4c2.jpg "Kubernetes") >#Kubernetes安装 Apollo [TOC] tn2>首先安装存储。 ## Centos 安装nfs ```bash systemctl stop firewalld systemctl disable firewalld yum install -y nfs-common nfs-utils mkdir /nfsdata chmod 666 /nfsdata vi /etc/exports /nfsdata *(rw,async) exportfs -rv systemctl start rpcbind systemctl start nfs systemctl enable rpcbind.service nfs showmount -e yum install -y nfs-utils ``` ### Ubuntu 安装nfs ```bash apt-get install nfs-kernel-server -y sudo ufw disable mkdir /nfsdata chmod 666 /nfsdata echo "/nfsdata *(async,insecure,no_root_squash,no_subtree_check,rw)" > /etc/exports cat /etc/exports /etc/init.d/nfs-kernel-server restart showmount -e ``` ### k8s工作节点安装nfs ```bash apt install nfs-common -y yum install -y nfs-utils ``` ### 安装NFS Storage ```bash wget https://github.com/kubernetes-sigs/nfs-subdir-external-provisioner/releases/download/nfs-subdir-external-provisioner-4.0.16/nfs-subdir-external-provisioner-4.0.16.tgz #解压 tar -xvf nfs-subdir-external-provisioner-4.0.16.tgz cd nfs-subdir-external-provisioner ifconfig vim values.yaml ``` ![](https://img.tnblog.net/arcimg/hb/02631e48735c4765ad552f8907a39d99.png) ```bash kubectl create ns nfs helm install nfs-subdir-external-provisioner . -n nfs kubectl patch storageclass nfs-client -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}' ``` ## 安装Mysql ```bash helm repo add my-repo https://charts.bitnami.com/bitnami kubectl create ns mysql helm install my-release \ --set auth.rootPassword=bob \ --set auth.username=bob \ --set auth.password=bob \ -n mysql \ my-repo/mysql MYSQL_ROOT_PASSWORD=$(kubectl get secret --namespace mysql my-release-mysql -o jsonpath="{.data.mysql-root-password}" | base64 -d) echo $MYSQL_ROOT_PASSWORD ``` ## Apollo ```bash helm repo add apollo https://charts.apolloconfig.com helm search repo apollo kubectl create ns apollo ``` ```bash mkdir -p /root/apollo/apollo-service/ && cd /root/apollo/apollo-service/ # 拉取 chart 到本地 /root/apollo/apollo-service/ 目录 helm pull apollo/apollo-service --version 0.5.1 tar -zxvf apollo-service-0.5.1.tgz cp apollo-service/values.yaml ./values-test.yaml # 查看当前目录层级 tree -L 2 . ├── apollo-service │ ├── Chart.yaml │ ├── templates │ └── values.yaml ├── apollo-service-xxx.tgz └── values-test.yaml ``` ### 创建数据库 ```bash # 获取数据库初始化语句 # https://github.com/apolloconfig/apollo/blob/master/scripts/sql/apolloconfigdb.sql # https://raw.githubusercontent.com/apolloconfig/apollo/master/scripts/sql/apolloconfigdb.sql wget https://raw.githubusercontent.com/apolloconfig/apollo/master/scripts/sql/apolloconfigdb.sql -O /tmp/apolloconfigdb.sql cat /tmp/apolloconfigdb.sql kubectl cp /tmp/apolloconfigdb.sql mysql/my-release-mysql-0:/tmp/apolloconfigdb.sql kubectl exec -n mysql -it pod/my-release-mysql-0 /bin/bash # 连接部署好的 Mysql 数据,创建 apollo 账户和数据库 mysql -uroot -p # 或 mysql -h mysql_host -u root -p root123 mysql > create database ApolloConfigDB default character set utf8mb4 collate utf8mb4_unicode_ci; mysql > create user 'apollo'@'%' identified by 'apollo'; mysql > grant all on ApolloConfigDB.* to 'apollo'@'%'; # 老版本 mysql > grant all on ApolloConfigDB.* to 'bob'@'%' identified by 'bob'; # 执行数据库初始化语句 mysql > source /tmp/apolloconfigdb.sql; ``` ```bash vim values-test.yaml configdb: name: apollo-configdb host: "my-release-mysql.mysql" port: 3306 dbName: ApolloConfigDB userName: "apollo" password: "apollo" ``` ```bash helm -n apollo install apollo-service apollo-service -f values-test.yaml | tee test.log helm -n apollo list ``` ## 安装 apollo-portal ```bash helm repo add apollo https://www.apolloconfig.com/charts/ helm repo update helm search repo apollo-portal mkdir -p /root/apollo/apollo-portal/ && cd /root/apollo/apollo-portal/ # 拉取 chart 到本地 /root/apollo/apollo-portal/ 目录 helm pull apollo/apollo-portal --version 0.5.1 tar -zxvf apollo-portal-0.5.1.tgz cp apollo-portal/values.yaml ./values-test.yaml # 查看当前目录层级 tree -L 2 . ├── apollo-portal │ ├── Chart.yaml │ ├── templates │ └── values.yaml ├── apollo-portal-0.5.1.tgz └── values-test.yaml ``` ```bash # 获取数据库初始化语句 # https://github.com/apolloconfig/apollo/blob/master/scripts/sql/apolloportaldb.sql # https://raw.githubusercontent.com/apolloconfig/apollo/master/scripts/sql/apolloportaldb.sql wget https://raw.githubusercontent.com/apolloconfig/apollo/master/scripts/sql/apolloportaldb.sql -O /tmp/apolloportaldb.sql kubectl cp /tmp/apolloportaldb.sql mysql/my-release-mysql-0:/tmp/apolloportaldb.sql kubectl exec -n mysql -it pod/my-release-mysql-0 /bin/bash # 连接部署好的 Mysql 数据,创建 apollo 账户和数据库 mysql -uroot -p mysql > create database ApolloPortalDB default character set utf8mb4 collate utf8mb4_unicode_ci; mysql > grant all on ApolloPortalDB.* to 'apollo'@'%'; # 执行数据库初始化语句 mysql > source /tmp/apolloportaldb.sql exit exit ``` ```bash vim values-test.yaml ``` ```bash cat values-test.yaml name: apollo-portal fullNameOverride: "apollo-portal" replicaCount: 1 containerPort: 8070 # SVC 配置 service: fullNameOverride: "" port: 8070 targetPort: 8070 type: ClusterIP sessionAffinity: ClientIP # ingress 配置,方便集群外访问 ingress: enabled: true annotations: {} hosts: - host: "apollo.evescn.com" paths: [/] tls: [] nodeSelector: {} # 配置定义,定义当前 apollo 的环境以及对应环境的 configservice 地址,支持配置多个环境,网络上可以访问即可, dev,fat,uat,prod 参数 config: envs: fat metaServers: fat: http://apollo-configservice.apollo:8080 # 服务对应外部数据库地址信息 portaldb: name: apollo-portaldb # apolloportaldb host host: "my-release-mysql.mysql" port: 3306 dbName: ApolloPortalDB userName: apollo password: apollo ``` ```bash helm -n apollo install apollo-portal apollo-portal -f values-test.yaml | tee test.log helm -n apollo list ``` ```bash export POD_NAME=$(kubectl get pods --namespace apollo -l "app=apollo-portal" -o jsonpath="{.items[0].metadata.name}") echo "Visit http://0.0.0.0:8070 to use your application" kubectl --address 0.0.0.0 --namespace apollo port-forward $POD_NAME 8070:8070 ``` tn2>账号和密码就是:apollo/admin ![](https://img.tnblog.net/arcimg/hb/68a1af65f9e3446eb478217c8fdb5454.png) ![](https://img.tnblog.net/arcimg/hb/ae15f4eae2dc447db438395534b3b8fe.png)