7、七层负载-Ingress应用
1. 考题内容:
2. 答题思路:
1、要先查到集群中使用的ingressclass
2、编写yaml
我考的题只是把 hi 服务换成了 hello,其他都一模一样
3. 官网地址:
https://kubernetes.io/zh-cn/docs/concepts/services-networking/ingress/
4. 考题答案:
切换环境
kubectl config use-tontext k8s
# 1).查看ingressclass名称
kubectl get ingressclass
# 2).编写ping.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ping
namespace: ing-internal
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
ingressClassName: nginx #注意:我查到的ingressclass名称为nginx
rules:
- http:
paths:
- path: /hi
pathType: Prefix
backend:
service:
name: hi
port:
number: 5678
# 3).创建ping.yaml
kubectl apply -f ping.yaml
5. 验证
# 1).查看创建的ingress
kubectl get ingress -n ing-internal
# 2).curl验证ingress
curl -kL <INTERNAL_IP>/hi #INTERNAL_IP为第三步中查到的ip