k8s上安装nacos
nacos安装
·
k8s上安装nacos
1、helm安装
wget https://get.helm.sh/helm-v3.3.4-linux-amd64.tar.gz
tart -zxvf helm-v3.3.4-linux-amd64.tar.gz
mv linux-amd64/helm /usr/local/bin/helm
helm version
vim ~/.bashrc
source <(helm completion bash)
source ~/.bashrc
#添加hellm常用库
helm repo add stable https://kubernetes-charts.storage.googleapis.com/
helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com/
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
helm repo update # Make sure we get the latest list of charts
helm repo add ali-stable https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
helm repo add harbor https://helm.goharbor.io
2、安装mysql
提前创建好pvc
helm repo add bitnami https://charts.bitnami.com/bitnami
helm pull bitnami/mysql
/root/zhanghsn/mysql
helm install -n nacos nacos-mysql bitnami/mysql --set persistence.storageClass=copaddon-nfs-public,persistence.size=3Gi
NAME: nacos-mysql
LAST DEPLOYED: Wed May 18 18:25:16 2022
NAMESPACE: nacos
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
CHART NAME: mysql
CHART VERSION: 9.0.0
APP VERSION: 8.0.29
** Please be patient while the chart is being deployed **
Tip:
Watch the deployment status using the command: kubectl get pods -w --namespace nacos
Services:
echo Primary: nacos-mysql.nacos.svc.cluster.local:3306
Execute the following to get the administrator credentials:
echo Username: root
MYSQL_ROOT_PASSWORD=$(kubectl get secret --namespace nacos nacos-mysql -o jsonpath="{.data.mysql-root-password}" | base64 --decode)
To connect to your database:
1. Run a pod that you can use as a client:
kubectl run nacos-mysql-client --rm --tty -i --restart='Never' --image docker.io/bitnami/mysql:8.0.29-debian-10-r15 --namespace nacos --env MYSQL_ROOT_PASSWORD=$MYSQL_ROOT_PASSWORD --command -- bash
2. To connect to primary service (read/write):
#修改pv策略
kubectl -n public patch pv $pv -p '{"spec":{"persistentVolumeReclaimPolicy":"Retain"}}'
获取mysql密码
[root@Paas-cce-test-primary-monitor01 mysql]# echo MYSQL_ROOT_PASSWORD=$(kubectl get secret --namespace nacos nacos-mysql -o jsonpath="{.data.mysql-root-password}" | base64 --decode)
MYSQL_ROOT_PASSWORD=djUH7IQvTN
3、下载nacs包
https://github.com/nacos-group/nacos-k8s.git
git clone https://github.com/nacos-group/nacos-k8s.git
tar -xf helm-v3.3.4-linux-amd64.tar.gz
4、安装operator
cd /root/zhanghsn/nacos-k8s-master/operator/chart
[root@Paas-cce-test-primary-monitor01 chart]# helm install -n nacos nacos-operator ./nacos-operator
WARNING: Kubernetes configuration file is group-readable. This is insecure. Location: /root/.kube/config
WARNING: Kubernetes configuration file is world-readable. This is insecure. Location: /root/.kube/config
NAME: nacos-operator
LAST DEPLOYED: Wed May 18 15:06:02 2022
NAMESPACE: nacos
STATUS: deployed
REVISION: 1
[root@Paas-cce-test-primary-monitor01 chart]# kubectl get pod -n nacos
NAME READY STATUS RESTARTS AGE
nacos-operator-6b45c79bd4-75qll 1/1 Running 0 38s
5、安装nacos
cd /root/zhanghsn/nacos-k8s-master/operator/config/samples
[root@Paas-cce-test-primary-monitor01 samples]# kubectl apply -f ./nacos_cluster_mysql.yaml
nacos.nacos.io/nacos created
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/backend-protocol: ' HTTP'
name: nacos-ingress
namespace: nacos
spec:
rules:
- host: nacos.zhanghsn.com
http:
paths:
- backend:
serviceName: nacos-headless
servicePort: 8848
path: /nacos
pathType: ImplementationSpecific
6、排错
mysql初始化失败
https://blog.csdn.net/tmaczt/article/details/124696919?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522165285601916781685368060%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fall.%2522%257D&request_id=165285601916781685368060&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~first_rank_ecpm_v1~rank_v31_ecpm-8-124696919-null-null.142^v10^pc_search_result_control_group,157^v4^control&utm_term=helm%E5%AE%89%E8%A3%85nacos&spm=1018.2226.3001.4187
解决:
现将mysql中的nacos库创建出来吗,在把sql语句导入pod,执行sql语句,重新部署nacos
cd /root/zhanghsn/nacos-k8s-master/operator/config/sql
kubectl cp ./nacos-mysql.sql -n nacos nacos-mysql-0:/op/
kubectl exec -it -n nacos nacos-mysql-0 /bin/bash
mysql -h nacos-mysql.nacos.svc.cluster.local -uroot -p"$MYSQL_ROOT_PASSWORD"
use nacose
source /op/nacos-mysql.sql
exit
cd /root/zhanghsn/nacos-k8s-master/operator/config/samples
kubectl delete -f ./nacos_cluster_mysql.yaml
kubectl apply -f ./nacos_cluster_mysql.yaml
kubectl get job -n nacos
kubectl delete job -n nacos nacos-mysql-sql-init
kubectl logs -n nacos nacos-0
看到Nacos started successfully in cluster mode. use external storage表示nacos启动成功
7、访问方式
1、nodeport
创建一个nodeport来进行访问
2、域名访问
创建一个ingress绑定对应的svc(nacos-headless)
做好域名解析
8、测试nacos
1、在nacos管理界面创建一些内容
2、进去mysql查看表中是否有数据
3、删除nacos的pod,知道重新running
4、查看mysql数据库数据是否还在
5、查看nacos界面配置是否还在
9、nacos版本查看
直接查看nacos界面即可
10、说下6中的问题
6中的问题在我的同事大神帮助下,排查到是官方的operator镜像有问题,镜像里面没有把sql文件放进去,我们自己重新做了镜像解决了这个问题,我把重新打的镜像也放上来,需要的自己下载。
更多推荐
已为社区贡献5条内容
所有评论(0)