我正在使用docker-for-desktop(适用于Mac的docker)并已安装入口控制器
$kubectl get pods -n ingress-nginx
NAME READY STATUS RESTARTS AGE
nginx-ingress-controller-78474696b4-8vmbr 1/1 Running 0 20d
,但无法处理示例服务的流量。 这是一个示例nginx服务:
$kubectl run --image nginx webserver
$kubectl expose deploy webserver --port 80 --type NodePort
其运行方式为:
$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
和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
并申请:
kubectl apply -f sample-ingress.yaml
ingress运行方式为:
$kubectl get ing
NAME HOSTS ADDRESS PORTS AGE
webserver-sample * localhost 80 7m
服务正在按预期运行(返回200
):
curl http://localhost:31805/
但是问题是我无法打http://localhost/foo
$curl http://localhost/foo
curl: (7) Failed to connect to localhost port 80: Connection refused
任何有关如何调试该问题的建议将不胜感激
[更新]这是@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
,这里也描述了入口:
$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
答案 0 :(得分:0)
仅在Windows的Docker中复制了您的案例-对我来说它运行良好。
尝试使用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:
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
/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
/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
尝试使用最新说明和Yamls从头开始重新安装所有程序。它应该可以正常工作