CKAD-2026-Ingress

这道题主要是考察ingress的知识:

主要知识背景:url->ingress->service->pod

"路径错、后端名错、端口错、标签错"

更顺口一点:

"路名端口标,依次查四错"

  • :Ingress 的 path 错误

  • :Ingress 的 backend.service.name 错误

  • :Service 的 targetPort 错误

  • :Service 的 selector 标签错误

1. URL → Ingress 环节:Ingress 的 path 错误

  • 错误现象 :用户使用 curl -L http://content-marlin.local/ 访问根路径 /,但请求无法被 Ingress 正确路由。

  • 原因 :原 Ingress 配置中的 path 可能设置为 /content-marlin 或其他错误值,而不是 /

    Deployment 容器探针的 path/,且题目要求的访问地址为根路径,因此 Ingress 必须匹配 / 才能将请求转发给后端。

  • 修复 :将 Ingress 的 path 改为 /


2. Ingress → Service 环节:Ingress 的 backend.service.name 错误

  • 错误现象:Ingress 匹配到请求后,无法找到正确的 Service 转发流量。

  • 原因 :原 Ingress 中 backend.service.name 指向的 Service 名称与实际创建的 Service 名称(nginx-ing-svc)不一致(例如可能写成了其他名字)。

  • 修复 :将 Ingress 的 service.name 改为 nginx-ing-svc


3. Service → Pod 环节(端口部分):Service 的 targetPort 错误

  • 错误现象:Service 收到流量后,无法将请求转发到 Pod 的正确端口。

  • 原因 :原 Service 的 targetPort 与 Deployment 中 Pod 的 containerPort(值为 80)不匹配(例如可能是 8080 或其他端口)。

  • 修复 :将 Service 的 targetPort 改为 80


4. Service → Pod 环节(选择器部分):Service 的 selector 错误

  • 错误现象:Service 无法找到任何可用的 Pod,因为标签选择器没有匹配到任何 Pod。

  • 原因 :原 Service 的 selector 中标签与 Deployment 中 Pod 模板的标签(app: nginx-ing)不一致(例如可能写成了 app: nginx 或其他值)。

  • 修复 :将 Service 的 selector 改为 app: nginx-ing

用户请求 http://content-marlin.local/content-marlin

┌─────────────┐

│ Ingress │ ← 域名 + 路径匹配规则

│ nginx-ingress-test │

└──────┬──────┘

│ 转发到 Service

┌─────────────┐

│ Service │ ← 固定 ClusterIP,负载均衡

│ (名字随意) │

└──────┬──────┘

│ 通过标签选择器匹配 Pod

┌─────────────┐

│ Pod │ ← 标签 app: nginx-ing

│ (Deployment 创建) │

└─────────────┘

  1. Ingress 排错

Task

namespace content-marlin 下,名为 content-marlin-demployment 的 Deployment 通过 Ingress nginx-ingress-test 公开。

您可以在目录 /home/student/content-marlin-demployment 中找到 deployment、service、ingress 的清单文件。

Deployment 本应可以通过http://content-marlin.local/content-marlin正常访问,但是目前返回错误。

通过更新相关资源,来识别并修复问题,以便 Deployment 按计划可以被正常访问。

请注意,这道题的 deployment 是正确的,请不要修改 deployment。

最后,你可以使用命令来检测 curl -L http://content-marlin.local/

【1】 按照题目要求,在master 节点上执行,切换到题目要求节点

ssh ckad000000

【2】 因为题目告知了 deployment 是正确的,所以我们先看一下 deployment 配置信息。

cat /home/student/content-marlin-demployment/deployment.yaml

内容如下

bash 复制代码
apiVersion: apps/v1

kind: Deployment

metadata:

  name: content-marlin-demployment

  namespace: content-marlin

spec:

  replicas: 1

  selector:

    matchLabels:

      app: nginx-ing字

  template:

    metadata:

      labels:

        app: nginx-ing  ## 3 ## 记住 Deployment 里 template 下的标签名

    spec:

      containers:

      - name: nginx

        image: vicuu/nginx:hello

        imagePullPolicy: IfNotPresent

        ports:

        - containerPort: 80 ## 1 ## 记住 Deployment 的容器的端口号,因为题目说明了 Deployment 是正确的。

        startupProbe:

          httpGet:

            path: / ## 2 ## 记住这个 path 的地址,这里是 /

            port: 80

          failureThreshold: 30

          periodSeconds: 10

【3】 修改 service 配置文件

vim /home/student/content-marlin-demployment/service.yaml

修改内容为下面红色字体

bash 复制代码
apiVersion: v1

kind: Service

metadata:

  name: nginx-ing-svc # 记住 Service 里的这个 name

  namespace: content-marlin

  labels:

    app: nginx

spec:

  ports:

  - port: 80

    targetPort: 80 # 修改 Service 的 targetPort 端口与上面 Deployment 的 containerPort 端口号一致,即修改为 80

    protocol: TCP

  selector:

app: nginx-ing # 这里要修改为 Deployment 里的 template 下的那个标签名字。Service 通过选择标签跟 Deployment 建立关联

编辑完后,按 ESC,再按 :wq 保存退出

【4】 修改 ingress 配置文件

修改 ingress 配置文件,并重新创建 ingress。

vim /home/student/content-marlin-demployment/ingress.yaml

修改内容为下面红色字体

bash 复制代码
apiVersion: networking.k8s.io/v1

kind: Ingress

metadata:

  name: nginx-ingress-test

  namespace: content-marlin

spec:

  ingressClassName: traefix

  rules:

  - http:

      paths:

      - path: / # 这里要修改为 Deployment 里 那个 path 地址,也就是 /

        pathType: Prefix

        backend:

          service:

            name: nginx-ing-svc # 这里要修改成 Service 里的 name。因为 Ingress 通过 Service 的 name 建立关联。

            port:

              number: 80

编辑完后,按 ESC,再按 :wq 保存退出

【5】 创建 service 和 ingress

kubectl apply -f /home/student/content-marlin-demployment/service.yaml

kubectl apply -f /home/student/content-marlin-demployment/ingress.yaml

【6】 按照题目里要求的网址检测,是否能正常访问,模拟环境加上30080,与之前一样,404即为正常。

curl -L http://content-marlin.local:30080/

相关推荐
zzzsde6 小时前
【Linux】库的制作和使用(3)ELF&&动态链接
linux·运维·服务器
CQU_JIAKE6 小时前
4.3【A]
linux·运维·服务器
AI周红伟6 小时前
OpenClaw是什么?OpenClaw能做什么?OpenClaw详细介绍及保姆级部署教程-周红伟
大数据·运维·服务器·人工智能·微信·openclaw
Elastic 中国社区官方博客6 小时前
当 TSDS 遇到 ILM:设计不会拒绝延迟数据的时间序列数据流
大数据·运维·数据库·elasticsearch·搜索引擎·logstash
qing222222226 小时前
Linux中修改mysql数据表
linux·运维·mysql
杨云龙UP6 小时前
Oracle 中 NOMOUNT、MOUNT、OPEN 怎么理解? 在不同场景下如何操作?_20260402
linux·运维·数据库·oracle
Amctwd6 小时前
【Linux】OpenCode 安装教程
linux·运维·服务器
和小潘一起学AI7 小时前
SHH隧道内网穿透
运维·服务器
wwj888wwj7 小时前
Docker基础(复习)
java·linux·运维·docker