Kubernetes 中使用 Ingress 时的访问链路

本篇博客记录了在使用 Kubernetes 的 Ingress 时,应用的访问链路,这可以为应用访问不通时排查问题提供帮助。

部署应用及 Ingress

使用如下所示的 YAML 文件部署 nginx 及其 Service 和 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
64
65
66
67
68
kind: Deployment
apiVersion: extensions/v1beta1
metadata:
  name: nginx
  labels:
    app: nginx
spec:
  replicas: 2
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
        version: v1
    spec:
      containers:
      - name: nginx
        image: nginx:latest
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 80
          protocol: TCP
        livenessProbe:
          httpGet:
            path: /
            port: 80
          initialDelaySeconds: 30
          timeoutSeconds: 30
        readinessProbe:
          httpGet:
            path: /
            port: 80
          initialDelaySeconds: 30
          timeoutSeconds: 30

---
kind: Service
apiVersion: v1
metadata:
  name: nginx
  labels:
    app: nginx
spec:
  ports:
  - port: 80
    targetPort: 80
    name: http
  selector:
    app: nginx

---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: nginx
  annotations:
    ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - http:
      paths:
      - path: /
        backend:
          serviceName: nginx
          servicePort: 80
    host: xdhuxc.com

访问测试

1
curl -Lv --resolve xdhuxc.com:80:${ingress-node-ip} xdhuxc.com

例如:

1
curl -Lv --resolve xdhuxc.com:80:172.31.40.84 xdhuxc.com

访问链路

域名 主机 ingress service pod/容器
xdhuxc.com -> 172.20.26.150:80 -> ingress-controller -> [service] -> 192.168.235.231:80

参考资料

https://blog.csdn.net/cj2580/article/details/80017904#comments

updatedupdated2018-08-182018-08-18
加载评论