nacos服务在Kubernetes体系中,默认使用headless service。
如下是资源状态。
[root@VM-99-6-centos ~]# kubectl get svc nacos-headless
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
nacos-headless ClusterIP None <none> 8848/TCP,9848/TCP,9849/TCP,7848/TCP 17d
[root@VM-99-6-centos ~]# kubectl get sts
NAME READY AGE
nacos 3/3 17d
[root@VM-99-6-centos ~]# kubectl get pods -l app=nacos
NAME READY STATUS RESTARTS AGE
nacos-0 2/2 Running 0 17d
nacos-1 2/2 Running 0 17d
nacos-2 2/2 Running 0 17d
[root@VM-99-6-centos ~]# kubectl get ep nacos-headless
NAME ENDPOINTS AGE
nacos-headless 172.16.0.10:9848,172.16.0.135:9848,172.16.0.73:9848 + 9 more... 17d
外网怎么访问管理页面呢?
一、将 nacos-headless service 通过负载均衡映射到外网
kubectl expose service nacos-headless --type=LoadBalancer --name=nacos-external-lb
[root@VM-99-6-centos ~]# kubectl get svc nacos-external-lb
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
nacos-external-lb LoadBalancer 172.16.252.122 175.24.252.49 8848:31795/TCP,9848:30213/TCP,9849:30320/TCP,7848:30044/TCP 48m
二、仅将8848端口通过负载均衡映射到外网
kubectl expose svc nacos-headless --name=nacos-external --type=LoadBalancer --port=8848 --target-port=8848
[root@VM-99-6-centos ~]# kubectl get svc nacos-external
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
nacos-external LoadBalancer 172.16.254.50 175.24.254.201 8848:30291/TCP 38s
[root@VM-99-6-centos ~]# kubectl describe svc nacos-external
Name: nacos-external
Namespace: default
Labels: app=nacos-headless
Annotations: service.kubernetes.io/loadbalance-id: lb-696gr02t
Selector: app=nacos
Type: LoadBalancer
IP Families: <none>
IP: 172.16.254.50
IPs: <none>
LoadBalancer Ingress: 175.24.254.201
Port: <unset> 8848/TCP
TargetPort: 8848/TCP
NodePort: <unset> 30291/TCP
Endpoints: 172.16.0.10:8848,172.16.0.135:8848,172.16.0.73:8848
Session Affinity: None
External Traffic Policy: Cluster
Events: <none>
网友评论