[英]Ingress controller not handling the traffic
I'm using docker-for-desktop (docker for mac) and have installed ingress controller 我正在使用docker-for-desktop(docker for mac)并安装了入口控制器
$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:
这是一个示例nginx服务:
$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
和
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: ingress正在运行:
$kubectl get ing
NAME HOSTS ADDRESS PORTS AGE
webserver-sample * localhost 80 7m
service is running as expected (which returns 200
): 服务正在按预期运行(返回
200
):
curl http://localhost:31805/
but problem is I'm not able to hit http://localhost/foo
但问题是我无法点击
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 [更新]这里是@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. 刚刚在Docker for Windows中复制了你的案例 - 对我来说它运行正常。 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
尝试使用NodePort和ClusterIP选项公开 - 结果是相同的 - 它的工作原理下面是使用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: 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
- path: /bar
backend:
serviceName: webserver
servicePort: 80
Curl for /foo
and /bar
returns 308 Permanent Redirect
(that is expected and works by design) /foo
和/bar
卷曲返回308 Permanent Redirect
(预期并按设计工作)
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
/smth
卷曲返回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. 尝试使用最新指令和yamls从头开始重新安装。 It should work for sure
它应该是肯定的
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.