K8s 使用 ingress 反向代理外部 ip
创建 endpoints,endpoints.yaml
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
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
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
执行命令
# 创建
kubectl apply -f ingress.yaml,endpoints.yaml,service.yaml
# 查看
kubectl get ingress test-ingress -n test
# 查看详情
kubectl describe ingress test-ingress -n test