deployment.yaml
kind: Deployment
apiVersion: apps/v1
metadata:
name: deploymnt
labels:
name: deploymnt
spec:
replicas: 2
selector:
matchLabels:
hello: hi
template:
metadata:
name: deppod
labels:
hello: hi
spec:
containers:
- name: c2
image: httpd
ports:
- containerPort: 80
Service.yaml
kind: Service
apiVersion: v1
metadata:
name: demoservice
spec:
ports:
- port: 80
nodePort: 32201
selector:
name: deploymnt
type: NodePort
after applying
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
demoservice NodePort 10.105.148.95 <none> 80:32201/TCP 5h4m
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 10d
after applying both yamls and then curl:-
ubuntu@ubuntu-Lenovo-ideapad-320-15ISK:~/kubeprac$ curl 10.105.148.95:32201
curl: (7) Failed to connect to 10.105.148.95 port 32201: Connection timed out
2 Then I used the minikube's ip from local host
minikube service list
|-------------|-------------|--------------|---------------------------|
| NAMESPACE | NAME | TARGET PORT | URL |
|-------------|-------------|--------------|---------------------------|
| default | demoservice | 80 | http://192.168.49.2:32201 |
| default | kubernetes | No node port |
| kube-system | kube-dns | No node port |
|-------------|-------------|--------------|---------------------------|
ubuntu@ubuntu-Lenovo-ideapad-320-15ISK:~/kubeprac$ curl http://192.168.49.2:32201
curl: (7) Failed to connect to 192.168.49.2 port 32201: Connection refused
docker@minikube:~$ curl http://192.168.49.2:32201
curl: (7) Failed to connect to 192.168.49.2 port 32201: Connection refused
Please help !!! I am not sure what is getting wrong here. Even the selectors and label seems to be fine
Make sure your host machine allows kubernetes node ports range are allowed. You can check this by running the command below
sudo ufw status numbered | grep tcp
And you show see a line like this
30000:32767/tcp ALLOW IN Anywhere
If you don't it, run this command to add the ports range
sudo ufw allow 30000:32767/tcp
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.