我是Kubernetes中Ingress的新手。我在AKS集群中安装了Ingress NGINX控制器。我的应用程序在testns(命名空间(中的pod(端口80(中运行。我在同一个命名空间中为它创建了一个服务。现在我想从外部访问我的应用程序。所以我为它创建了一个Ingress yaml。
服务.yaml
kubectl get svc -A | grep my-svc
testns my-svc ClusterIP 10.0.116.192 <none> 80/TCP 93m
进入
Name: example-ingress
Namespace: testns
Address:
Default backend: default-http-backend:80 (<error: endpoints "default-http-backend" not found>)
Rules:
Host Path Backends
---- ---- --------
*
/apple my-svc:80 (10.244.1.33:80)
Annotations: ingress.kubernetes.io/rewrite-target: /
Events: <none>
入口.yaml
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: example-ingress
annotations:
ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- http:
paths:
- path: /apple
backend:
serviceName: my-svc
servicePort: 80
当我使用<IP_ADDRESS_OF_THE_INGRESS>apple,则会给出404错误。我想知道为什么应用程序无法访问。
尝试将入口类添加到YAML配置kubernetes.io/ingress.class: "nginx"
中
作为注释
kubernetes.io/ingress.class: "nginx"
nginx.ingress.kubernetes.io/rewrite-target: /
示例
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: example-ingress
annotations:
kubernetes.io/ingress.class: "nginx"
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- http:
paths:
- path: /apple
backend:
serviceName: my-svc
servicePort: 80