Home > Net >  Unable to create ingress route to KubeSphere
Unable to create ingress route to KubeSphere

Time:06-03

I have installed nginx ingress controller. As I understand that one of the main reasons to use ingress is to save money by not creating multiple load balancers.

My kubesphere-console service yaml manifest looks like below:

cat kubesphere-console.yaml 
apiVersion: v1
kind: Service
metadata:
  annotations:
    meta.helm.sh/release-name: ks-core
    meta.helm.sh/release-namespace: kubesphere-system
  creationTimestamp: "2022-05-30T04:51:22Z"
  finalizers:
  - service.kubernetes.io/load-balancer-cleanup
  labels:
    app: ks-console
    app.kubernetes.io/managed-by: Helm
    tier: frontend
    version: v3.1.0
  name: ks-console
  namespace: kubesphere-system
  resourceVersion: "785863"
  uid: 8628c2d0-164b-499f-ac0c-254ac77aa48c
spec:
  allocateLoadBalancerNodePorts: true
  clusterIP: 10.0.29.29
  clusterIPs:
  - 10.0.29.29
  externalTrafficPolicy: Cluster
  internalTrafficPolicy: Cluster
  ipFamilies:
  - IPv4
  ipFamilyPolicy: SingleStack
  ports:
  - name: nginx
    nodePort: 30880
    port: 80
    protocol: TCP
    targetPort: 8000
  selector:
    app: ks-console
    tier: frontend
  sessionAffinity: None
  type: LoadBalancer
status:
  loadBalancer:
    ingress:
    - ip: 20.248.217.111

The kubesphere-console ingress route yaml manifest is like below:

cat ingress-route-kubesphere.yaml 
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: kubesphere-console
  annotations:
    nginx.ingress.kubernetes.io/ssl-redirect: "false"
    nginx.ingress.kubernetes.io/use-regex: "true"
    nginx.ingress.kubernetes.io/rewrite-target: /$2
spec:
  ingressClassName: nginx
  rules:
  - http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: ks-console
            port:
              number: 80
      - path: /(.*)
        pathType: Prefix
        backend:
          service:
            name: ks-console
            port:
              number: 80
---

I created ingress-controller on AKS cluster as like below:

NAMESPACE=ingress-basic

helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
helm repo update

helm install ingress-nginx ingress-nginx/ingress-nginx \
  --create-namespace \
  --namespace $NAMESPACE \
  --set controller.service.annotations."service\.beta\.kubernetes\.io/azure-load-balancer-health-probe-request-path"=/healthz

LB created for nginxingress-controller as like below

 k get svc -ningress-basic
NAME                                 TYPE           CLUSTER-IP    EXTERNAL-IP    PORT(S)                      AGE
ingress-nginx-controller             LoadBalancer   10.0.194.38   20.92.133.79   80:32703/TCP,443:31053/TCP   23h
ingress-nginx-controller-admission   ClusterIP      10.0.189.8    <none>         443/TCP                      23h

Kindly do note that I am not that great in Ingress resource/networking so I am still learning. My main intention is use one ingress controller to expose all applications

Example:

Kubesphere-console --> Port 80 and Endpoint should be ksconsole

tekton-pipelines ----> Port 80 and Endpoint should be tekton-dashboard

I shall sincerely appreciate any help. P.S: I investigated the ingress control pod logs but no luck there or I really don't what they mean....

k logs -f ingress-nginx-controller-6648b5dbb8-ntm8t -ningress-basic

