菜单 学习猿地 - LMONKEY

VIP

开通学习猿地VIP

尊享10项VIP特权 持续新增

知识通关挑战

打卡带练!告别无效练习

接私单赚外块

VIP优先接,累计金额超百万

学习猿地私房课免费学

大厂实战课仅对VIP开放

你的一对一导师

每月可免费咨询大牛30次

领取更多软件工程师实用特权

入驻
57
0

003.OpenShift网络

原创
05/13 14:22
阅读数 91440

一 OpenShift网络实现

1.1 软件定义网络(SDN)

默认情况下,Docker网络使用仅使用主机虚机网桥bridge,主机内的所有容器都连接至该网桥。连接到此桥的所有容器都可以彼此通信,但不能与不同主机上的容器通信。通常,这种通信使用端口映射来处理,其中容器端口绑定到主机上的端口,所有通信都通过物理主机上的端口路由。
当有大量主机和容器时,使用此模式,需要手动管理所有端口绑定非常不现实。
为了支持跨集群的容器之间的通信,OpenShift容器平台使用了软件定义的网络(SDN)方法。软件定义的网络是一种网络模型,它通过几个网络层的抽象来管理网络服务。SDN将处理流量的软件(称为控制平面)和路由流量的底层机制(称为数据平面)解耦。SDN支持控制平面和数据平面之间的通信。
在OpenShift Container Platform 3.9中(之后简称OCP),管理员可以为pod网络配置三个SDN插件:
  1. ovs-subnet:默认插件,子网提供了一个flat pod网络,其中每个pod可以与其他pod和service通信。
  2. ovs-multitenant:该为pod和服务提供了额外的隔离层。当使用此插件时,每个project接收一个惟一的虚拟网络ID (VNID),该ID标识来自属于该project的pod的流量。通过使用VNID,来自不同project的pod不能与其他project的pod和service通信。
  3. ovs-networkpolicy:此插件允许管理员使用NetworkPolicy对象定义自己的隔离策略。
cluster network由OpenShift SDN建立和维护,它使用Open vSwitch创建overlay网络,master节点不能通过集群网络访问容器,除非master同时也为node节点。
注意:VNID为0的project可以与所有其他pod通信,在OpenShift容器平台中,默认项目的VNID为0。

1.2 Kubernetes SDN Pod

kubernetes basic networking_v1
在默认的OpenShift容器平台安装中,每个pod都有一个惟一的IP地址。pod中的所有容器都对外表现在相同的主机上。给每个pod提供自己的IP地址意味着,在端口分配、网络、DNS、负载平衡、应用程序配置和迁移方面,pod被视为物理主机或虚拟机的独立节点(仅从网络层面看待)。
Kubernetes提供了service的概念,在任何OpenShift应用程序中,service都是必不可少的资源。service充当一个或多个pod前的负载平衡器。该service提供一个固定的IP地址,并且允许与pod通信,而不必跟踪单独的pod IP地址。
kubernetes services networking_v1
大多数实际应用程序都不是作为单个pod运行的。它们需要水平伸缩,这样应用程序就可以在许多pod上运行,以满足不断增长的用户需求。在OpenShift集群中,pod不断地在集群中的节点之间创建和销毁。每次创建pod时,它们都会获得一个不同的IP地址。一个service提供一个单独的、惟一的IP地址供其他pod使用,而不依赖于pod运行的节点,因此一个pod不必一定需要发现另一个pod的IP地址。客户端通过service的请求在不同pod之间实现负载均衡。

1.3 Kubernetes SDN Service

