Tôi đã tạo một cụm K8 gồm 5 máy ảo (1 bậc thầy và 4 nô lệ chạy Ubuntu 16.04.3 LTS) sử dụng kubeadm
. Tôi đã sử dụng flannel
để thiết lập mạng trong cụm. Tôi đã có thể triển khai thành công một ứng dụng. Tôi, sau đó, tiếp xúc với nó thông qua dịch vụ NodePort. Từ đây mọi thứ trở nên phức tạp đối với tôi.Dịch vụ NodePort của K8s là “không thể truy cập bằng IP” chỉ trên 2/4 nô lệ trong cụm
Trước khi tôi bắt đầu, tôi đã tắt dịch vụ firewalld
mặc định trên chính và các nút.
Khi tôi hiểu từ K8s Services doc, loại NodePort hiển thị dịch vụ trên tất cả các nút trong cụm. Tuy nhiên, khi tôi tạo ra nó, dịch vụ chỉ được hiển thị trên 2 nút trong số 4 nút trong cụm. Tôi đoán đó không phải là hành vi mong đợi (phải không?)
Để gỡ rối, đây là một số thông số kỹ thuật tài nguyên:
[email protected]:~# kubectl get nodes
NAME STATUS AGE VERSION
vm-deepejai-00b Ready 5m v1.7.3
vm-plashkar-006 Ready 4d v1.7.3
vm-rosnthom-00f Ready 4d v1.7.3
vm-vivekse-003 Ready 4d v1.7.3 //the master
vm-vivekse-004 Ready 16h v1.7.3
[email protected]:~# kubectl get pods -o wide -n playground
NAME READY STATUS RESTARTS AGE IP NODE
kubernetes-bootcamp-2457653786-9qk80 1/1 Running 0 2d 10.244.3.6 vm-rosnthom-00f
springboot-helloworld-2842952983-rw0gc 1/1 Running 0 1d 10.244.3.7 vm-rosnthom-00f
[email protected]:~# kubectl get svc -o wide -n playground
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR
sb-hw-svc 10.101.180.19 <nodes> 9000:30847/TCP 5h run=springboot-helloworld
[email protected]:~# kubectl describe svc sb-hw-svc -n playground
Name: sb-hw-svc
Namespace: playground
Labels: <none>
Annotations: <none>
Selector: run=springboot-helloworld
Type: NodePort
IP: 10.101.180.19
Port: <unset> 9000/TCP
NodePort: <unset> 30847/TCP
Endpoints: 10.244.3.7:9000
Session Affinity: None
Events: <none>
[email protected]:~# kubectl get endpoints sb-hw-svc -n playground -o yaml
apiVersion: v1
kind: Endpoints
metadata:
creationTimestamp: 2017-08-09T06:28:06Z
name: sb-hw-svc
namespace: playground
resourceVersion: "588958"
selfLink: /api/v1/namespaces/playground/endpoints/sb-hw-svc
uid: e76d9cc1-7ccb-11e7-bc6a-fa163efaba6b
subsets:
- addresses:
- ip: 10.244.3.7
nodeName: vm-rosnthom-00f
targetRef:
kind: Pod
name: springboot-helloworld-2842952983-rw0gc
namespace: playground
resourceVersion: "473859"
uid: 16d9db68-7c1a-11e7-bc6a-fa163efaba6b
ports:
- port: 9000
protocol: TCP
Sau một số phiên bản tôi nhận ra rằng trên những 2 nút "bị lỗi", những dịch vụ không có sẵn từ bên trong các máy chủ đó.
node01 (làm việc):
[email protected]:~# curl 127.0.0.1:30847 //<localhost>:<nodeport>
Hello Docker World!!
[email protected]:~# curl 10.101.180.19:9000 //<cluster-ip>:<port>
Hello Docker World!!
[email protected]:~# curl 10.244.3.7:9000 //<pod-ip>:<port>
Hello Docker World!!
node02 (làm việc):
[email protected]:~# curl 127.0.0.1:30847
Hello Docker World!!
[email protected]:~# curl 10.101.180.19:9000
Hello Docker World!!
[email protected]:~# curl 10.244.3.7:9000
Hello Docker World!!
Node03 (không hoạt động):
[email protected]:~# curl 127.0.0.1:30847
curl: (7) Failed to connect to 127.0.0.1 port 30847: Connection timed out
[email protected]:~# curl 10.101.180.19:9000
curl: (7) Failed to connect to 10.101.180.19 port 9000: Connection timed out
[email protected]:~# curl 10.244.3.7:9000
curl: (7) Failed to connect to 10.244.3.7 port 9000: Connection timed out
Node04 (không hoạt động):
[email protected]:/# curl 127.0.0.1:30847
curl: (7) Failed to connect to 127.0.0.1 port 30847: Connection timed out
[email protected]:/# curl 10.101.180.19:9000
curl: (7) Failed to connect to 10.101.180.19 port 9000: Connection timed out
[email protected]:/# curl 10.244.3.7:9000
curl: (7) Failed to connect to 10.244.3.7 port 9000: Connection timed out
Đã thử netstat
và telnet
trên tất cả 4 nô lệ. Dưới đây là kết quả:
node01 (host làm việc):
[email protected]:~# netstat -tulpn | grep 30847
tcp6 0 0 :::30847 :::* LISTEN 27808/kube-proxy
[email protected]:~# telnet 127.0.0.1 30847
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
node02 (host làm việc):
[email protected]:~# netstat -tulpn | grep 30847
tcp6 0 0 :::30847 :::* LISTEN 11842/kube-proxy
[email protected]:~# telnet 127.0.0.1 30847
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
Node03 (host không làm việc):
[email protected]:~# netstat -tulpn | grep 30847
tcp6 0 0 :::30847 :::* LISTEN 7791/kube-proxy
[email protected]:~# telnet 127.0.0.1 30847
Trying 127.0.0.1...
telnet: Unable to connect to remote host: Connection timed out
Node04 (máy chủ không hoạt động):
[email protected]:/# netstat -tulpn | grep 30847
tcp6 0 0 :::30847 :::* LISTEN 689/kube-proxy
[email protected]:/# telnet 127.0.0.1 30847
Trying 127.0.0.1...
telnet: Unable to connect to remote host: Connection timed out
thông tin bổ sung:
Từ kubectl get pods
đầu ra, tôi có thể thấy rằng các pod được thực sự triển khai trên nô lệ vm-rosnthom-00f
. Tôi có thể ping
máy chủ lưu trữ này từ tất cả 5 máy ảo và curl vm-rosnthom-00f:30847
cũng hoạt động với tất cả các máy ảo.
Tôi có thể thấy rõ ràng rằng mạng cụm nội bộ bị hỏng, nhưng tôi không chắc chắn cách giải quyết! iptables -L
cho tất cả các nô lệ là giống hệt nhau, và thậm chí cả Loopback địa phương (ifconfig lo
) là lên và chạy cho tất cả các nô lệ. Tôi hoàn toàn không biết gì về cách sửa nó!
Chỉ cần xác nhận, địa chỉ IP của tất cả các giao diện không có dock có một không gian IP riêng biệt hơn docker, pods và dịch vụ không? Lệnh tôi muốn xem là 'root @ vm-deepejai-00b:/# curl THE_IP_OF_vm-vivekse-004: 30847' để đảm bảo' vm-deepejai-00b' có thể định tuyến lưu lượng truy cập đến 'vm-vivekse-004' , bởi vì đó là những gì đang xảy ra dưới vỏ bọc anyway –
Ngoài ra, chỉ cần cho cực rõ ràng, bạn đã kiểm tra 'iptables -t nat-L' cũng như chỉ' iptables -L' (Tôi không thể nói nếu đó là những gì bạn có nghĩa là) –
@MatthewLDaniel Đối với bình luận đầu tiên của bạn, curl hoạt động: 'root @ vm-deepejai-00b: ~ # curl 173.36.23.4:30847 Xin chào Docker World !! ' trong đó 173.36.23.4 là địa chỉ IP của vm- vivekse-004 –