题目
Create a new nginx ingress resource as follows:
- Name:pong
- Namespace:ing-internal
- Exposing service hi on path /hi using service port 5678
The availability of service hi can be checked using the following command,which should return hi
答案
官网:Kubernetes 文档/概念/服务、负载均衡和联网/Ingress
https://kubernetes.io/zh/docs/concepts/services-networking/ingress/
Ingress 公开了从集群外部到集群内服务的 HTTP 和 HTTPS 路由。 流量路由由 Ingress 资源上定义的规则控制。
#ingress
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: pong
namespace: ing-internal
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- http:
paths:
- path: /hi
pathType: Prefix
backend:
service:
name: hi
port:
number: 5678
拓展
要使用ingress需要为k8s集群安装一个ingress控制器,这里采用 Nginx Ingress 控制器
#使用yaml
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.1.2/deploy/static/provider/cloud/deploy.yaml