marcel-dempers / docker-development-youtube-series

5.31k stars 4.09k forks source link

Kubernetes Ingress controller nginx tutorial - Unable to listen on port 80 for example services #209

Closed edebosz-inka closed 1 year ago

edebosz-inka commented 1 year ago

Hi,

I'm following ingres setup for kubernetes from: https://github.com/marcel-dempers/docker-development-youtube-series/blob/master/kubernetes/ingress/controller/nginx/README.md and after executing:

kubectl apply -f ./kubernetes/ingress/controller/nginx/features/service-a.yaml
kubectl apply -f ./kubernetes/ingress/controller/nginx/features/service-b.yaml

I get 2 pods with config maps and services but when I try to check/test service via command:

kubectl port-forward svc/service-a 80

I get an error:

$  kubectl port-forward svc/service-a 80
Unable to listen on port 80: Listeners failed to create with the following errors: [unable to create listener: Error listen tcp4 127.0.0.1:80: bind: An attempt was made to access a socket in a way forbidden by its access permissions. unable to create listener: Error listen tcp6 [::1]:80: bind: An attempt was made to access a socket in a way forbidden by its access permissions.]
error: unable to listen on any of the requested ports: [{80 80}]

service-a and service-b are deployed in default namespace. I run podman with kind on windows.

Some cluster outputs:

$ kubectl get nodes
NAME                 STATUS   ROLES                  AGE   VERSION
kind-control-plane   Ready    control-plane,master   33m   v1.23.5

$ kubectl -n ingress-nginx get pods
NAME                                        READY   STATUS      RESTARTS   AGE
ingress-nginx-admission-create-ps7b5        0/1     Completed   0          27m
ingress-nginx-admission-patch-fbdvh         0/1     Completed   0          27m
ingress-nginx-controller-7d5fb757db-4484h   1/1     Running     0          27m

$ kubectl -n ingress-nginx get svc
NAME                                 TYPE           CLUSTER-IP      EXTERNAL-IP   PORT(S)                      AGE
ingress-nginx-controller             LoadBalancer   10.96.72.32     <pending>     80:31626/TCP,443:32604/TCP   26m
ingress-nginx-controller-admission   ClusterIP      10.96.113.254   <none>        443/TCP                      26m

$ kubectl.exe -n default get pods
NAME                         READY   STATUS    RESTARTS   AGE
service-a-5958f96499-bml9h   1/1     Running   0          25m
service-b-7c4785bccb-x92qc   1/1     Running   0          25m

$ kubectl.exe -n default get svc
NAME         TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)   AGE
kubernetes   ClusterIP   10.96.0.1       <none>        443/TCP   26m
service-a    ClusterIP   10.96.40.3      <none>        80/TCP    23m
service-b    ClusterIP   10.96.136.154   <none>        80/TCP    23m

I'm missing something or something changed?

adikal25 commented 1 year ago

Try port forwarding it to 8080 port, the port 80 may be in use with the other applications

edebosz-inka commented 1 year ago

Ok, so I changed service to:

apiVersion: v1
kind: Service
metadata:
  name: service-b
spec:
  selector:
    app: service-b
  ports:
    - protocol: TCP
      port: 8080
      targetPort: 80

and then forwarded a service kubectl port-forward svc/service-a 8080 than accessed via http://localhost:8080/

Thank you for the pointer :)