题目要求

在namespace ingress-ckad 下,有 deployment service ingress 三个资源已经部署好了, 但是他们的配置有问题,导致的ingress 网络不通。

3个资源的配置清单在目录 /ckad/CKAD202206 中 ,请将其修改为正确的,并重新创建。

参考

https://kubernetes.io/zh-cn/docs/concepts/services-networking/ingress/

解答

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# 查看配置,进行修改
vim /ckad/CKAD202206/ingress.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-dm
namespace: ingress-ckad
spec:
replicas: 2
selector:
matchLabels:
name: nginx-ing
template:
metadata:
labels:
name: nginx-ing #标签
spec:
containers:
- name: nginx
image: vicuu/nginx:hello81
imagePullPolicy: IfNotPresent
ports:
- containerPort: 81 #容器端口
---
apiVersion: v1
kind: Service
metadata:
name: nginx-ing-svc #服务名
namespace: ingress-ckad
spec:
ports:
- port: 80 #和ingress的端口一致
targetPort: 81 #这个端口需要和deployment的containerPort值一致
protocol: TCP
selector:
name: nginx-ing #修改标签 和deployment的一致

---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: nginx-ingress-test
namespace: ingress-ckad
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
ingressClassName: nginx-example123
rules:
- http:
paths:
- path: /hello
pathType: Prefix
backend:
service:
name: nginx-ing-svc #需要和service的服务名一致
port:
number: 80 # 需要和service的port的值一致

# 应用配置,测试验证
kubectl apply -f /ckad/CKAD202206/ingress.yaml
curl 10.106.76.153
curl 10.102.130.182/hello