alibaba / kt-connect

A toolkit for Integrating with your kubernetes dev environment more efficiently
https://alibaba.github.io/kt-connect/#/
GNU General Public License v3.0
1.48k stars 230 forks source link

启动 ktctl 成功后,可以根据IP访问k8s集群中的 pod。但是无法访问 service 。 #430

Closed thousmile closed 1 year ago

thousmile commented 1 year ago

这是启动 ktctl connect 成功的截图

QQ截图20230505154953

通过 pod ip 可以访问成功 (黄色部分) 通过 Ingress 反向代理也是可以访问

但是通过 service 的 IP 或者 名称。无法访问。(红色部分)

QQ截图20230505154910

在k8s集群中,任意一个pod中也是可以通过 service 的 IP 或者 名称 访问 QQ截图20230505154731

下面是k8s部署的yaml

################## hello deployment ##################
apiVersion: apps/v1
kind: Deployment
metadata:
  name: hello-nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app: hello-nginx
  template:
    metadata:
      labels:
        app: hello-nginx
    spec:
      containers:
        - name: nginx
          image: nginx:1.24.0
          ports:
            - containerPort: 80

---
################## hello Service ##################
apiVersion: v1
kind: Service
metadata:
  name: hello-nginx
  labels:
    app: hello-nginx
spec:
  type: ClusterIP
  selector:
    app: hello-nginx
  ports:
    - port: 80
      targetPort: 80

---
################## ingress myapp ##################
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: hello-nginx
  labels:
    app: hello-nginx
spec:
  ingressClassName: nginx
  rules:
    - host: hello.example.com
      http:
        paths:
          - path: "/"
            pathType: Prefix
            backend:
              service:
                name: hello-nginx
                port:
                  number: 80