use*_*970 0 kubernetes amazon-eks nginx-ingress
我有一个 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
Run Code Online (Sandbox Code Playgroud)
我有一个类似的部署和服务 yaml 文件,用于部署和创建 nginx Web 服务器。我还运行了以下命令所有部署都需要以下强制命令。
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/mandatory.yaml
Run Code Online (Sandbox Code Playgroud)
和
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/provider/cloud-generic.yaml
Run Code Online (Sandbox Code Playgroud)
如该网址中所述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、replicatsets 和部署运行良好,
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
Run Code Online (Sandbox Code Playgroud)
我期待当我点击时apache.example.com- 它应该显示“它有效”并且 Nginx.example.com 应该显示“欢迎 Nginx”
我这样做对吗
浏览器 ==>ALB==>入口控制器==>ekscluster
更新 1
当我点击 url 时,我得到 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
Run Code Online (Sandbox Code Playgroud)
所以只是一个想法(我可能错过了阅读你的问题)但入口控制器不会直接路由到你的部署,它需要一个服务来路由,所以在你的情况下你必须创建一个这样的服务:
apiVersion: v1
kind: Service
metadata:
name: apache-kubernetes
spec:
selector:
app: apache-kubernetes
ports:
- protocol: TCP
port: 80
targetPort: 80
Run Code Online (Sandbox Code Playgroud)
然后,这将使用端点配置 nginx 入口以路由到您在入口中指定的位置:
...
paths:
- path: /
backend:
serviceName: apache-kubernetes
servicePort: 80
Run Code Online (Sandbox Code Playgroud)
这将指向服务而不是部署
流程(逻辑上因为 nginx 入口为更少的跳数做了一些魔法):
浏览器 ==>ALB==>ekscluster==>入口控制器==>服务==>pod
| 归档时间: |
|
| 查看次数: |
977 次 |
| 最近记录: |