如果是在centos7上直接启动nacos
注意修改启动命令 sh startup.sh -m standalone
访问路径 http://********:8848/nacos/index.html
https://nacos.io/zh-cn/docs/use-nacos-with-kubernetes.html?tdsourcetag=s_pctim_aiomsg
1. 安装git 并在每台机器上面clone nacos-k8s
yum install nfs-utils
yum install -y git
git clone https://github.com/nacos-group/nacos-k8s.git
2. 部署NFS
a 创建角色
cd /root/nacos-k8s/deploy/nf
[root@master nfs]# kubectl create -f rbac.yaml clusterrole.rbac.authorization.k8s.io/nfs-client-provisioner-runner created clusterrolebinding.rbac.authorization.k8s.io/run-nfs-client-provisioner created role.rbac.authorization.k8s.io/leader-locking-nfs-client-provisioner created rolebinding.rbac.authorization.k8s.io/leader-locking-nfs-client-provisioner created
b 创建 ServiceAccount
和部署 NFS-Client Provisioner 如果挂载失败参考下一篇挂载方式
[root@master nfs]# kubectl create -f deployment.yaml serviceaccount/nfs-client-provisioner created deployment.extensions/nfs-client-provisioner created
c 创建 NFS StorageClass
[root@master nfs]# kubectl create -f class.yaml storageclass.storage.k8s.io/managed-nfs-storage created
d 验证NFS部署成功
[root@master nfs]# kubectl get pod -l app=nfs-client-provisioner NAME READY STATUS RESTARTS AGE nfs-client-provisioner-7f468b4bb6-qlr7g 1/1 Running 0 21m
3.1 部署数据库 通过本地方式
由于nfs阿里埋了很多坑,只有用本地创建
部署主库
kubectl apply -f mysql-master-local.yaml
部署从库
kubectl apply -f mysql-slave-local.yaml
从库要修改部分配置不然报错
service
工作模式:
1.11之后 ipvs 1.10 iptables 1.10之前 userspace
type:
ClusterIP 集群内部通讯 NodePort 集群外部通讯
ports:
port service上面的端口
targetPort pod上面的端口
nodePort 集群外部被访问的端口 只有当type等于NodePort才生效
资源记录:
SVC_NAME.NS_NAME.DOMAIN.LTD
查看pod的详细信息
kubectl get svc
kubectl describe svc 名称
访问顺序 service-> endPoints-> pod
定义一个能被外部访问的pod
apiVersion: v1
kind: Service
metadata:
name: myapp
namespace: default
spec:
selector:
app: myapp
release: canary
clusterIP: 10.99.99.99
type: NodePort
ports:
port: 80
targetPort: 80
nodePort: 30055 #如果不指定会动态分配
外部访问方式
while true;do curl http://ip:30055/hostname.html; sleep 1; done
apiVersion: v1 kind: ReplicationController metadata: name: mysql-slave labels: name: mysql-slave spec: replicas: 1 selector: #关联到那个pod上面,name就是pod的名字在 name: mysql-slave template: metadata: labels: name: mysql-slave spec: containers: - name: slave image: nacos/nacos-mysql-slave:latest ports: - containerPort: 3306 volumeMounts: - name: mysql-slave-data mountPath: /var/lib/mysql1 env: - name: MYSQL_ROOT_PASSWORD value: "root" - name: MYSQL_REPLICATION_USER value: 'nacos_ru' - name: MYSQL_REPLICATION_PASSWORD value: 'nacos_ru' volumes: - name: mysql-slave-data hostPath: path: /var/lib/mysql1 --- apiVersion: v1 #核心容器 kind: Service metadata: name: mysql-slave labels: name: mysql-slave spec: ports: - port: 3306 targetPort: 3306 selector: name: mysql-slave
3.2 部署数据库 通过nfs
部署主库
kubectl apply -f mysql-master-nfs.yaml
部署从库 挂载到另外一台服务器
4. 部署nacos
kubectl apply -f nacos-quick-start.yaml
查看标签
kubectl get pods -L app,run --show tables
5. 外部
查看我们创建的服务
[root@master nacos]# kubectl get service NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 2d1h mysql-master ClusterIP 10.107.47.155 <none> 3306/TCP 27m mysql-slave ClusterIP 10.105.236.228 <none> 3306/TCP 14m nacos-headless ClusterIP 10.97.251.211 <none> 8848/TCP 11m
所有评论(0)