service背后运行的一组pod由OpenShift容器平台自动管理。每个service都被分配了一个唯一的IP地址供客户端连接。这个IP地址也来自OpenShift SDN,它与pod的内部网络不同,也只在集群中可见。每个与selector匹配的pod都作为endpoint添加到service资源中。当创建和销毁pods时,service后面的endpoint将自动更新。
service yaml语法:
  1 - apiVersion: v1
  2   kind: Service			#声明资源类型
  3   metadata:
  4     labels:
  5       app: hello-openshift
  6       name: hello-openshift	#服务的唯一名称
  7   spec:
  8     ports:,
  9     - name: 8080-tcp
 10       port: 8080		#服务对外公开的端口客户机连接到服务端口
 11       protocol: TCP
 12       targetPort: 8080		#targetPort属性必须匹配pod容器定义中的containerPort,服务将数据包转发到pod中定义的目标端口。
 13     selector:			#该服务使用selector属性查找要转发数据包的pod。目标pod的元数据中需要有匹配的标签。如果服务发现多个具有匹配标签的pod,它将在它们之间实现负载
 14       app: hello-openshift
 15       deploymentconfig: hello-openshift

1.4 service对外暴露

默认情况下,pod和service IP地址不能从OpenShift集群外部访问。对于需要从OpenShift集群外部访问服务的应用程序,可以通过以下三种方式。
HostPort/HostNetwork:在这种方法中,client可以通过主机上的网络端口直接访问集群中的应用程序pod。应用程序pod中的端口被绑定到运行该pod的主机上的端口。这种方法在集群中运行大量pod时,存在端口冲突的风险。
NodePort:这是一种较老的基于Kubernetes的方法,通过绑定到node主机上的可用端口,将service公开给外部客户端,然后node主机代理到service IP地址的连接。使用oc edit svc命令编辑服务属性,指定NodePort的类型,并为NodePort属性提供端口值。OpenShift然后通过node主机的公共IP地址和nodePort中设置的端口值代理到服务的连接。这种方法支持非http通信。
OpenShift routes:OpenShift中的推荐方式。它使用唯一的URL公开服务。使用oc expose命令公开用于外部访问的服务,或者从OpenShift web控制台公开服务。在这种方法中,目前只支持HTTP、HTTPS、TLS whit SNI和WebSockets。
附图:显示了NodePort服务如何允许外部访问Kubernetes服务。
kubernetes nodeport services_v1
service nodeport yaml语法:
  1 apiVersion: v1
  2 kind: Service
  3 metadata:
  4 ...
  5 spec:
  6   ports:
  7   - name: 3306-tcp
  8     port: 3306
  9     protocol: TCP
 10     targetPort: 3306	#pod目标端口,即需要和pod定义的端口匹配
 11     nodePort: 30306	#OpenShift集群中主机上的端口,暴露给外部客户端
 12   selector:
 13     app: mysqldb
 14     deploymentconfig: mysqldb
 15     sessionAffinity: None
 16   type: NodePort	#服务的类型,如NodePort
 17 ...
OpenShift将服务绑定到服务定义的nodePort属性中定义的值,并为集群中所有node(包括master)上的流量打开该端口。外部客户端可以连接到node端口上的任何节点的公共IP地址来访问服务。请求会在服务后面的各个pod之间实现轮询的负载平衡。
OpenShift route主要限于HTTP和HTTPS流量,但是节点端口可以处理非HTTP流量,当设置好公开的端口后,客户机可以使用TCP或UDP的协议连接到该端口。
提示:缺省情况下,NodePort属性的端口号限制在30000-32767之间,可通过在OpenShift主配置文件中配置范围。
node port在集群中的所有node上都是打开的,包括master节点。如果没有提供node端口值,OpenShift将自动在配置范围内分配一个随机端口

1.5 pod访问外部网络

pod可以使用其主机的地址与外部网络通信。只要主机能够解析pod需要到达的服务器,pod就可以使用网络地址转换(network address translation, NAT)机制与目标服务器通信。

二 OpenShift SDN练习

2.1 前置准备

[student@workstation ~]$ lab install-prepare setup
[student@workstation ~]$ cd /home/student/do280-ansible
[student@workstation do280-ansible]$ ./install.sh
提示:以上准备为部署一个正确的OpenShift平台。

