8. cka题目-ingress

578 阅读1分钟

题目描述

  • 设置配置环境 kubectl config use-context k8s
  • 如下创建一个新的 nginx ingress 资源:
    • 名称:pong
    • namespace: ing-internal
  • 使用服务端口 5678 在路径/hello 上公开服务 hello
  • 可以使用一下命令检查服务 hello 的可用性,该命令返回 hello: curl -kL < INTERNAL_IP>/hello/

根据题目完成预置条件

  • 创建 namespace
kubectl create namespace ing-internal
  • 创建 hello 服务
cat > /cka/serviceHello.yaml <<EOF
apiVersion: v1
kind: Service
metadata:
  name: hello
  namespace: ing-internal
spec:
  selector:
    app: MyApp
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80
EOF

# 创建 hello 服务
kubectl apply -f /cka/serviceHello.yaml

解析

  • Ingress 配置文件
cat > /cka/ingress.yaml <<EOF
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: /hello
        pathType: Prefix
        backend:
          service:
            name: hello
            port:
              number: 5678
EOF
  • 创建 Ingress
kubectl apply -f /cka/ingress.yaml

参考

Ingress