10.240.0.4 - - [02/Jun/2022:12:29:42  0000] "GET /healthz HTTP/1.1" 302 43 "-" "Load Balancer Agent" 194 0.002 [kubesphere-system-ks-console-80] [] 10.240.0.41:8000 43 0.000 302 6ea21ca50e247cc5d5e56975c8946fcc
10.240.0.4 - - [02/Jun/2022:12:29:42  0000] "GET /healthz HTTP/1.1" 302 43 "-" "Load Balancer Agent" 194 0.003 [kubesphere-system-ks-console-80] [] 10.240.0.41:8000 43 0.004 302 1f2e1bfa0223e6b3b630a59fe7dba4d1
10.240.0.4 - - [02/Jun/2022:12:29:48  0000] "GET /healthz HTTP/1.1" 302 43 "-" "Load Balancer Agent" 194 0.004 [kubesphere-system-ks-console-80] [] 10.240.0.41:8000 43 0.000 302 dbb5af0fd6426f783c337da06912e427
10.240.0.4 - - [02/Jun/2022:12:29:48  0000] "GET /healthz HTTP/1.1" 302 43 "-" "Load Balancer Agent" 194 0.003 [kubesphere-system-ks-console-80] [] 10.240.0.41:8000 43 0.004 302 9fc084018c70c0f61f379e2266a056f8
10.240.0.4 - - [02/Jun/2022:12:29:54  0000] "GET /healthz HTTP/1.1" 302 43 "-" "Load Balancer Agent" 194 0.003 [kubesphere-system-ks-console-80] [] 10.240.0.41:8000 43 0.004 302 f9e4c75d81aa0e7ff03e402dfdca2d35
10.240.0.4 - - [02/Jun/2022:12:29:54  0000] "GET /healthz HTTP/1.1" 302 43 "-" "Load Balancer Agent" 194 0.003 [kubesphere-system-ks-console-80] [] 10.240.0.41:8000 43 0.000 302 187cc1fdb0fb1499c1ef040e8aeb5e01
10.240.0.4 - - [02/Jun/2022:12:30:00  0000] "GET /healthz HTTP/1.1" 302 43 "-" "Load Balancer Agent" 194 0.003 [kubesphere-system-ks-console-80] [] 10.240.0.41:8000 43 0.004 302 9b3b1ae4165184ed16fa974be51cd460
10.240.0.4 - - [02/Jun/2022:12:30:00  0000] "GET /healthz HTTP/1.1" 302 43 "-" "Load Balancer Agent" 194 0.003 [kubesphere-system-ks-console-80] [] 10.240.0.41:8000 43 0.004 302 eac2591d333af20ab1a3ee4052327291
10.240.0.4 - - [02/Jun/2022:12:30:06  0000] "GET /healthz HTTP/1.1" 302 43 "-" "Load Balancer Agent" 194 0.004 [kubesphere-system-ks-console-80] [] 10.240.0.41:8000 43 0.000 302 f08f30018bcfd229adb1ed36b6473563
10.240.0.4 - - [02/Jun/2022:12:30:06  0000] "GET /healthz HTTP/1.1" 302 43 "-" "Load Balancer Agent" 194 0.002 [kubesphere-system-ks-console-80] [] 10.240.0.41:8000 43 0.000 302 f157141e253c7fcc61008440ff047605
10.240.0.4 - - [02/Jun/2022:12:30:12  0000] "GET /healthz HTTP/1.1" 302 43 "-" "Load Balancer Agent" 194 0.003 [kubesphere-system-ks-console-80] [] 10.240.0.41:8000 43 0.004 302 6ba07067e1345b665e16a3cab03ee50c
10.240.0.4 - - [02/Jun/2022:12:30:12  0000] "GET /healthz HTTP/1.1" 302 43 "-" "Load Balancer Agent" 194 0.003 [kubesphere-system-ks-console-80] [] 10.240.0.41:8000 43 0.004 302 4978c44153381d1aac6bc959c4afa72d
10.240.0.4 - - [02/Jun/2022:12:30:18  0000] "GET /healthz HTTP/1.1" 302 43 "-" "Load Balancer Agent" 194 0.003 [kubesphere-system-ks-console-80] [] 10.240.0.41:8000 43 0.004 302 fc1e6e7fd4f4219ef6ca38689275035a
10.240.0.4 - - [02/Jun/2022:12:30:18  0000] "GET /healthz HTTP/1.1" 302 43 "-" "Load Balancer Agent" 194 0.003 [kubesphere-system-ks-console-80] [] 10.240.0.41:8000 43 0.000 302 1e286ef7a2b36a5b04521e59657e0433

CodePudding user response:

Usually, you can access your services directly through the external IP (wildcard) of the ingress-controller svc if you create an ingress without a specified host. You can set a domain name for the ingress after configuring DNS resolution correctly.

Here is an example of exposing both ks-apiserver and ks-console through nginx-ingress-controller.

nginx controller svc

root@master:~# kubectl -n ingress-nginx get svc
NAME                                 TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)                      AGE
ingress-nginx-controller             NodePort    10.233.11.24    <none>        80:30882/TCP,443:31054/TCP   15m
ingress-nginx-controller-admission   ClusterIP   10.233.18.191   <none>        443/TCP                      37m

ingress of ks-apiserver and ks-console

root@master:~# kubectl -n kubesphere-system get ing api -o yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    kubesphere.io/creator: admin
  creationTimestamp: "2022-06-02T08:48:48Z"
  generation: 8
  name: kubesphere
  namespace: kubesphere-system
  resourceVersion: "982261"
  uid: f8f6cadf-874c-4996-8759-3467ac33d61c
spec:
  ingressClassName: nginx
  rules:
  - host: api.172.31.50.170.nip.io
    http:
      paths:
      - backend:
          service:
            name: ks-apiserver
            port:
              number: 80
        path: /
        pathType: ImplementationSpecific
  - host: console.172.31.50.170.nip.io
    http:
      paths:
      - backend:
          service:
            name: ks-console
            port:
              number: 80
        path: /
        pathType: ImplementationSpecific
status:
  loadBalancer:
    ingress:
    - ip: 172.31.50.170

Verify the ingresses

$ curl http://api.172.31.50.170.nip.io:30882/
{
  "kind": "Status",
  "apiVersion": "v1",
  "metadata": {

  },
  "status": "Failure",
  "message": "forbidden: User \"system:anonymous\" cannot GET path \"/\"",
  "reason": "Forbidden",
  "details": {

  },
  "code": 403
}%
$ curl http://console.172.31.50.170.nip.io:30882/
Redirecting to <a href="/login">/login</a>.%
  • Related