Нет порта прослушивания на узле подчиненного узла при предоставлении сервиса через kubectl - PullRequest
1 голос
/ 17 июня 2019

Я настраиваю кластер kubernetes, имеющий один главный узел (физический miniPC, работающий под управлением сервера Ubuntu 18.04) и один подчиненный узел (ноутбук, работающий под управлением ubuntu 16.04).

Docker - это контейнерЯ использую совместно с kubernetes.

Я запускаю демонстрационное приложение через

kubectl run hello-world --image=gcr.io/google-samples/hello-app:1.0  --port 8080

и выставляю его через

kubectl expose deployment hello-world --port=8080 --target-port=8080

Приложение запускается на подчиненном узле

alecu@slave-node:~$ sudo docker ps
CONTAINER ID        IMAGE                  COMMAND                  CREATED             STATUS              PORTS               NAMES
91967f160a7c        bc5c421ecd6c           "./hello-app"            About an hour ago   Up About an hour                        k8s_hello-world_hello-world-5bcc568dd9-xktwg_default_875609f4-90d0-11e9-9940-7cd30a0da72f_0

И я могу получить к нему доступ изнутри контейнера

alecu@slave-node:~$ sudo nsenter -t 21075 -n curl http://localhost:8080
Hello, world!
Version: 1.0.0
Hostname: hello-world-6899bf7846-t5pb7

Но когда я пытаюсь получить доступ к нему извне контейнера, я получаю отказ в соединении:

alecu@slave-node:~$ curl http://localhost:8080
curl: (7) Failed to connect to localhost port 8080: Connection refused

netstat не показывает порт 8080

alecu@slave-node:~$ netstat -tnlp | grep 8080

curl также не работает с master-узла

alecu@master-node:~$ kubectl describe service hello-world
Name:              hello-world
Namespace:         default
Labels:            <none>
Annotations:       <none>
Selector:          run=hello-world
Type:              ClusterIP
IP:                10.100.48.99
Port:              <unset>  8080/TCP
TargetPort:        8080/TCP
Endpoints:         192.168.1.18:8080
Session Affinity:  None
Events:            <none>

alecu@master-node:~$ curl -v http://192.168.1.18:8080
* Rebuilt URL to: http://192.168.1.18:8080/
*   Trying 192.168.1.18...
* TCP_NODELAY set
^C
alecu@master-node:~$ curl -v http://10.100.48.99:8080
* Rebuilt URL to: http://10.100.48.99:8080/
*   Trying 10.100.48.99...
* TCP_NODELAY set
^C
alecu@master-node:~$

Я ctrl + c'ed команда curl, поскольку она бесконечно ждала.

Я не понимаю, почему на подчиненном узле порт 8080 не открыт.

[EDIT] Я исправил службу для использования NodePort

 kubectl patch svc hello-world --type='json' -p '[{"op":"replace","path":"/spec/type","value":"NodePort"}]'

, ноcurl тоже не работает на http://nodeIP:nodePort

alecu@master-node:~$ kubectl describe svc hello-world
Name:                     hello-world
Namespace:                default
Labels:                   run=hello-world
Annotations:              <none>
Selector:                 run=hello-world
Type:                     NodePort
IP:                       10.100.171.36
Port:                     <unset>  8080/TCP
TargetPort:               8080/TCP
NodePort:                 <unset>  30988/TCP
Endpoints:                192.168.1.21:8080
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   <none>
alecu@master-node:~$ curl -v http://10.100.171.36:30988
* Rebuilt URL to: http://10.100.171.36:30988/
*   Trying 10.100.171.36...
* TCP_NODELAY set
^C

Ответы [ 2 ]

1 голос
/ 17 июня 2019

обновить тип сервиса до NodePort. тогда вы сможете получить доступ к приложению извне, используя http://NODEIP:NODEPORT Или используйте clusterIP для доступа к приложению из кластера.

получить команду clusterIP снизу

kubectl get svc

см. Инструкции ниже

master $ kubectl run hello-world --image=gcr.io/google-samples/hello-app:1.0  --port 8080
deployment.apps/hello-world created
master $
master $ kubectl expose deployment hello-world --port=8080 --target-port=8080
service/hello-world exposed
master $
master $ kubectl get svc
NAME          TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)         AGE
hello-world   ClusterIP   10.104.172.60   <none>        8080/TCP        4s
kube-dns      ClusterIP   10.96.0.10      <none>        53/UDP,53/TCP   1h
master $
master $ curl 10.104.172.60:8080
Hello, world!
Version: 1.0.0
Hostname: hello-world-6654767c49-r2mnz
0 голосов
/ 17 июня 2019

Я обнаружил проблему.

Я использовал два неисправных сетевых модуля, которые были указаны во множественном курсе.

https://docs.projectcalico.org/v3.3/getting-started/kubernetes/installation/hosted/rbac-kdd.yaml
https://docs.projectcalico.org/v3.3/getting-started/kubernetes/installation/hosted/kubernetes-datastore/calico-networking/1.7/calico.yaml

После применения этих двух модулей невозможно установить соединение ни с одним веб-сайтом, ни с кластером.

Я заменил их на фланель в качестве сетевого модуля, и все работает нормально.

https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...