Base OS : CentOS (1 master 2 minions)
K8S version : 1.9.5 (deployed using KubeSpray)
我刚接触Kubernetes Ingress,正在设置两个不同的服务,每个服务都可以通过自己的路径访问。
我已经创建了2个部署:
kubectl run nginx --image=nginx --port=80
kubectl run echoserver --image=gcr.io/google_containers/echoserver:1.4 --port=8080
我还创建了它们相应的服务:
kubectl expose deployment nginx --target-port=80 --type=NodePort
kubectl expose deployment echoserver --target-port=8080 --type=NodePort
我的svc
是:
[root@node1 kubernetes]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
echoserver NodePort 10.233.48.121 <none> 8080:31250/TCP 47m
nginx NodePort 10.233.44.54 <none> 80:32018/TCP 1h
我的NodeIP地址是172.16.16.2
,我可以使用它访问两个Pod。
http://172.16.16.2:31250 &
http://172.16.16.2:32018
现在除此之外,我想部署一个Ingress,以便我能够使用不同的路径访问两个pod,而不是使用2个IP和2个不同的端口,而是1个IP地址。
所以我的Ingress文件是:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: fanout-nginx-ingress
spec:
rules:
- http:
paths:
- path: /nginx
backend:
serviceName: nginx
servicePort: 80
- path: /echo
backend:
serviceName: echoserver
servicePort: 8080
这将产生:
[root@node1 kubernetes]# kubectl describe ing fanout-nginx-ingress
Name: fanout-nginx-ingress
Namespace: development
Address:
Default backend: default-http-backend:80 (<none>)
Rules:
Host Path Backends
---- ---- --------
*
/nginx nginx:80 (<none>)
/echo echoserver:8080 (<none>)
Annotations:
Events: <none>
现在,当我尝试使用 NodeIP 地址(172.16.16.2)访问 Pods 时,什么也没有。
http://172.16.16.2/echo
http://172.16.16.2/nginx
我的配置文件中是否有我遗漏的东西?