2.2 本练习准备

[student@workstation ~]$ lab openshift-network setup #准备本实验环境

2.3 创建应用

[student@workstation ~]$ oc login -u developer -p redhat https://master.lab.example.com
[student@workstation ~]$ oc new-project network-test #创建project
[student@workstation ~]$ oc new-app --name=hello -i php:7.0 http://registry.lab.example.com/scaling
[student@workstation ~]$ oc get pods
NAME READY STATUS RESTARTS AGE
hello-1-build 1/1 Running 0 8s

2.4 扩展应用

[student@workstation ~]$ oc scale --replicas=2 dc hello
[student@workstation ~]$ oc get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE
hello-1-kszfh 1/1 Running 0 11m 10.128.0.21 node1.lab.example.com
hello-1-q7wk2 1/1 Running 0 11m 10.129.0.37 node2.lab.example.com

2.5 测试访问

[student@workstation ~]$ curl http://10.128.0.21:8080
curl: (7) Failed connect to 10.128.0.21:8080; Network is unreachable
[root@node1 ~]# curl http://10.128.0.21:8080
  1 <html>
  2  <head>
  3   <title>PHP Test</title>
  4  </head>
  5  <body>
  6  <br/> Server IP: 10.128.0.21
  7  </body>
  8 </html>
  9 [root@node1 ~]# curl http://10.129.0.37:8080
 10 <html>
 11  <head>
 12   <title>PHP Test</title>
 13  </head>
 14  <body>
 15  <br/> Server IP: 10.129.0.37
 16  </body>
 17 </html>
提示:默认情况下,pod的ip属于内部,集群内部节点可以使用pod ip访问,集群外部(如workstation)无法访问。
[student@workstation ~]$ oc get svc hello
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
hello ClusterIP 172.30.253.212 <none> 8080/TCP 14m
[student@workstation ~]$ curl http://172.30.253.212:8080
curl: (7) Failed connect to 172.30.253.212:8080; Network is unreachable
[root@node1 ~]# curl http://172.30.253.212:8080 #验证负载均衡
  1 <html>
  2  <head>
  3   <title>PHP Test</title>
  4  </head>
  5  <body>
  6  <br/> Server IP: 10.128.0.21
  7  </body>
  8 </html>
  9 [root@node1 ~]# curl http://172.30.253.212:8080		#验证负载均衡
 10 <html>
 11  <head>
 12   <title>PHP Test</title>
 13  </head>
 14  <body>
 15  <br/> Server IP: 10.129.0.37
 16  </body>
 17 </html>
提示:默认情况下,cluster的ip属于内部,集群内部节点可以使用cluster ip访问,集群外部(如workstation)无法访问。

2.6 检查服务

[student@workstation ~]$ oc describe svc hello
Name: hello
Namespace: network-test
Labels: app=hello
Annotations: openshift.io/generated-by=OpenShiftNewApp
Selector: app=hello,deploymentconfig=hello
Type: ClusterIP
IP: 172.30.253.212
Port: 8080-tcp 8080/TCP
TargetPort: 8080/TCP
Endpoints: 10.128.0.21:8080,10.129.0.37:8080
Session Affinity: None
Events: <none>
解释:
endpoint:显示请求路由到的pod IP地址列表。当pod有更新后,endpoint将自动更新。
Selector:OpenShift使用为pods定义的选择器和标签来使用给定的集群IP,以便实现应用的负载均衡。如上所示为OpenShift将此服务的请求路由到所有标记为app=hello和deploymentconfig=hello的pod。

2.7 检查pod

[student@workstation ~]$ oc describe pod hello-1-kszfh

2.8 设置外部访问

