0

我正在尝试将 Kong Ingress Controller 部署到我在 virtualbox 中使用 kubeadm 部署的 K8s 集群中。

它由一个主节点和两个工作节点组成。

根据文档,我正在使用 DBless 部署:

kubectl apply -f https://raw.githubusercontent.com/Kong/kubernetes-ingress-controller/master/deploy/single/all-in-one-dbless.yaml

结果是这样的:

namespace/kong created
customresourcedefinition.apiextensions.k8s.io/kongclusterplugins.configuration.konghq.com created
customresourcedefinition.apiextensions.k8s.io/kongconsumers.configuration.konghq.com created
customresourcedefinition.apiextensions.k8s.io/kongingresses.configuration.konghq.com created
customresourcedefinition.apiextensions.k8s.io/kongplugins.configuration.konghq.com created
customresourcedefinition.apiextensions.k8s.io/tcpingresses.configuration.konghq.com created
customresourcedefinition.apiextensions.k8s.io/udpingresses.configuration.konghq.com created
serviceaccount/kong-serviceaccount created
role.rbac.authorization.k8s.io/kong-leader-election created
clusterrole.rbac.authorization.k8s.io/kong-ingress created
rolebinding.rbac.authorization.k8s.io/kong-leader-election created
clusterrolebinding.rbac.authorization.k8s.io/kong-ingress created
service/kong-proxy created
service/kong-validation-webhook created
deployment.apps/ingress-kong created

到目前为止,一切都很好。以下是它创建的组件:

NAME                                READY   STATUS    RESTARTS        AGE
pod/ingress-kong-7498964bb6-ddbfw   2/2     Running   2 (7m37s ago)   7m41s

NAME                              TYPE           CLUSTER-IP      EXTERNAL-IP   PORT(S)                      AGE
service/kong-proxy                LoadBalancer   10.110.24.254   <pending>     80:31345/TCP,443:31076/TCP   7m41s
service/kong-validation-webhook   ClusterIP      10.108.43.162   <none>        443/TCP                      7m41s

NAME                           READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/ingress-kong   1/1     1            1           7m41s

NAME                                      DESIRED   CURRENT   READY   AGE
replicaset.apps/ingress-kong-7498964bb6   1         1         1       7m41s

我正在使用端口转发公开负载均衡器:

kubectl port-forward svc/kong-proxy -n kong 80:80

然后我 curl http://localhost 结果如预期:

curl : {"message":"no Route matched with those values"}

最后,我部署了一组入口规则来测试它:

apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    app: nginx
  name: nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  strategy: {}
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - image: nginx:alpine
        name: nginx
        ports:
        - containerPort: 80
        resources: {}
status: {}
---
apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    app: httpd
  name: httpd
spec:
  replicas: 1
  selector:
    matchLabels:
      app: httpd
  strategy: {}
  template:
    metadata:
      labels:
        app: httpd
    spec:
      containers:
      - image: httpd:alpine
        name: httpd
        ports:
        - containerPort: 80
        resources: {}
status: {}
---
apiVersion: v1
kind: Service
metadata:
  creationTimestamp: null
  labels:
    app: nginx
  name: nginx-service
spec:
  ports:
  - port: 80
    protocol: TCP
    targetPort: 80
  selector:
    app: nginx
  type: ClusterIP
status:
  loadBalancer: {}
---
apiVersion: v1
kind: Service
metadata:
  creationTimestamp: null
  labels:
    app: httpd
  name: httpd-service
spec:
  ports:
  - port: 80
    protocol: TCP
    targetPort: 80
  selector:
    app: httpd
  type: ClusterIP
status:
  loadBalancer: {}
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    konghq.com/strip-path: "true"
  name: nginx-ingress
spec:
  ingressClassName: kong
  rules:
  - http:
      paths:
      - backend:
          service:
            name: nginx-service
            port:
              number: 80
        path: /nginx
        pathType: Prefix
status:
  loadBalancer: {}
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    konghq.com/strip-path: "true"
  name: httpd-ingress
spec:
  ingressClassName: kong
  rules:
  - http:
      paths:
      - backend:
          service:
            name: httpd-service
            port:
              number: 80
        path: /httpd
        pathType: Prefix

例如,当我尝试 curl 在我的入口规则中定义的任何路径时,curl http://localhost/httpd它会引发此错误:

curl : An invalid response was received from the upstream server

kong 代理的日志显示此错误:

[error] 1097#0: *6474 connect() failed (113: Host is unreachable) while connecting to upstream, client: 127.0.0.1, server: kong, request: "GET /httpd HTTP/1.1", upstream: "http://10.88.0.58:80/", host: "localhost"

当我列出端点时显示 IP:

httpd-service   10.88.0.58:80       14m
nginx-service   10.88.0.59:80       14m

两种服务(httpd-service 和 nginx-service)都是正确的,当我将它们的服务移植到我的本地机器时,我可以访问它们。

我在 DigitalOcean 上的另一个集群中进行了相同的部署,除了配置负载平衡器之外,结果几乎相同。

谁可以帮我这个事?

谢谢!

4

0 回答 0