首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法创建到KubeSphere的入口路由

无法创建到KubeSphere的入口路由
EN

Stack Overflow用户
提问于 2022-06-02 10:22:05
回答 1查看 225关注 0票数 1

我安装了nginx入口控制器。据我所知,使用入口的主要原因之一是通过不创建多个负载平衡器来节省费用。

我的kubesphere控制台服务yaml清单如下所示:

代码语言:javascript
复制
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

kubesphere-控制台入口路由yaml清单如下所示:

代码语言:javascript
复制
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
---

我在AKS集群上创建了入口控制器,如下所示:

代码语言:javascript
复制
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

为nginxingress创建的LB -控制器如下所示

代码语言:javascript
复制
 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

请注意,我在母校资源/网络方面不是那么出色,所以我仍然在学习。我的主要意图是使用一个入口控制器来公开所有的应用程序。

示例:

Kubesphere-控制台->端口80和端点应该是80控制台

tekton管道> 80端口和端点应该是tekton仪表板。

我真诚地感谢您的帮助。P.S:我调查了入口控制舱原木,但那里没有运气,否则我真的不明白他们的意思.

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-06-02 12:29:58

通常,如果您创建一个没有指定主机的入口,则可以通过入口控制器svc的外部IP (通配符)直接访问您的服务。您可以在正确配置DNS解析后为入口设置域名。

下面是一个通过nginx入口控制器同时公开ks-apiserverks-console的示例。

nginx控制器svc

代码语言:javascript
复制
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

ks-apiserverks-console的入口

代码语言:javascript
复制
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

确认入口

代码语言:javascript
复制
$ 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>.%
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72474611

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档