使用NodePort方式设置外部访问。
[student@workstation ~]$ oc edit svc hello
  1 apiVersion: v1
  2 kind: Service
  3 metadata:
  4   annotations:
  5     openshift.io/generated-by: OpenShiftNewApp
  6   creationTimestamp: 2019-07-19T15:50:09Z
  7   labels:
  8     app: hello
  9   name: hello
 10   namespace: network-test
 11   resourceVersion: "24496"
 12   selfLink: /api/v1/namespaces/network-test/services/hello
 13   uid: e348e2a3-aa3c-11e9-b230-52540000fa0a
 14 spec:
 15   clusterIP: 172.30.253.212
 16   ports:
 17   - name: 8080-tcp
 18     port: 8080
 19     protocol: TCP
 20     targetPort: 8080
 21     nodePort: 30800
 22   selector:
 23     app: hello
 24     deploymentconfig: hello
 25   sessionAffinity: None
 26   type: NodePort
 27 status:
[student@workstation ~]$ oc describe svc hello
Name: hello
Namespace: network-test
Labels: app=hello
Annotations: openshift.io/generated-by=OpenShiftNewApp
Selector: app=hello,deploymentconfig=hello
Type: NodePort #验证是否为NodePort
IP: 172.30.253.212
Port: 8080-tcp 8080/TCP
TargetPort: 8080/TCP
NodePort: 8080-tcp 30800/TCP
Endpoints: 10.128.0.21:8080,10.129.0.37:8080
Session Affinity: None
External Traffic Policy: Cluster
Events: <none>

2.9 验证外部访问

[student@workstation ~]$ curl http://node1.lab.example.com:30800
  1 <html>
  2  <head>
  3   <title>PHP Test</title>
  4  </head>
  5  <body>
  6  <br/> Server IP: 10.128.0.21
  7  </body>
  8 </html>
[student@workstation ~]$ curl http://node2.lab.example.com:30800
  1 <html>
  2  <head>
  3   <title>PHP Test</title>
  4  </head>
  5  <body>
  6  <br/> Server IP: 10.129.0.37
  7  </body>
  8 </html>

2.10 使用pod shell

[student@workstation ~]$ oc rsh hello-1-kszfh #使用pod的shell
sh-4.2$ curl http://services.lab.example.com

三 OpenShift router

3.1 OpenShift route概述

OpenShift service允许在OpenShift中的pod之间进行网络访问;
OpenShift routes允许从OpenShift外部对pods进行网络访问。
openshift routes_v1
路由概念上是通过连接公网IP和DNS主机名访问内网service IP。在实践中,为了提高性能和减少延迟,OpenShift route通过OpenShift创建的网络直接连接到pod,使用该服务只查找endpoint,service只是协助查询Pod地址。
OpenShift 路由功能由router service提供,该服务在OpenShift实例中作为一个pod运行,可以像任何其他常规pod一样伸缩和复制。router service基于开源软件HAProxy实现。
OpenShift route配置的公共DNS主机名需要指向运行router的节点的公共IP地址。route pod与常规应用程序pod不同,它绑定到节点的公共IP地址,而不是内部pod网络。这通常使用DNS通配符配置。
  1 - apiVersion: v1
  2   kind: Route				#声明为route类型
  3   metadata:
  4     creationTimestamp: null
  5     labels:
  6       app: quoteapp
  7     name: quoteapp				#路由器名字
  8   spec:
  9     host: quoteapp.apps.lab.example.com	#与route关联的FQDN,必须预先配置,以解析到OpenShift route pod运行的节点的IP地址
 10     port:
 11       targetPort: 8080-tcp
 12   to:					#一个对象,该对象声明此route指向的资源类型(在本例中是OpenShift service),以及该资源的名称(quoteapp)
 13     kind: Service
 14     name: quoteapp
提示:不同资源类型可以使用相同的名称,如一个名为quoteapp的route可以指向一个名为quoteapp的service。
service通过selector与pod的label进行匹配,router通过name与service的name匹配。

3.2 创建route

