获取Kubernetes Ingress端点/ IP地址

7 kubernetes kubernetes-ingress

Base OS : CentOS (1 master 2 minions)
K8S version : 1.9.5 (deployed using KubeSpray)
Run Code Online (Sandbox Code Playgroud)

我是Kubernetes Ingress的新手,我正在设置两种不同的服务,每种服务都有自己的路径.

我创建了2个部署:

kubectl run nginx --image=nginx --port=80
kubectl run echoserver --image=gcr.io/google_containers/echoserver:1.4 --port=8080
Run Code Online (Sandbox Code Playgroud)

我也创建了相应的服务:

kubectl expose deployment nginx --target-port=80 --type=NodePort
kubectl expose deployment echoserver --target-port=8080 --type=NodePort
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

我的NodeIP地址是172.16.16.2,我可以使用

http://172.16.16.2:31250 &
http://172.16.16.2:32018
Run Code Online (Sandbox Code Playgroud)

现在,除此之外,我想部署一个Ingress,这样我就可以不使用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
Run Code Online (Sandbox Code Playgroud)

这会产生:

[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>
Run Code Online (Sandbox Code Playgroud)

现在,当我尝试使用NodeIP地址(172.16.16.2)访问Pod时,我什么都没得到.

http://172.16.16.2/echo
http://172.16.16.2/nginx
Run Code Online (Sandbox Code Playgroud)

在我的配置中有什么我错过的吗?

Luk*_*ski 8

我在裸机安装上遇到了同样的问题 - 或者更接近于此问题(kubernetes虚拟集群 - 通过Host-Only-Adapter连接的虚拟机集).这是我的kubernetes vlab的链接.

首先确保安装了入口控制器.目前有两个入口控制器值得尝试kubernetes nginx入口控制器nginx kubernetes入口控制器 -I安装第一个.

安装

转到安装说明并执行第一步

# prerequisite-generic-deployment-command
$ kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/mandatory.yaml
Run Code Online (Sandbox Code Playgroud)

接下来获取群集节点的IP地址.

$ kubectl get nodes -o wide
NAME     STATUS   ROLES    ...   INTERNAL-IP    
master   Ready    master   ...   192.168.121.110
node01   Ready    <none>   ...   192.168.121.111
node02   Ready    <none>   ...   192.168.121.112
Run Code Online (Sandbox Code Playgroud)

此外,ingress-nginx类型的箱子服务LoadBalancer.我是通过NodePort从安装教程下载模板服务并在svc-ingress-nginx-lb.yaml文件中进行以下调整来实现的.

$ curl https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/provider/baremetal/service-nodeport.yaml > svc-ingress-nginx-lb.yaml

# my changes svc-ingress-nginx-lb.yaml
type: LoadBalancer
externalIPs:
  - 192.168.121.110
  - 192.168.121.111
  - 192.168.121.112
externalTrafficPolicy: Local

# create ingress- service
$ kubectl apply -f svc-ingress-nginx-lb.yaml
Run Code Online (Sandbox Code Playgroud)

验证

检查是否ingress-nginx已创建服务.

$ kubectl get svc -n ingress-nginx
NAME            TYPE           CLUSTER-IP     EXTERNAL-IP                                                       PORT(S)                      AGE
ingress-nginx   LoadBalancer   10.110.127.9   192.168.121.110,192.168.121.111,192.168.121.112   80:30284/TCP,443:31684/TCP   70m
Run Code Online (Sandbox Code Playgroud)

检查是否nginx-ingress-controller已创建部署.

$ kubectl get deploy -n ingress-nginx
NAME                       DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
nginx-ingress-controller   1         1         1            1           73m
Run Code Online (Sandbox Code Playgroud)

检查nginx-ingresspod是否正在运行.

$ kubectl get pods --all-namespaces -l 

app.kubernetes.io/name=ingress-nginx
NAMESPACE       NAME                                        READY   STATUS    RESTARTS   AGE
ingress-nginx   nginx-ingress-controller-5cd796c58c-lg6d4   1/1     Running   0          75m
Run Code Online (Sandbox Code Playgroud)

最后,检查入口控制器版本.别忘了更改pod名称!

$ kubectl exec -it nginx-ingress-controller-5cd796c58c-lg6d4 -n ingress-nginx -- /nginx-ingress-controller --version
-------------------------------------------------------------------------------
NGINX Ingress controller
  Release:    0.21.0
  Build:      git-b65b85cd9
  Repository: https://github.com/aledbf/ingress-nginx
-------------------------------------------------------------------------------
Run Code Online (Sandbox Code Playgroud)

测试

通过执行本教程中的步骤测试入口控制器是否正常工作- 当然,您将省略minikube部分.

成功执行所有步骤将创建应该如下所示的入口控制器资源.

$ kubectl get ing
NAME               HOSTS                                ADDRESS                                          PORTS    AGE
ingress-tutorial   myminikube.info,cheeses.all          192.168.121.110,192.168.121.111,192.168.121.112   80      91m
Run Code Online (Sandbox Code Playgroud)

和看起来像这样的豆荚.

$ kubectl get pods 
NAME                              READY   STATUS             RESTARTS   AGE
cheddar-cheese-6f94c9dbfd-cll4z   1/1     Running            0          110m
echoserver-55dcfbf8c6-dwl6s       1/1     Running            0          104m
stilton-cheese-5f6bbdd7dd-8s8bf   1/1     Running            0          110m
Run Code Online (Sandbox Code Playgroud)

最后,测试myminikube.info通过入口负载均衡器传播的请求.

$ curl myminikube.info
CLIENT VALUES:
client_address=10.44.0.7
command=GET
real path=/
query=nil
request_version=1.1
request_uri=http://myminikube.info:8080/

SERVER VALUES:
server_version=nginx: 1.10.0 - lua: 10001

HEADERS RECEIVED:
accept=*/*
host=myminikube.info
user-agent=curl/7.29.0
x-forwarded-for=10.32.0.1
x-forwarded-host=myminikube.info
x-forwarded-port=80
x-forwarded-proto=http
x-original-uri=/
x-real-ip=10.32.0.1
x-request-id=b2fb3ee219507bfa12472c7d481d4b72
x-scheme=http
BODY:
Run Code Online (Sandbox Code Playgroud)

这是一个漫长的旅程,让入口在熊金属环境中工作.因此,我将包括帮助我的相关链接.