I'm using docker-for-desktop (docker for mac) and have installed ingress controller
$kubectl get pods -n ingress-nginx
NAME READY STATUS RESTARTS AGE
nginx-ingress-controller-78474696b4-8vmbr 1/1 Running 0 20d
but not able to handle the traffic for a sample service. Here's a sample nginx service:
$kubectl run --image nginx webserver
$kubectl expose deploy webserver --port 80 --type NodePort
which runs as:
$kubectl get services
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 40d
webserver NodePort 10.109.250.166 <none> 80:31805/TCP 9m
and sample-ingress.yaml
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: webserver-sample
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- http:
paths:
- path: /foo
backend:
serviceName: webserver
servicePort: 80
and apply:
kubectl apply -f sample-ingress.yaml
ingress is running as:
$kubectl get ing
NAME HOSTS ADDRESS PORTS AGE
webserver-sample * localhost 80 7m
service is running as expected (which returns 200
):
curl http://localhost:31805/
but problem is I'm not able to hit http://localhost/foo
$curl http://localhost/foo
curl: (7) Failed to connect to localhost port 80: Connection refused
Any suggestion on how to debug the issue would be really be appreciated
[Update] here's the list of all services as requested by @VKR
$kubectl get svc --all-namespaces -o wide
NAMESPACE NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR
default kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 40d <none>
default webserver NodePort 10.107.135.81 <none> 80:32361/TCP 9h run=webserver
docker compose-api ClusterIP 10.108.251.142 <none> 443/TCP 40d com.docker.deploy-namespace=docker,com.docker.fry=compose.api,com.docker.image-tag=v0.4.12
ingress-nginx ingress-nginx NodePort 10.106.47.48 <none> 80:31448/TCP,443:31512/TCP 20d app.kubernetes.io/name=ingress-nginx,app.kubernetes.io/part-of=ingress-nginx
kube-system kube-dns ClusterIP 10.96.0.10 <none> 53/UDP,53/TCP 40d k8s-app=kube-dns
and also here's describe ingress:
$kubectl describe ing webserver-sample
Name: webserver-sample
Namespace: default
Address: localhost
Default backend: default-http-backend:80 (<none>)
Rules:
Host Path Backends
---- ---- --------
*
/foo webserver:80 (10.1.0.151:80)
Annotations:
kubectl.kubernetes.io/last-applied-configuration: {"apiVersion":"extensions/v1beta1","kind":"Ingress","metadata":{"annotations":{"nginx.ingress.kubernetes.io/rewrite-target":"/"},"name":"webserver-sample","namespace":"default"},"spec":{"rules":[{"http":{"paths":[{"backend":{"serviceName":"webserver","servicePort":80},"path":"/foo"}]}}]}}
nginx.ingress.kubernetes.io/rewrite-target: /
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal CREATE 9m42s nginx-ingress-controller Ingress default/webserver-sample
Normal UPDATE 9m30s nginx-ingress-controller Ingress default/webserver-sample
Just reproduced your case in Docker for Windows - for me it works fine. Tried to expose with both NodePort and ClusterIP options - result is the same - it works Below is example using ClusterIP kubectl expose deploy webserver --port 80 --type ClusterIP
PS C:\Windows\system32> kubectl get pods -n ingress-nginx
NAME READY STATUS RESTARTS AGE
nginx-ingress-controller-78474696b4-29fps 1/1 Running 0 2m
PS D:\> kubectl.exe get svc --all-namespaces
NAMESPACE NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
default kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 26m
default webserver ClusterIP 10.110.218.48 <none> 80/TCP 8m
docker compose-api ClusterIP 10.105.175.29 <none> 443/TCP 25m
ingress-nginx ingress-nginx LoadBalancer 10.101.213.113 localhost 80:31191/TCP,443:32056/TCP 19m
kube-system kube-dns ClusterIP 10.96.0.10 <none> 53/UDP,53/TCP 26m
yaml I used:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: webserver-sample
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- http:
paths:
- path: /foo
backend:
serviceName: webserver
servicePort: 80
- path: /bar
backend:
serviceName: webserver
servicePort: 80
Curl for /foo
and /bar
returns 308 Permanent Redirect
(that is expected and works by design)
PS D:\> curl http://localhost/foo
curl : 308 Permanent Redirect
nginx/1.15.10
At line:1 char:1
+ curl http://localhost/foo
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
PS D:\> curl http://localhost/bar
curl : 308 Permanent Redirect
nginx/1.15.10
At line:1 char:1
+ curl http://localhost/bar
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
Curl for /smth
returns 404
PS D:\> curl http://localhost/smth
curl : 404 Not Found
nginx/1.15.10
At line:1 char:1
+ curl http://localhost/smth
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
Try to reinstall all from scratch using latest instruction and yamls. It should work for sure