创建route最简单和推荐的方法是使用oc expose命令,将service资源名称作为输入参数。--name选项可用于控制route资源的名称,--hostname选项可用于为route提供自定义主机名。
示例:
[user@demo ~]$ oc expose service quote \
--name quote --hostname=quoteapp.apps.lab.example.com
从模板或不带--hostname参数的oc expose命令创建的路由,命名方式为:
<route-name>-<project-name>.<default-domain>
解释
route-name:route的名称,或原始资源的名称;
project-name:包含资源的项目的名称;
default-domain:该值是在OpenShift master上配置的,它对应于作为安装OpenShift先决条件列出的通配符DNS域。
例如,在OpenShift集群中名为test的project中创建一条名为quote的路由,其中子域为apps.example.com,则FQDN为quote-test.apps.example.com
注意:承载通配符域的DNS服务器不知道任何route的主机名,它只将任何名称解析为已配置的ip。只有OpenShift route知道route主机名,将每个主机都当作HTTP虚拟主机。无效的通配符域主机名,即不与任何route对应的主机名,将被OpenShift路由器阻塞。
通过向oc create提供JSON或YAML资源定义文件,也可以像其他OpenShift资源一样创建route资源。
oc new-app命令在从容器映像、Dockerfiles或应用程序源代码构建pod时不创建route资源。
oc new-app命令不知道pod是否打算从OpenShift实例外部访问。当oc new-app命令从模板创建一组pod时,没有什么可以阻止模板将路由资源包含到应用程序中。

3.3 查找默认subdomain

默认路由子域是在OpenShift配置文件master-config.yaml中的routingConfig字段中定义,使用关键字subdomain。
routingConfig:
subdomain: apps.example.com
默认情况下,OpenShift HAProxy route绑定到主机端口80 (HTTP)和443 (HTTPS)。route必须放置在这些端口不使用的节点上。或者,可以通过设置ROUTER_SERVICE_HTTP_PORT和ROUTER_SERVICE_HTTPS_PORT环境变量来配置路由器监听其他端口.
路由器支持以下协议:
  • HTTP
  • HTTPS with SNI
  • WebSockets
  • TLS with SNI

3.4 routing类型和选项

路由可以是安全的,也可以是非安全的。安全route提供了使用几种类型的TLS方式来向客户端提供证书的能力。不安全路由是最容易配置的,因为它们不需要密钥或证书,但是安全路由会加密进出pod的流量。
在创建安全路由之前,需要生成TLS证书。
示例:如下步骤创建名为test.example.com的路由创建一个简单的自签名证书。
  • 使用openssl命令创建私钥:
[user@demo ~]$ openssl genrsa -out example.key 2048
  • 使用生成的私钥创建证书签名请求(CSR):
[user@demo ~]$ openssl req -new -key example.key -out example.csr -subj "/C=US/ST=CA/L=Los Angeles/O=Example/OU=IT/CN=test.example.com"
  • 使用密钥和CSR生成证书
[user@demo ~]$ openssl x509 -req -days 366 -in example.csr -signkey example.key -out example.crt
  • 当证书准备好时,创建一个edge-terminated的路由
[user@demo ~]$ oc create route edge --service=test \
--hostname=test.example.com \
--key=example.key --cert=example.crt

3.5 通配符子域

wildcard policy允许用户定义domain中所有主机的route。route可以使用wildcardPolicy字段将wildcard policy指定为其配置的一部分。OpenShift路由器支持通配符路由,通过设置路由器部署配置中的ROUTER_ALLOW_WILDCARD_ROUTES环境变量为true,从而可将wildcardPolicy属性设置为子域的任何route都由路由器提供服务。路由器根据route的通配符策略暴露相关的service。
示例:如下下示例表示对于三个不同的路由,a.lab.example.com、b.lab.example.com和c.lab.example.com,它们应该路由到一个名为test的OpenShift服务,可以使用通配符策略配置路由。
  • 将路由器作为集群管理用户处理通配符路由
