首页 > 解决方案 > LoadBalancer 类型的 Kubernetes 入口未按预期工作

问题描述

我在 kubernetes 集群中安装了Kubernetes NGINX Ingress 。当我试图通过入口控制器访问微服务端时,它没有按预期工作

我正在 AWS Instance 上进行部署,我遵循了此处的文档

我有两个 Spring Boot 应用程序,其上下文路径为/customer在端口 9000 上运行,/prac 在端口 8000 上运行,第三个是 nginx 在端口 80 上运行

我已经执行了这些命令来创建类型 LoadBalancer 的入口控制器

kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/nginx-0.30.0/deploy/static/mandatory.yaml

kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/nginx-0.30.0/deploy/static/provider/aws/service-l4.yaml
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/nginx-0.30.0/deploy/static/provider/aws/patch-configmap-l4.yaml

豆荚运行

NAMESPACE       NAME                                        READY   STATUS    RESTARTS   AGE     IP              NODE               NOMINATED NODE   READINESS GATES
ingress-nginx   nginx-ingress-controller-7f74f657bd-rh5fj   1/1     Running   0          23h     10.32.0.10      ip-172-31-11-145   <none>           <none>
kube-system     coredns-6955765f44-8wkwl                    1/1     Running   0          2d23h   10.32.0.3       ip-172-31-11-145   <none>           <none>
kube-system     coredns-6955765f44-w79bh                    1/1     Running   0          2d23h   10.32.0.2       ip-172-31-11-145   <none>           <none>
kube-system     etcd-ip-172-31-11-145                       1/1     Running   0          2d23h   172.31.11.145   ip-172-31-11-145   <none>           <none>
kube-system     kube-apiserver-ip-172-31-11-145             1/1     Running   0          2d23h   172.31.11.145   ip-172-31-11-145   <none>           <none>
kube-system     kube-controller-manager-ip-172-31-11-145    1/1     Running   0          2d23h   172.31.11.145   ip-172-31-11-145   <none>           <none>
kube-system     kube-proxy-6ktz2                            1/1     Running   0          2d23h   172.31.34.24    ip-172-31-34-24    <none>           <none>
kube-system     kube-proxy-mrlt6                            1/1     Running   0          2d23h   172.31.11.145   ip-172-31-11-145   <none>           <none>
kube-system     kube-scheduler-ip-172-31-11-145             1/1     Running   0          2d23h   172.31.11.145   ip-172-31-11-145   <none>           <none>
kube-system     weave-net-5bmvb                             2/2     Running   0          2d23h   172.31.11.145   ip-172-31-11-145   <none>           <none>
kube-system     weave-net-gl7xz                             2/2     Running   1          2d23h   172.31.34.24    ip-172-31-34-24    <none>           <none>
practice        customer-6d467cbc57-q6l6h                   1/1     Running   0          46h     10.32.0.8       ip-172-31-11-145   <none>           <none>
practice        customer-6d467cbc57-rx7zt                   1/1     Running   0          46h     10.32.0.5       ip-172-31-11-145   <none>           <none>
practice        ngtest-6c5ff8c7df-lmbhz                     1/1     Running   0          45h     10.44.0.1       ip-172-31-34-24    <none>           <none>
practice        ngtest-6c5ff8c7df-pvv4w                     1/1     Running   0          45h     10.32.0.9       ip-172-31-11-145   <none>           <none>
practice        prac-865d49687b-q8hss                       1/1     Running   0          23h     10.32.0.11      ip-172-31-11-145   <none>           <none>
practice        prac-865d49687b-wxkxr                       1/1     Running   0          23h     10.44.0.2       ip-172-31-34-24    <none>           <none>
practice        some-mysql-7896cfbb4c-kgnxf                 1/1     Running   0          46h     10.32.0.7       ip-172-31-11-145   <none>           <none>

服务运行

NAMESPACE       NAME               TYPE           CLUSTER-IP      EXTERNAL-IP     PORT(S)                      AGE
default         kubernetes         ClusterIP      10.96.0.1       <none>          443/TCP                      2d23h
ingress-nginx   ingress-nginx      LoadBalancer   10.110.197.3    18.221.167.75   80:32414/TCP,443:31112/TCP   23h
kube-system     kube-dns           ClusterIP      10.96.0.10      <none>          53/UDP,53/TCP,9153/TCP       2d23h
practice        customer-service   ClusterIP      10.106.14.223   <none>          9090/TCP                     46h
practice        ngtest             ClusterIP      10.109.249.63   <none>          80/TCP                       45h
practice        prac-service       ClusterIP      10.110.96.199   <none>          8000/TCP                     46h
practice        some-mysql         ClusterIP      None            <none>          3306/TCP                     46h

安装 ingress nginx 后,我创建了 Loadbalancer 类型的入口控制器。

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: practice-ingress
  namespace: practice
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec: 
  rules:
  - host: kdhut.com
    http: 
      paths:
      - backend:
          serviceName: customer-service
          servicePort: 9090
        path: /customer
      - backend:
          serviceName: prac-service
          servicePort: 8000
        path: /prac
      - backend:
          serviceName: ngtest
          servicePort: 80
        path: /

我创建了 Classic Load Balancer,但负载均衡器运行状况检查未通过,运行状况检查我指向端口 80,但它显示已停止服务。

在此处输入图像描述

我试图检查集群 IP,但它显示来自服务器的空响应,请帮助我。

root@ip-172-31-11-145:/home/ubuntu# kubectl get svc --all-namespaces
NAMESPACE       NAME               TYPE           CLUSTER-IP      EXTERNAL-IP     PORT(S)                      AGE
default         kubernetes         ClusterIP      10.96.0.1       <none>          443/TCP                      2d23h
ingress-nginx   ingress-nginx      LoadBalancer   10.110.197.3    18.221.167.75   80:32414/TCP,443:31112/TCP   23h
kube-system     kube-dns           ClusterIP      10.96.0.10      <none>          53/UDP,53/TCP,9153/TCP       2d23h
practice        customer-service   ClusterIP      10.106.14.223   <none>          9090/TCP                     46h
practice        ngtest             ClusterIP      10.109.249.63   <none>          80/TCP                       46h
practice        prac-service       ClusterIP      10.110.96.199   <none>          8000/TCP                     46h
practice        some-mysql         ClusterIP      None            <none>          3306/TCP                     46h
root@ip-172-31-11-145:/home/ubuntu#
root@ip-172-31-11-145:/home/ubuntu#
root@ip-172-31-11-145:/home/ubuntu#
root@ip-172-31-11-145:/home/ubuntu# curl http://10.110.197.3/
curl: (52) Empty reply from server
root@ip-172-31-11-145:/home/ubuntu# curl http://10.110.197.3/prac/
curl: (52) Empty reply from server
root@ip-172-31-11-145:/home/ubuntu#

标签: spring-bootdockernginxkuberneteskubernetes-ingress

解决方案


推荐阅读