ᕕ( ᐛ )ᕗ Jimyag's Blog

K8s 使用 ingress 反向代理外部 ip

创建 endpoints,endpoints.yaml

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
apiVersion: v1
kind: Endpoints
metadata:
  name: test-endpoint
  namespace: test
subsets:
- addresses:
  - ip: 192.168.2.1
  ports:
  - name: port
    port: 8088
    protocol: TCP

创建 service, service.yaml

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
apiVersion: v1
kind: Service
metadata:
  name: test-service
  namespace: test
spec:
  type: ClusterIP
  ports:
  - name: port
    port: 80
    protocol: TCP
    targetPort: 80

创建 ingress , ingress.yaml

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
apiVersion: v1
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: test-ingress
  namespace: test
spec:
  ingressClassName: nginx
  rules:
  - host: test.jimyag.com
    http:
      paths:
      - backend:
          service:
            name: test-service
            port:
              number: 80
        path: /
        pathType: ImplementationSpecific

执行命令

1
2
3
4
5
6
# 创建
kubectl apply -f ingress.yaml,endpoints.yaml,service.yaml
# 查看
kubectl get ingress test-ingress -n test
# 查看详情
kubectl describe ingress test-ingress -n test

#K8s