[user@demo ~]$ oc scale dc/router --replicas=0
[user@demo ~]$ oc set env dc/router ROUTER_ALLOW_WILDCARD_ROUTES=true
[user@demo ~]$ oc scale dc/router --replicas=1
  • 使用通配符策略创建新路由
[user@demo ~]$ oc expose svc test --wildcard-policy=Subdomain \
--hostname='www.lab.example.com'

3.6 管理route

在master节点上,在default中查找router
[root@master]# oc project default
[root@master]# oc get pods
在master节点上,检查路由器环境变量,以找到运行在pod中的HAProxy进程的连接参数
[root@master]# oc env pod router-1-32toa --list | tail -n 6
提示:当创建路由器时,STATS_PASSWORD变量中的密码是随机生成的。STATS_USERNAME和STATS_PORT变量有固定的默认值,但是它们都可以在路由器创建时更改。
在router运行的节点上,配置firewall-cmd以打开STATS_PORT变量指定的端口。
[root@node ~]# firewall-cmd --permanent --zone=public --add-port=1936
[root@node ~]# firewall-cmd --reload
打开web浏览器并访问HAProxy statistics URL 为 http://nodeIP:STATS_PORT/。
在User Name字段中输入STATS_USERNAME的值,在Password字段中输入STATS_PASSWORD的值,然后单击OK。则会显示的HAProxy metrics页面。

四 创建Route练习

4.1 前置准备

准备完整的OpenShift集群,参考《003.OpenShift网络》2.1。

4.2 本练习准备

[student@workstation ~]$ lab secure-route setup #准备本实验环境

4.3 创建应用

[student@workstation ~]$ oc login -u developer -p redhat https://master.lab.example.com
[student@workstation ~]$ oc new-project secure-route #创建project
[student@workstation ~]$ oc new-app --docker-image=registry.lab.example.com/openshift/hello-openshift --name=hello
[student@workstation ~]$ oc get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE
hello-1-wwgkr 1/1 Running 0 20s 10.129.0.38 node2.lab.example.com

4.4 创建TLS证书

[student@workstation ~]$ cd /home/student/DO280/labs/secure-route/ #使用环境中的脚本快速创建TLS自签名证书
[student@workstation secure-route]$ ./create-cert.sh

4.5 创建route

[student@workstation secure-route]$ ll
-rw-r--r--. 1 student student 550 Aug 7 2018 commands.txt
-rwxr-xr-x. 1 student student 506 Jul 19 2018 create-cert.sh
-rw-rw-r--. 1 student student 1224 Jul 20 10:43 hello.apps.lab.example.com.crt
-rw-rw-r--. 1 student student 1017 Jul 20 10:43 hello.apps.lab.example.com.csr
-rw-rw-r--. 1 student student 1679 Jul 20 10:43 hello.apps.lab.example.com.key
[student@workstation secure-route]$ oc create route edge \
> --service=hello --hostname=hello.apps.lab.example.com \
> --key=hello.apps.lab.example.com.key \
> --cert=hello.apps.lab.example.com.crt

4.6 确认验证

[student@workstation secure-route]$ oc get route
NAME HOST/PORT PATH SERVICES PORT TERMINATION WILDCARD
hello hello.apps.lab.example.com hello 8080-tcp edge None
[student@workstation secure-route]$ oc get route hello -o yaml #以yaml格式查看route

4.7 测试访问

[student@workstation ~]$ curl http://hello.apps.lab.example.com #以http形式访问会无法转发至后端任何pod
  1 ……
  2       <h1>Application is not available</h1>
  3       <p>The application is currently not serving requests at this endpoint. It may not have been started or is still starting.</p>
  4 ……
[student@workstation ~]$ curl -k -vvv https://hello.apps.lab.example.com #以https形式访问
  1 ……
  2 Hello OpenShift!
  3 * Connection #0 to host hello.apps.lab.example.com left intact
  4 ……

4.8 非安全形式访问

