题目
分析
在ing-internal 命名空间下创建一个ingress,名字为pong,代理的service hi,端口为5678,配置路径/hi。
验证:访问curl -kL <INTERNAL_IP>/hi会返回hi
命令
环境搭建
这里就以一个nginx服务为例
创建命名空间
kubectl create ns ing-internal
deploy-hi.yaml
apiVersion: apps/v1 kind: Deployment metadata: name: nginx-hi labels: app: nginx spec: replicas: 1 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:1.14.2 ports: - containerPort: 80 name: http
创建deployment
kubectl create -f deploy-hi.yaml -n ing-internal
service-hi.yaml
apiVersion: v1 kind: Service metadata: labels: app: nginx name: hi spec: ports: - port: 80 protocol: TCP targetPort: http selector: app: nginx sessionAffinity: None type: NodePort
创建service hi
kubectl create -f service-hi.yaml -n ing-internal
写入hi到/hi路径
cd /usr/share/nginx/html && mkdir hi && echo "hi" > hi/index.html
解题
由于测试环境端口是80,所以下面的不是题目对应的答案
ingress-hi.yaml
apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: pong namespace: ing-internal spec: rules: - http: paths: - path: /hi pathType: Prefix backend: service: name: hi port: number: 80
命令
kubectl create -f ingress-hi.yaml
题目对应答案如下:
apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: pong namespace: ing-internal spec: rules: - http: paths: - path: /hi pathType: Prefix backend: service: name: hi port: number: 5678
结果
创建deploy 及 service截图如下:
配置hi路径截图如下:
配置好ingress后验证截图如下: