kubernetes集群搭建(6):kubernetes基本使用演示
以简单部署访问来演示kubernetes的基本使用
流程: 用户访问client应用,client应用中调用server应用,由于部署了多节点,client在访问server时应该配置server 暴露的虚拟IP地址
由于DNS暂未配置成功,在client调用server时配置的是server的cluster ip而不是服务名
server端与client端均为springboot web应用
1.代码示例:
server端代码:打包为server.jar
1 @RestController 2 public class PermissionController { 3 4 @RequestMapping("/permission/check") 5 public Result permissionCheck(@RequestBody PermissionParam permissionParam) { 6 7 System.out.println("接收到验证请求:"+JSON.toJSONString(permissionParam)); 8 if(permissionParam.getRequestURI().equals("/permission/test")){ 9 return new Result(); 10 } else { 11 return new Result("x00001","无权限进行此操作"); 12 } 13 } 14 15 16 @RequestMapping("/test") 17 public Result test() { 18 return new Result("访问成功 "+System.currentTimeMillis()); 19 } 20 21 }
client端代码:打包为client.jar
1 @RestController 2 public class PermissionController { 3 4 @Value("${server_url}") 5 private String permissionServerUrl; 6 7 @Autowired 8 PermissionCheckService permissionService; 9 10 @RequestMapping("/permission/test") 11 public Result permissionTest() { 12 return new Result("有权限,访问成功。运行参数为:"+ permissionServerUrl); 13 } 14 15 @RequestMapping("/test") 16 public Result test() { 17 return new Result("访问成功 "+System.currentTimeMillis()); 18 } 19 20 21 }
1 @Service 2 public class PermissionCheckService { 3 @Value("${server_url}") 4 private String permissionServerUrl; 5 6 @Autowired 7 private RestTemplate restTemplate; 8 9 public Result permissionCheck(Long userId, Integer appId, String uri) throws RestClientException, URISyntaxException { 10 ResponseEntity<Result> result = restTemplate.postForEntity(new URI(permissionServerUrl + "/permission/check"), 11 new PermissionParam(userId, appId, uri), Result.class); 12 return result.getBody(); 13 } 14 }
client端拦截器:用于在接收到请求时,调用server端接口验证是否有权限访问
1 package com.phicomm.permission.client.config; 2 3 import javax.servlet.http.HttpServletRequest; 4 import javax.servlet.http.HttpServletResponse; 5 6 import org.springframework.beans.factory.annotation.Autowired; 7 import org.springframework.context.annotation.Bean; 8 import org.springframework.context.annotation.Configuration; 9 import org.springframework.web.servlet.HandlerInterceptor; 10 import org.springframework.web.servlet.ModelAndView; 11 import org.springframework.web.servlet.config.annotation.InterceptorRegistry; 12 import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; 13 14 import com.alibaba.fastjson.JSON; 15 import com.phicomm.permission.client.service.PermissionCheckService; 16 import com.phicomm.permission.lib.Result; 17 18 @Configuration 19 public class InterceptorConfig extends WebMvcConfigurerAdapter { 20 21 @Bean 22 public PermissionCheckInterceptor getPermissionCheckInterceptor() { 23 return new PermissionCheckInterceptor(); 24 } 25 26 @Override 27 public void addInterceptors(InterceptorRegistry registry) { 28 registry.addInterceptor(getPermissionCheckInterceptor()).addPathPatterns("/**").excludePathPatterns("/test"); 29 super.addInterceptors(registry); 30 } 31 32 33 class PermissionCheckInterceptor implements HandlerInterceptor { 34 @Autowired 35 PermissionCheckService permissionCheckService; 36 37 @Override 38 public void afterCompletion(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, Exception arg3) 39 throws Exception { 40 } 41 42 @Override 43 public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, ModelAndView arg3) 44 throws Exception { 45 46 } 47 48 @Override 49 public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object obj) throws Exception { 50 String uri = request.getRequestURI(); 51 Integer appId = 1; 52 System.out.println("开始权限验证:"+ uri); 53 54 Result result = permissionCheckService.permissionCheck(1L, appId, uri); 55 if (result.getStatus().equals(Result.Status.SUCCESS.code())) { 56 return true; 57 } else { 58 response.setContentType("application/json;charset=utf-8"); 59 response.getWriter().write(JSON.toJSONString(result)); 60 return false; 61 } 62 } 63 64 } 65 }
2.docker镜像制作:
a.上传server.jar 和 client.jar 及jdk到docker私服待用(jdk已解压并重命名目录,目的是为了让镜像中的jdk路径清晰易记)
1 [root@localhost ~]# ls -l 2 总用量 231344 3 -rw-------. 1 root root 1231 4月 9 21:24 anaconda-ks.cfg 4 -rw-r--r--. 1 root root 9420658 4月 17 15:29 apache-tomcat-8.0.51.tar.gz 5 -rw-r--r--. 1 root root 22102842 4月 20 15:08 client.jar 6 -rw-r--r--. 1 root root 474 4月 19 09:04 Dockerfile_bak 7 -rw-r--r--. 1 root root 382 4月 20 14:29 DockerfileClient 8 -rw-r--r--. 1 root root 386 4月 23 11:19 DockerfileServer 9 drwxr-xr-x. 8 10 143 255 12月 13 2016 jdk 10 -rw-r--r--. 1 root root 183246769 4月 17 15:26 jdk-8u121-linux-x64.tar.gz 11 -rw-r--r--. 1 root root 22102433 4月 20 13:23 server.jar 12 drwxr-xr-x. 9 root root 160 4月 17 15:29 tomcat 13 [root@localhost ~]#
b.编写镜像制作用Dockerfile
1 [root@localhost ~]# vi DockerfileServer 2 3 FROM centos 4 MAINTAINER changw.xiao@qq.com 5 COPY ./jdk /usr/local/jdk 6 COPY ./server.jar /root/server.jar 7 8 ENV JAVA_HOME /usr/local/jdk 9 ENV JRE_HOME $JAVA_HOME/jre 10 ENV CLASSPATH .:$JAVA_HOME/lib:$JRE_HOME/lib 11 ENV PATH $PATH:$JAVA_HOME/bin 12 ENV CATALINA_OPTS -Xms128m -Xmx1024m -XX:PermSize=64M -XX:MaxPermSize=512M 13 ENTRYPOINT ["java", "-jar", "/root/server.jar", "--server.port=9999"]
1 [root@localhost ~]# vi DockerfileClient 2 3 FROM centos 4 MAINTAINER changw.xiao@qq.com 5 COPY ./jdk /usr/local/jdk 6 COPY ./client.jar /root/client.jar 7 8 ENV JAVA_HOME /usr/local/jdk 9 ENV JRE_HOME $JAVA_HOME/jre 10 ENV CLASSPATH .:$JAVA_HOME/lib:$JRE_HOME/lib 11 ENV PATH $PATH:$JAVA_HOME/bin 12 ENV CATALINA_OPTS -Xms128m -Xmx1024m -XX:PermSize=64M -XX:MaxPermSize=512M 13 ENTRYPOINT ["java","-jar","/root/client.jar","--server.port=9998"]
c.制作镜像并push到docker私库上
1 [root@localhost ~]# docker build -f DockerfileServer -t server:v2 --rm=true . 2 Sending build context to Docker daemon 622.6 MB 3 Step 1/10 : FROM centos 4 ---> e934aafc2206 5 Step 2/10 : MAINTAINER changw.xiao@qq.com 6 ---> Using cache 7 ---> 72ab25d99688 8 Step 3/10 : COPY ./jdk /usr/local/jdk 9 ---> Using cache 10 ---> 527d6efcf1eb 11 Step 4/10 : COPY ./server.jar /root/server.jar 12 ---> Using cache 13 ---> 7d6ad5d000af 14 Step 5/10 : ENV JAVA_HOME /usr/local/jdk 15 ---> Using cache 16 ---> 99a7bfe20a2c 17 Step 6/10 : ENV JRE_HOME $JAVA_HOME/jre 18 ---> Using cache 19 ---> 65fa863798ba 20 Step 7/10 : ENV CLASSPATH .:$JAVA_HOME/lib:$JRE_HOME/lib 21 ---> Using cache 22 ---> 4884da8b0a46 23 Step 8/10 : ENV PATH $PATH:$JAVA_HOME/bin 24 ---> Using cache 25 ---> 342ae4b430ce 26 Step 9/10 : ENV CATALINA_OPTS -Xms128m -Xmx1024m -XX:PermSize=64M -XX:MaxPermSize=512M 27 ---> Using cache 28 ---> 9f4f69bba1a8 29 Step 10/10 : ENTRYPOINT java -jar /root/server.jar --server.port=9999 30 ---> Using cache 31 ---> adba02d66112 32 Successfully built adba02d66112 33 [root@localhost ~]# docker tag server:v2 127.0.0.1:5000/server:v2 34 [root@localhost ~]# docker push 127.0.0.1:5000/server:v2 35 The push refers to a repository [127.0.0.1:5000/server] 36 d791b1f51432: Layer already exists 37 3d8fe6c21563: Layer already exists 38 43e653f84b79: Layer already exists 39 v2: digest: sha256:0cdc81e870c533efb7d60be2452fdfce2f0b0186d0568537e9a67d205262e7c6 size: 954 40 [root@localhost ~]# docker images |grep server 41 127.0.0.1:5000/server v1 adba02d66112 2 days ago 591 MB 42 127.0.0.1:5000/server v2 adba02d66112 2 days ago 591 MB 43 server v1 adba02d66112 2 days ago 591 MB 44 server v2 adba02d66112 2 days ago 591 MB 45 [root@localhost ~]#
1 [root@localhost ~]# docker build -f DockerfileClient -t client:v2 --rm=true . 2 Sending build context to Docker daemon 622.6 MB 3 Step 1/10 : FROM centos 4 ---> e934aafc2206 5 Step 2/10 : MAINTAINER changw.xiao@qq.com 6 ---> Using cache 7 ---> 72ab25d99688 8 Step 3/10 : COPY ./jdk /usr/local/jdk 9 ---> Using cache 10 ---> 527d6efcf1eb 11 Step 4/10 : COPY ./client.jar /root/client.jar 12 ---> Using cache 13 ---> 397a279f72b9 14 Step 5/10 : ENV JAVA_HOME /usr/local/jdk 15 ---> Using cache 16 ---> e553d3e47099 17 Step 6/10 : ENV JRE_HOME $JAVA_HOME/jre 18 ---> Using cache 19 ---> 019ed6b62619 20 Step 7/10 : ENV CLASSPATH .:$JAVA_HOME/lib:$JRE_HOME/lib 21 ---> Using cache 22 ---> 9fa826201e2b 23 Step 8/10 : ENV PATH $PATH:$JAVA_HOME/bin 24 ---> Using cache 25 ---> 5922592036e7 26 Step 9/10 : ENV CATALINA_OPTS -Xms128m -Xmx1024m -XX:PermSize=64M -XX:MaxPermSize=512M 27 ---> Using cache 28 ---> c563bf822200 29 Step 10/10 : ENTRYPOINT java -jar /root/client.jar --server.port=9998 30 ---> Using cache 31 ---> 6b9a0358f207 32 Successfully built 6b9a0358f207 33 [root@localhost ~]# docker tag client:v2 127.0.0.1:5000/client:v2 34 [root@localhost ~]# docker push 127.0.0.1:5000/client:v2 35 The push refers to a repository [127.0.0.1:5000/client] 36 8e2aa24bef0a: Layer already exists 37 3d8fe6c21563: Layer already exists 38 43e653f84b79: Layer already exists 39 v2: digest: sha256:a3d77ff85edb5272eb22d57b6bfd5ae6052b5903eaf7b09b256de2304207b905 size: 954 40 [root@localhost ~]# docker images |grep client 41 127.0.0.1:5000/client v1 6b9a0358f207 2 days ago 591 MB 42 127.0.0.1:5000/client v2 6b9a0358f207 2 days ago 591 MB 43 client v1 6b9a0358f207 2 days ago 591 MB 44 client v2 6b9a0358f207 2 days ago 591 MB 45 [root@localhost ~]#
3.server端rc配置与部署
3.1.创建server-rc.yaml配置文件
1 [root@k8s-master ~]# vi server-rc.yaml 2 3 apiVersion: v1 4 kind: ReplicationController #指名类型为rc 5 metadata: 6 name: serverrc #rc 名字,创建后的pod名字为 serverrc-随机字符 7 spec: 8 replicas: 2 #指定副本数量,会一直维持这个数量的副本,如果某节点挂掉,又会立即构建新的来替代 9 template: 10 metadata: 11 labels: 12 app: server #app名字,相同的名字代表是同一个应用,service会按这个名字来做负载 13 spec: 14 containers: 15 - name: server 16 image: 192.168.100.6:5000/server:v1 #镜像源 17 ports: 18 - containerPort: 9999 #容器端口
3.2.启动server-rc
kubectl create -f /root/server-rc.yaml
3.3.确认启动是否成功
[root@k8s-master ~]# kubectl get pods --all-namespaces | grep serverrc
default serverrc-3qprz 1/1 Running 0 3h
default serverrc-8s274 1/1 Running 0 3h
注意:kubectl get pods默认只显示namespace为default下的,要显示全部 需加上 --all-namespances
3.4.查看详情或错误信息
[root@k8s-master ~]# kubectl describe pod serverrc-3qprz Name: serverrc-3qprz Namespace: default Node: k8s-node1/192.168.100.5 #在哪个节点上部署的 Start Time: Mon, 23 Apr 2018 08:53:06 +0800 Labels: app=server Status: Running IP: 172.16.49.2 #容器内对应的ip信息(之前master上 etcdctl mk /atomic.io/network/config '{"Network":"172.16.0.0/16"}' 配置的ip范围内) Controllers: ReplicationController/serverrc Containers: server: Container ID: docker://00a7c4c588f2d7593bf0bbe6fd07350903f96e00f6e75278283e054580731a4f Image: 192.168.100.6:5000/server:v1 #使用的镜像 Image ID: docker-pullable://192.168.100.6:5000/server@sha256:0cdc81e870c533efb7d60be2452fdfce2f0b0186d0568537e9a67d205262e7c6 Port: 9999/TCP #端口信息 State: Running Started: Mon, 23 Apr 2018 08:53:06 +0800 Ready: True Restart Count: 0 Volume Mounts: <none> Environment Variables: <none> Conditions: Type Status Initialized True Ready True PodScheduled True No volumes. QoS Class: BestEffort Tolerations: <none> No events.#如果没启动成功,这里会有错误信息,根据错误信息不断修改配置最终才会成功 [root@k8s-master ~]#
3.5.测试应用是否部署成功
[root@k8s-master ~]# curl 172.16.49.2:9999/test
{"content":"访问成功 1524458561072","status":"OK","errorCode":null,"errorMsg":null}
[root@k8s-master ~]#
[root@k8s-master ~]#
4.server端service配置与部署
4.1. 由于server端部署的节点可以为多个(本示例仅2个),怎么给client调用方提供唯一的请求地址呢?
传统部署方式一般会在前段做一个负载均衡,提供唯一的地址供调用方使用
但由于kubernets部署环境下,node会因各种情况重建,ip信息也会变化,传统方式已经不再满足需要
可喜的是kubernets提供了service,service就是将同一名字的app信息收集后在前端提供了cluster_ip(重建会变化)和服务名(重建不会变化),
功能和负载均衡一样,但node的销毁、重建不需要用户关心,调用方也只需要知道服务名即可,无需知道node节点任何信息
4.2. 创建server-svc.yaml文件
[root@k8s-master ~]# vi server-svc.yaml apiVersion: v1 kind: Service #指定种类为service metadata: name: serversvc #service 名字 提供给调用方使用,调用方无需知道ip 由dns解析服务名为cluster ip labels: app: server #rc的名字,service将同一名字的rc作为后端node进行负载 spec: ports: - port: 9001 #service暴露在cluster ip上的端口,clusterIP:port 是提供给集群内部客户访问service的入口 targetPort: 9999 #pod上的端口,从port和nodePort上到来的数据最终经过kube-proxy流入到后端pod的targetPort上进入容器,和rc中的containerPort一致
nodePort: 30001 #提供给集群外部客户访问service的入口
protocol: TCP
selector:
app: server
type: NodePort
4.3.创建service 并确认创建成功
kubectl create -f server-svc.yaml
[root@k8s-master ~]# kubectl get svc --all-namespaces NAMESPACE NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE default kubernetes 10.254.0.1 <none> 443/TCP 4h default serversvc 10.254.77.154 <nodes> 9001:30001/TCP 4h kube-system kube-dns 10.254.0.2 <none> 53/UDP,53/TCP 2d [root@k8s-master ~]#
4.4.查看svc详情
[root@k8s-master ~]# kubectl describe svc serversvc Name: serversvc #服务名,调用方就根据服务名来调用,因为随着svc重建,cluster_ip也会变更的 Namespace: default Labels: app=server Selector: app=server Type: NodePort IP: 10.254.77.154 #这个即为cluster_ip,相当于nginx做负载均衡时 nginx的ip地址 Port: <unset> 9001/TCP NodePort: <unset> 30001/TCP Endpoints: 172.16.20.2:9999,172.16.49.2:9999 #这个为service负载的节点ip和端口 Session Affinity: None No events. #如果有错,这里会有很多行日志 [root@k8s-master ~]#
4.5.测试访问
[root@k8s-master ~]# curl 172.16.49.2:9999/test #直接通过nodeIP:port 访问成功
{"content":"访问成功 1524460721254","status":"OK","errorCode":null,"errorMsg":null}
[root@k8s-master ~]#
[root@k8s-master ~]# curl 172.16.20.2:9999/test #访问另一节点也成功
{"content":"访问成功 1524460728456","status":"OK","errorCode":null,"errorMsg":null}
[root@k8s-master ~]#
[root@k8s-master ~]# curl 10.254.77.154:9001/test #直接访问cluster_ip 没成功? 其实这里必须要到容器内部才能访问
curl: (7) Failed connect to 10.254.77.154:9001; 拒绝连接
[root@k8s-master ~]#
[root@k8s-master ~]# kubectl exec -it clientrc-8qk3z /bin/bash
[root@clientrc-8qk3z /]# curl 10.254.77.154:9001/test #进入容器内部访问cluster_ip 成功
{"content":"访问成功 1524460861212","status":"OK","errorCode":null,"errorMsg":null}
[root@clientrc-8qk3z /]#
[root@clientrc-8qk3z /]# exit
exit
[root@k8s-master ~]#
5.client端rc创建 并调用server端接口
5.1.client-rc.yaml
1 apiVersion: v1 2 kind: ReplicationController 3 metadata: 4 name: clientrc 5 spec: 6 replicas: 2 #节点数量 7 template: 8 metadata: 9 labels: 10 app: client 11 spec: 12 containers: 13 - name: client 14 image: 192.168.100.6:5000/client:v1 15 ports: 16 - containerPort: 9998 #容器端口 17 env: #增加了环境变量,用来配置server端地址 18 - name: server_url #变量名 19 value: 'http://10.254.77.154:9001/' #变量值,由于我的dns没配置好,所以这里使用了server端的service cluster_ip,如果配置好了dns 这里应该为 value: 'http://serversvc:9001/'
5.2.创建client rc
kubectl create -f client-rc.yaml
5.3.确认启动状态
[root@k8s-master ~]# kubectl get pods --all-namespaces |grep client
default clientrc-8qk3z 1/1 Running 0 4h
default clientrc-hqs06 1/1 Running 0 4h
[root@k8s-master ~]#
[root@k8s-master ~]# kubectl get pods -l app=client -o json | grep podIP
"podIP": "172.16.60.3",
"podIP": "172.16.20.3",
[root@k8s-master ~]#
5.4.client两个节点访问
[root@k8s-master ~]# curl 172.16.60.3:9998/test
{"content":"访问成功 1524461788548","status":"OK","errorCode":null,"errorMsg":null}
[root@k8s-master ~]#
[root@k8s-master ~]# curl 172.16.20.3:9998/test
{"content":"访问成功 1524461800005","status":"OK","errorCode":null,"errorMsg":null}
[root@k8s-master ~]#
5.5.client端调用server端服务
在client端发送需要被拦截器拦截的请求,从而达到调用server端接口的目的
[root@k8s-master ~]# curl 172.16.60.3:9998/permission/test
{"content":"有权限,访问成功。运行参数为:http://10.254.77.154:9001/","status":"OK","errorCode":null,"errorMsg":null}
[root@k8s-master ~]# curl 172.16.60.3:9998/permission/test2
{"errorCode":"x00001","errorMsg":"无权限进行此操作","status":"ERROR"}[root@k8s-master ~]#
通过logs来查看各容器的输出log
kubectl logs serverrc-8s274
server端的日志为:
1 [root@k8s-master ~]# kubectl logs serverrc-8s274 2 . ____ _ __ _ _ 3 /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ 4 ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ 5 \\/ ___)| |_)| | | | | || (_| | ) ) ) ) 6 ' |____| .__|_| |_|_| |_\__, | / / / / 7 =========|_|==============|___/=/_/_/_/ 8 :: Spring Boot :: (v2.0.1.RELEASE) 9 2018-04-23 00:53:11.716 INFO 1 --- [ main] c.p.p.s.PermissionServerApplication : Starting PermissionServerApplication v0.0.1-SNAPSHOT on serverrc-8s274 with PID 1 (/root/server.jar started by root in /) 10 2018-04-23 00:53:11.737 INFO 1 --- [ main] c.p.p.s.PermissionServerApplication : No active profile set, falling back to default profiles: default 11 2018-04-23 00:53:11.993 INFO 1 --- [ main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@574caa3f: startup date [Mon Apr 23 00:53:11 UTC 2018]; root of context hierarchy 12 2018-04-23 00:53:16.425 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 9999 (http) 13 2018-04-23 00:53:16.500 INFO 1 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat] 14 2018-04-23 00:53:16.501 INFO 1 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.29 15 2018-04-23 00:53:16.569 INFO 1 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib] 16 2018-04-23 00:53:16.864 INFO 1 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 17 2018-04-23 00:53:16.864 INFO 1 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 4932 ms 18 2018-04-23 00:53:17.107 INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Servlet statViewServlet mapped to [/druid/*] 19 2018-04-23 00:53:17.111 INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Servlet dispatcherServlet mapped to [/] 20 2018-04-23 00:53:17.114 INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*] 21 2018-04-23 00:53:17.114 INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*] 22 2018-04-23 00:53:17.114 INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*] 23 2018-04-23 00:53:17.114 INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*] 24 2018-04-23 00:53:17.114 INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'webStatFilter' to urls: [/*] 25 2018-04-23 00:53:17.873 INFO 1 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 26 2018-04-23 00:53:18.366 INFO 1 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@574caa3f: startup date [Mon Apr 23 00:53:11 UTC 2018]; root of context hierarchy 27 2018-04-23 00:53:18.542 INFO 1 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/permission/check]}" onto public com.phicomm.permission.lib.Result com.phicomm.permission.server.controller.PermissionController.permissionCheck(com.phicomm.permission.lib.PermissionParam) 28 2018-04-23 00:53:18.543 INFO 1 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/test]}" onto public com.phicomm.permission.lib.Result com.phicomm.permission.server.controller.PermissionController.test() 29 2018-04-23 00:53:18.556 INFO 1 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) 30 2018-04-23 00:53:18.557 INFO 1 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest) 31 2018-04-23 00:53:18.610 INFO 1 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 32 2018-04-23 00:53:18.610 INFO 1 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 33 2018-04-23 00:53:19.002 INFO 1 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup 34 2018-04-23 00:53:19.003 INFO 1 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'druidDataSource' has been autodetected for JMX exposure 35 2018-04-23 00:53:19.018 INFO 1 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Located MBean 'druidDataSource': registering with JMX server as MBean [com.alibaba.druid.pool:name=druidDataSource,type=DruidDataSource] 36 2018-04-23 00:53:19.357 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 9999 (http) with context path '' 37 2018-04-23 00:53:19.373 INFO 1 --- [ main] c.p.p.s.PermissionServerApplication : Started PermissionServerApplication in 8.942 seconds (JVM running for 12.022) 38 2018-04-23 00:55:59.133 INFO 1 --- [nio-9999-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring FrameworkServlet 'dispatcherServlet' 39 2018-04-23 00:55:59.135 INFO 1 --- [nio-9999-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization started 40 2018-04-23 00:55:59.157 INFO 1 --- [nio-9999-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization completed in 22 ms 41 ????????{"appId":1,"requestURI":"/permission/test","userId":1} 42 ????????{"appId":1,"requestURI":"/permission/test2","userId":1} 43 [root@k8s-master ~]#
1 [root@k8s-master ~]# kubectl logs clientrc-8qk3z 2 . ____ _ __ _ _ 3 /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ 4 ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ 5 \\/ ___)| |_)| | | | | || (_| | ) ) ) ) 6 ' |____| .__|_| |_|_| |_\__, | / / / / 7 =========|_|==============|___/=/_/_/_/ 8 :: Spring Boot :: (v2.0.1.RELEASE) 9 2018-04-23 00:57:36.442 INFO 1 --- [ main] c.p.p.c.PermissionClientApplication : Starting PermissionClientApplication v0.0.1-SNAPSHOT on clientrc-8qk3z with PID 1 (/root/client.jar started by root in /) 10 2018-04-23 00:57:36.493 INFO 1 --- [ main] c.p.p.c.PermissionClientApplication : No active profile set, falling back to default profiles: default 11 2018-04-23 00:57:37.023 INFO 1 --- [ main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@6d1e7682: startup date [Mon Apr 23 00:57:36 UTC 2018]; root of context hierarchy 12 2018-04-23 00:57:41.401 WARN 1 --- [ main] o.m.s.mapper.ClassPathMapperScanner : No MyBatis mapper was found in '[com.phicomm.permission.client]' package. Please check your configuration. 13 2018-04-23 00:57:44.780 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 9998 (http) 14 2018-04-23 00:57:44.850 INFO 1 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat] 15 2018-04-23 00:57:44.851 INFO 1 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.29 16 2018-04-23 00:57:44.863 INFO 1 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib] 17 2018-04-23 00:57:45.035 INFO 1 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 18 2018-04-23 00:57:45.042 INFO 1 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 8176 ms 19 2018-04-23 00:57:45.312 INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Servlet dispatcherServlet mapped to [/] 20 2018-04-23 00:57:45.316 INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*] 21 2018-04-23 00:57:45.316 INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*] 22 2018-04-23 00:57:45.316 INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*] 23 2018-04-23 00:57:45.316 INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*] 24 2018-04-23 00:57:45.872 INFO 1 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 25 2018-04-23 00:57:46.873 INFO 1 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@6d1e7682: startup date [Mon Apr 23 00:57:36 UTC 2018]; root of context hierarchy 26 2018-04-23 00:57:47.121 INFO 1 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/permission/test]}" onto public com.phicomm.permission.lib.Result com.phicomm.permission.client.controller.PermissionController.permissionTest() 27 2018-04-23 00:57:47.124 INFO 1 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/test]}" onto public com.phicomm.permission.lib.Result com.phicomm.permission.client.controller.PermissionController.test() 28 2018-04-23 00:57:47.128 INFO 1 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) 29 2018-04-23 00:57:47.128 INFO 1 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest) 30 2018-04-23 00:57:47.186 INFO 1 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 31 2018-04-23 00:57:47.186 INFO 1 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 32 2018-04-23 00:57:48.796 INFO 1 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup 33 2018-04-23 00:57:48.799 INFO 1 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'dataSource' has been autodetected for JMX exposure 34 2018-04-23 00:57:48.870 INFO 1 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Located MBean 'dataSource': registering with JMX server as MBean [com.alibaba.druid.pool:name=dataSource,type=DruidDataSource] 35 2018-04-23 00:57:49.367 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 9998 (http) with context path '' 36 2018-04-23 00:57:49.378 INFO 1 --- [ main] c.p.p.c.PermissionClientApplication : Started PermissionClientApplication in 16.264 seconds (JVM running for 22.435) 37 2018-04-23 01:00:25.246 INFO 1 --- [nio-9998-exec-2] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring FrameworkServlet 'dispatcherServlet' 38 2018-04-23 01:00:25.246 INFO 1 --- [nio-9998-exec-2] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization started 39 2018-04-23 01:00:25.283 INFO 1 --- [nio-9998-exec-2] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization completed in 37 ms 40 ???????/permission/test 41 ???????/permission/test2
至此,在kubernetes中应用间相互调用基本演示完毕(dns配置服务发现暂未成功)