由于加密的通信在路由器上终止,并且请求使用不安全的HTTP转发到pods,所以可以使用pod IP地址通过普通HTTP访问应用程序。为此,请使用oc get pods -o命令中指定的IP地址。
[student@workstation secure-route]$ oc get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE
hello-1-wwgkr 1/1 Running 0 21m 10.129.0.38 node2.lab.example.com
[root@node1 ~]# curl -vvv http://10.129.0.38:8080
clipboard

五 OpenShift网络综合实验

5.1 前置准备

准备完整的OpenShift集群,参考《003.OpenShift网络》2.1。

5.2 本练习准备

[student@workstation ~]$ lab network-review setup

5.3 验证所需资源

[student@workstation ~]$ oc login -u developer -p redhat \
https://master.lab.example.com
[student@workstation ~]$ oc get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE
hello-openshift-1-6ls8z 1/1 Running 0 2m 10.128.0.23 node1.lab.example.com
[student@workstation ~]$ oc get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
hello-openshift ClusterIP 172.30.124.237 <none> 8080/TCP,8888/TCP 2m
[student@workstation ~]$ oc get route
NAME HOST/PORT PATH SERVICES PORT TERMINATION WILDCARD
hello-openshift hello.apps.lab.example.com hello-opensift 8080-tcp None

5.4 测试访问

[student@workstation ~]$ curl http://hello.apps.lab.example.com #测试http访问
  1 ……
  2       <h1>Application is not available</h1>
  3       <p>The application is currently not serving requests at this endpoint. It may not have been started or is still starting.</p>
  4 ……
[root@node1 ~]# curl http://10.128.0.23:8080 #测试使用pod ip访问
Hello OpenShift!
[root@node1 ~]# curl http://172.30.124.237:8080 #测试使用cluster ip访问
curl: (7) Failed connect to 172.30.124.237:8080; Connection refused

5.5 TS cluster故障

[student@workstation ~]$ oc describe svc hello-openshift -n network-review
clipboard
提示:由上可知,没有endpoint,endpoint是使用selector对pod的label进行匹配。
[student@workstation ~]$ oc describe pod hello-openshift-1-6ls8z #查看pod详情
clipboard
故障点:由上可知,Selector的label不一致,则没有标记为hello_openshift的pod能进行匹配。
[student@workstation ~]$ oc edit svc hello-openshift
  1 ……
  2   selector:
  3     app: hello-openshift
  4     deploymentconfig: hello-openshift
  5   sessionAffinity: None
  6 ……

5.6 测试访问

[root@node1 ~]# curl http://10.128.0.23:8080 #测试使用pod ip访问
Hello OpenShift!
[root@node1 ~]# curl http://172.30.124.237:8080 #再次测试
Hello OpenShift!
[student@workstation ~]$ curl http://hello.apps.lab.example.com #测试http访问
  1 ……
  2       <h1>Application is not available</h1>
  3       <p>The application is currently not serving requests at this endpoint. It may not have been started or is still starting.</p>
  4 ……

5.7 TS route故障

[student@workstation ~]$ oc describe route hello-openshift
clipboard
故障点:由上可知,此路由没有endpoint。即对route的URL请求没有后端endpoint进行响应。路由器查询service的endpoint,并注册有效的endpoint来实现负载平衡。同时发现service名称中有一个拼写错误,它应该是hello-openshift。
[student@workstation ~]$ oc edit route hello-openshift
  1 ……
  2 spec:
  3   host: hello.apps.lab.example.com
  4   port:
  5     targetPort: 8080-tcp
  6   to:
  7     kind: Service
  8     name: hello-openshift
  9     weight: 100
 10   wildcardPolicy: None
 11 ……
[root@node1 ~]# curl http://hello.apps.lab.example.com #再次测试
Hello OpenShift!

5.8 确认验证

[student@workstation ~]$ lab network-review grade #使用脚本判断

发表评论

0/200
57 点赞
0 评论
收藏
为你推荐 换一批