我有一个eks集群,我的部署,服务和loadBalancer都可以正常工作。每个服务都创建自己的LoadBalancer,所有服务都已启动并正在运行。我有一个前端服务和2个后端服务 这是我的部署和入口文件
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: apache-kubernetes
spec:
replicas: 2
selector:
matchLabels:
app: apache-kubernetes
template:
metadata:
labels:
app: apache-kubernetes
spec:
containers:
- name: apache-kubernetes
image: httpd
ports:
- containerPort: 80
env:
- name: MESSAGE
value: Hello Kubernetes!
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: hello-apache-ingress
annotations:
kubernetes.io/ingress.class: "nginx"
spec:
rules:
- host: apache.example.com
- http:
paths:
- path: /
backend:
serviceName: apache-kubernetes
servicePort: 80
我有一个类似的部署和服务yaml文件,用于部署和创建nginx Web服务器。我还运行了以下命令 所有部署都需要以下强制性命令。
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/mandatory.yaml
和
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/provider/cloud-generic.yaml
如该网址https://kubernetes.github.io/ingress-nginx/deploy/#aws
中所述然后我运行这两个命令
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/provider/aws/service-l4.yaml
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/provider/aws/patch-configmap-l4.yaml
我运行kubectl get all
,我看到自己的Pod,副本集和部署运行正常
kubectl get ingress shows
hosts ADDRESS
apache.example.com 216990309c-1626238635.us-east-2.elb.amazonaws.com
nginx.example.com 216990309c-1626238635.us-east-2.elb.amazonaws.com
我期望当我点击apache.example.com
时,它应该显示“有效”
和Nginx.example.com应该显示“ welcome Nginx”
我做对了
浏览器==> ALB ==> ingresscontroller ==> ekscluster
更新1
当我点击网址时,我得到503,但吊舱正在运行
kubectl -n ingress-nginx记录nginx-ingress-controller-db5f9d7b5-cwwh2
给我
6 controller.go:781] Error obtaining Endpoints for Service "default/hello-kubernetes": no object matching key "default/hello-kubernetes" in local store
W0911 23:43:02.505451 6 controller.go:781] Error obtaining Endpoints for Service "default/nginx-kubernetes": no object matching key "default/nginx-kubernetes" in local store
W0911 23:43:20.846517 6 controller.go:781] Error obtaining Endpoints for Service "default/hello-kubernetes": no object matching key "default/hello-kubernetes" in local store
W0911 23:43:20.846540 6 controller.go:781] Error obtaining Endpoints for Service "default/nginx-kubernetes": no object matching key "default/nginx-kubernetes" in local store
答案 0 :(得分:4)
所以只是一个想法(我可能会错过阅读您的问题),但是入口控制器不会直接路由到您的部署,它需要一个服务进行路由,因此在您的情况下,您必须创建一个服务像这样:
apiVersion: v1
kind: Service
metadata:
name: apache-kubernetes
spec:
selector:
app: apache-kubernetes
ports:
- protocol: TCP
port: 80
targetPort: 80
这将为nginx入口配置要路由到的端点,在入口中您指定以下位置:
...
paths:
- path: /
backend:
serviceName: apache-kubernetes
servicePort: 80
这将指向服务而不是部署
流(从逻辑上讲,nginx入口为减少跳数做了一些魔术):
浏览器==> ALB ==> ekscluster ==> ingresscontroller ==> service ==> pod