kubernetes集群搭建(6):kubernetes基本使用演示

时间:2023-02-25 12:11:10

以简单部署访问来演示kubernetes的基本使用

kubernetes集群搭建(6):kubernetes基本使用演示

流程: 用户访问client应用,client应用中调用server应用,由于部署了多节点,client在访问server时应该配置server 暴露的虚拟IP地址

由于DNS暂未配置成功,在client调用server时配置的是server的cluster ip而不是服务名

server端与client端均为springboot web应用

1.代码示例:

server端代码:打包为server.jar

 @RestController
public class PermissionController { @RequestMapping("/permission/check")
public Result permissionCheck(@RequestBody PermissionParam permissionParam) { System.out.println("接收到验证请求:"+JSON.toJSONString(permissionParam));
if(permissionParam.getRequestURI().equals("/permission/test")){
return new Result();
} else {
return new Result("x00001","无权限进行此操作");
}
} @RequestMapping("/test")
public Result test() {
return new Result("访问成功 "+System.currentTimeMillis());
} }

client端代码:打包为client.jar

 @RestController
public class PermissionController { @Value("${server_url}")
private String permissionServerUrl; @Autowired
PermissionCheckService permissionService; @RequestMapping("/permission/test")
public Result permissionTest() {
return new Result("有权限,访问成功。运行参数为:"+ permissionServerUrl);
} @RequestMapping("/test")
public Result test() {
return new Result("访问成功 "+System.currentTimeMillis());
} }

Controller

 @Service
public class PermissionCheckService {
@Value("${server_url}")
private String permissionServerUrl; @Autowired
private RestTemplate restTemplate; public Result permissionCheck(Long userId, Integer appId, String uri) throws RestClientException, URISyntaxException {
ResponseEntity<Result> result = restTemplate.postForEntity(new URI(permissionServerUrl + "/permission/check"),
new PermissionParam(userId, appId, uri), Result.class);
return result.getBody();
}
}

service

client端拦截器:用于在接收到请求时,调用server端接口验证是否有权限访问

 package com.phicomm.permission.client.config;

 import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; import com.alibaba.fastjson.JSON;
import com.phicomm.permission.client.service.PermissionCheckService;
import com.phicomm.permission.lib.Result; @Configuration
public class InterceptorConfig extends WebMvcConfigurerAdapter { @Bean
public PermissionCheckInterceptor getPermissionCheckInterceptor() {
return new PermissionCheckInterceptor();
} @Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(getPermissionCheckInterceptor()).addPathPatterns("/**").excludePathPatterns("/test");
super.addInterceptors(registry);
} class PermissionCheckInterceptor implements HandlerInterceptor {
@Autowired
PermissionCheckService permissionCheckService; @Override
public void afterCompletion(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, Exception arg3)
throws Exception {
} @Override
public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, ModelAndView arg3)
throws Exception { } @Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object obj) throws Exception {
String uri = request.getRequestURI();
Integer appId = 1;
System.out.println("开始权限验证:"+ uri); Result result = permissionCheckService.permissionCheck(1L, appId, uri);
if (result.getStatus().equals(Result.Status.SUCCESS.code())) {
return true;
} else {
response.setContentType("application/json;charset=utf-8");
response.getWriter().write(JSON.toJSONString(result));
return false;
}
} }
}

PermissionCheckInterceptor

2.docker镜像制作:

  a.上传server.jar 和 client.jar 及jdk到docker私服待用(jdk已解压并重命名目录,目的是为了让镜像中的jdk路径清晰易记)

 [root@localhost ~]# ls -l
总用量 231344
-rw-------. 1 root root 1231 4月 9 21:24 anaconda-ks.cfg
-rw-r--r--. 1 root root 9420658 4月 17 15:29 apache-tomcat-8.0.51.tar.gz
-rw-r--r--. 1 root root 22102842 4月 20 15:08 client.jar
-rw-r--r--. 1 root root 474 4月 19 09:04 Dockerfile_bak
-rw-r--r--. 1 root root 382 4月 20 14:29 DockerfileClient
-rw-r--r--. 1 root root 386 4月 23 11:19 DockerfileServer
drwxr-xr-x. 8 10 143 255 12月 13 2016 jdk
-rw-r--r--. 1 root root 183246769 4月 17 15:26 jdk-8u121-linux-x64.tar.gz
-rw-r--r--. 1 root root 22102433 4月 20 13:23 server.jar
drwxr-xr-x. 9 root root 160 4月 17 15:29 tomcat
[root@localhost ~]#

镜像所需文件

  b.编写镜像制作用Dockerfile

 [root@localhost ~]# vi DockerfileServer 

 FROM centos
MAINTAINER changw.xiao@qq.com
COPY ./jdk /usr/local/jdk
COPY ./server.jar /root/server.jar ENV JAVA_HOME /usr/local/jdk
ENV JRE_HOME $JAVA_HOME/jre
ENV CLASSPATH .:$JAVA_HOME/lib:$JRE_HOME/lib
ENV PATH $PATH:$JAVA_HOME/bin
ENV CATALINA_OPTS -Xms128m -Xmx1024m -XX:PermSize=64M -XX:MaxPermSize=512M
ENTRYPOINT ["java", "-jar", "/root/server.jar", "--server.port=9999"]

DockerfileServer

 [root@localhost ~]# vi DockerfileClient 

 FROM centos
MAINTAINER changw.xiao@qq.com
COPY ./jdk /usr/local/jdk
COPY ./client.jar /root/client.jar ENV JAVA_HOME /usr/local/jdk
ENV JRE_HOME $JAVA_HOME/jre
ENV CLASSPATH .:$JAVA_HOME/lib:$JRE_HOME/lib
ENV PATH $PATH:$JAVA_HOME/bin
ENV CATALINA_OPTS -Xms128m -Xmx1024m -XX:PermSize=64M -XX:MaxPermSize=512M
ENTRYPOINT ["java","-jar","/root/client.jar","--server.port=9998"]

DockerfileClient

  c.制作镜像并push到docker私库上

 [root@localhost ~]# docker build -f DockerfileServer  -t server:v2 --rm=true .
Sending build context to Docker daemon 622.6 MB
Step 1/10 : FROM centos
---> e934aafc2206
Step 2/10 : MAINTAINER changw.xiao@qq.com
---> Using cache
---> 72ab25d99688
Step 3/10 : COPY ./jdk /usr/local/jdk
---> Using cache
---> 527d6efcf1eb
Step 4/10 : COPY ./server.jar /root/server.jar
---> Using cache
---> 7d6ad5d000af
Step 5/10 : ENV JAVA_HOME /usr/local/jdk
---> Using cache
---> 99a7bfe20a2c
Step 6/10 : ENV JRE_HOME $JAVA_HOME/jre
---> Using cache
---> 65fa863798ba
Step 7/10 : ENV CLASSPATH .:$JAVA_HOME/lib:$JRE_HOME/lib
---> Using cache
---> 4884da8b0a46
Step 8/10 : ENV PATH $PATH:$JAVA_HOME/bin
---> Using cache
---> 342ae4b430ce
Step 9/10 : ENV CATALINA_OPTS -Xms128m -Xmx1024m -XX:PermSize=64M -XX:MaxPermSize=512M
---> Using cache
---> 9f4f69bba1a8
Step 10/10 : ENTRYPOINT java -jar /root/server.jar --server.port=9999
---> Using cache
---> adba02d66112
Successfully built adba02d66112
[root@localhost ~]# docker tag server:v2 127.0.0.1:5000/server:v2
[root@localhost ~]# docker push 127.0.0.1:5000/server:v2
The push refers to a repository [127.0.0.1:5000/server]
d791b1f51432: Layer already exists
3d8fe6c21563: Layer already exists
43e653f84b79: Layer already exists
v2: digest: sha256:0cdc81e870c533efb7d60be2452fdfce2f0b0186d0568537e9a67d205262e7c6 size: 954
[root@localhost ~]# docker images |grep server
127.0.0.1:5000/server v1 adba02d66112 2 days ago 591 MB
127.0.0.1:5000/server v2 adba02d66112 2 days ago 591 MB
server v1 adba02d66112 2 days ago 591 MB
server v2 adba02d66112 2 days ago 591 MB
[root@localhost ~]#

server端镜像server:v2制作

 [root@localhost ~]# docker build -f DockerfileClient  -t client:v2 --rm=true .
Sending build context to Docker daemon 622.6 MB
Step 1/10 : FROM centos
---> e934aafc2206
Step 2/10 : MAINTAINER changw.xiao@qq.com
---> Using cache
---> 72ab25d99688
Step 3/10 : COPY ./jdk /usr/local/jdk
---> Using cache
---> 527d6efcf1eb
Step 4/10 : COPY ./client.jar /root/client.jar
---> Using cache
---> 397a279f72b9
Step 5/10 : ENV JAVA_HOME /usr/local/jdk
---> Using cache
---> e553d3e47099
Step 6/10 : ENV JRE_HOME $JAVA_HOME/jre
---> Using cache
---> 019ed6b62619
Step 7/10 : ENV CLASSPATH .:$JAVA_HOME/lib:$JRE_HOME/lib
---> Using cache
---> 9fa826201e2b
Step 8/10 : ENV PATH $PATH:$JAVA_HOME/bin
---> Using cache
---> 5922592036e7
Step 9/10 : ENV CATALINA_OPTS -Xms128m -Xmx1024m -XX:PermSize=64M -XX:MaxPermSize=512M
---> Using cache
---> c563bf822200
Step 10/10 : ENTRYPOINT java -jar /root/client.jar --server.port=9998
---> Using cache
---> 6b9a0358f207
Successfully built 6b9a0358f207
[root@localhost ~]# docker tag client:v2 127.0.0.1:5000/client:v2
[root@localhost ~]# docker push 127.0.0.1:5000/client:v2
The push refers to a repository [127.0.0.1:5000/client]
8e2aa24bef0a: Layer already exists
3d8fe6c21563: Layer already exists
43e653f84b79: Layer already exists
v2: digest: sha256:a3d77ff85edb5272eb22d57b6bfd5ae6052b5903eaf7b09b256de2304207b905 size: 954
[root@localhost ~]# docker images |grep client
127.0.0.1:5000/client v1 6b9a0358f207 2 days ago 591 MB
127.0.0.1:5000/client v2 6b9a0358f207 2 days ago 591 MB
client v1 6b9a0358f207 2 days ago 591 MB
client v2 6b9a0358f207 2 days ago 591 MB
[root@localhost ~]#

client端镜像client:v2制作

3.server端rc配置与部署

  3.1.创建server-rc.yaml配置文件

 [root@k8s-master ~]# vi server-rc.yaml 

 apiVersion: v1
kind: ReplicationController #指名类型为rc
metadata:
name: serverrc #rc 名字,创建后的pod名字为 serverrc-随机字符
spec:
replicas: 2  #指定副本数量,会一直维持这个数量的副本,如果某节点挂掉,又会立即构建新的来替代  
template:
metadata:
labels:
app: server  #app名字,相同的名字代表是同一个应用,service会按这个名字来做负载
spec:
containers:
- name: server  
image: 192.168.100.6:5000/server:v1 #镜像源
ports:
- 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

 apiVersion: v1
kind: ReplicationController
metadata:
name: clientrc
spec:
replicas: 2 #节点数量
template:
metadata:
labels:
app: client
spec:
containers:
- name: client
image: 192.168.100.6:5000/client:v1
ports:
- containerPort: 9998 #容器端口
env:            #增加了环境变量,用来配置server端地址      
- name: server_url    #变量名
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端的日志为:

 [root@k8s-master ~]# kubectl logs serverrc-8s274
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.0.1.RELEASE)
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 /)
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
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
2018-04-23 00:53:16.425 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 9999 (http)
2018-04-23 00:53:16.500 INFO 1 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2018-04-23 00:53:16.501 INFO 1 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.29
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]
2018-04-23 00:53:16.864 INFO 1 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2018-04-23 00:53:16.864 INFO 1 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 4932 ms
2018-04-23 00:53:17.107 INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Servlet statViewServlet mapped to [/druid/*]
2018-04-23 00:53:17.111 INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Servlet dispatcherServlet mapped to [/]
2018-04-23 00:53:17.114 INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2018-04-23 00:53:17.114 INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2018-04-23 00:53:17.114 INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2018-04-23 00:53:17.114 INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2018-04-23 00:53:17.114 INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'webStatFilter' to urls: [/*]
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]
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
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)
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()
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)
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)
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]
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]
2018-04-23 00:53:19.002 INFO 1 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
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
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]
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 ''
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)
2018-04-23 00:55:59.133 INFO 1 --- [nio-9999-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring FrameworkServlet 'dispatcherServlet'
2018-04-23 00:55:59.135 INFO 1 --- [nio-9999-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization started
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
????????{"appId":1,"requestURI":"/permission/test","userId":1}
????????{"appId":1,"requestURI":"/permission/test2","userId":1}
[root@k8s-master ~]#

server端其中一个node日志

 [root@k8s-master ~]# kubectl logs clientrc-8qk3z
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.0.1.RELEASE)
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 /)
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
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
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.
2018-04-23 00:57:44.780 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 9998 (http)
2018-04-23 00:57:44.850 INFO 1 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2018-04-23 00:57:44.851 INFO 1 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.29
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]
2018-04-23 00:57:45.035 INFO 1 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2018-04-23 00:57:45.042 INFO 1 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 8176 ms
2018-04-23 00:57:45.312 INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Servlet dispatcherServlet mapped to [/]
2018-04-23 00:57:45.316 INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2018-04-23 00:57:45.316 INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2018-04-23 00:57:45.316 INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2018-04-23 00:57:45.316 INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
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]
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
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()
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()
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)
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)
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]
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]
2018-04-23 00:57:48.796 INFO 1 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
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
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]
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 ''
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)
2018-04-23 01:00:25.246 INFO 1 --- [nio-9998-exec-2] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring FrameworkServlet 'dispatcherServlet'
2018-04-23 01:00:25.246 INFO 1 --- [nio-9998-exec-2] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization started
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
???????/permission/test
???????/permission/test2

cient端某一个node日志

至此,在kubernetes中应用间相互调用基本演示完毕(dns配置服务发现暂未成功)

kubernetes集群搭建(6):kubernetes基本使用演示的更多相关文章

  1. Kubernetes集群搭建之企业级环境中基于Harbor搭建自己的私有仓库

    搭建背景 企业环境中使用Docker环境,一般出于安全考虑,业务使用的镜像一般不会从第三方公共仓库下载.那么就要引出今天的主题 企业级环境中基于Harbor搭建自己的安全认证仓库 介绍 名称:Harb ...

  2. kubernetes集群搭建(2):docker私有仓库

    kubernetes集群搭建(1):环境准备 中各节点已经安装好了docker,请确认docker已启动并正常运行 1.通过命令启动私库 docker run -d -p 5000:5000 --pr ...

  3. Centos 7 kubernetes集群搭建

    一.环境准备 Kubernetes支持在物理服务器或虚拟机中运行,本次使用虚拟机准备测试环境,硬件配置信息如表所示: IP地址 节点角色 CPU Memory Hostname 磁盘 192.168. ...

  4. Kubernetes集群搭建过程中遇到的问题

    1. 创建Nginx Pod过程中报如下错误: #kubectlcreate -f nginx-pod.yaml Error from server: error when creating &quo ...

  5. Kubernetes集群搭建之系统初始化配置篇

    Kubernetes的几种部署方式 1. minikube Minikube是一个工具,可以在本地快速运行一个单点的Kubernetes,尝试Kubernetes或日常开发的用户使用.不能用于生产环境 ...

  6. Kubernetes集群搭建 ver1&period;20&period;5

    目录 部署方式 1. 基础环境准备 1.1 基础初始化 1.2 安装docker 2. 部署harbor及haproxy高可用反向代理 2.1 镜像加速配置 2.2 高可用master可配置 3. 初 ...

  7. &lbrack;云原生&rsqb;Kubernetes - 集群搭建(第2章)

    目录 一.前置知识点 二.kubeadm部署方式介绍 三.安装要求 四.最终目标 五.准备环境 六.环境初始化 6.1 设置系统主机名以及Hosts文件的相互解析 6.2 安装依赖文件(所有节点) 6 ...

  8. Ceph集群搭建及Kubernetes上实现动态存储(StorageClass)

    集群准备 ceph集群配置说明   节点名称 IP地址 配置 作用 ceph-moni-0 10.10.3.150 centos7.5 4C,16G,200Disk 管理节点,监视器 monitor ...

  9. Kubernetes集群搭建之Master配置篇

    本次系列使用的所需部署包版本都使用的目前最新的或最新稳定版,安装包地址请到公众号内回复[K8s实战]获取 今天终于到正题了~~ 生成kubernets证书与私钥 1. 制作kubernetes ca证 ...

  10. kubernetes集群搭建

    工作环境: 主机名 IP 系统 master 192.168.199.6 rhel7.4 node1 192.168.199.7 rhel7.4 node2 192.168.199.8 rhel7.4 ...

随机推荐

  1. socket&period;io简单入门&lpar;一&period;实现简单的图表推送)

    引子:随着nodejs蓬勃发展,虽然主要业务系统因为架构健壮性不会选择nodejs座位应用服务器.但是大量的内部系统却可以使用nodejs试水,大量的前端开发人员转入全堆开发也是一个因素. 研究本例主 ...

  2. 从零开始,搭建博客系统MVC5&plus;EF6搭建框架(5),博客详情页、留言、轮播图管理、右侧统计博文

    一.博客系统进度回顾 上一遍博客介绍到,系统已经实现到了发布以及前台布局展示,接下来就是实现一些,详情页,留言.轮播图管理.右侧博文统计信息实现. 二.博客系统详情页实现 2.1先来看看详情页展示的效 ...

  3. 如何更改Json&period;NET的序列化规则

    我想要使序列化出来的JSON都是小写,可以通过建立 LowercaseContractResolver:DefaultContractResolver 来实现, 创建Custom ContractRe ...

  4. Oracle11g导入&ast;&period;dmp数据文件

    imp命令导入数据:imp username/password@SID file=XXX.dmp fromuser=XXX touser=XXX tables=(XXX,XXX)  [ignore=y ...

  5. uva Stacks of Flapjacks

                                                     Stacks of Flapjacks  题目链接:Click Here~ 题目描写叙述:     ...

  6. CurrentCulture和CurrentUICulture的区别

    CurrentCulture 这个属性用来表示和改变使用者要使用的“地区属性”,地区属性改变后,数字.日期时间等表示格式也随之改变. 注意:一定是“地区属性”,如"zh-cn".& ...

  7. 删除一个目录及其子目录下的所有&period;svn文件

    今天建立svn,加入代码,发现这些个文件夹中竟然已经有.svn文件夹,也就是它以前使用过svn, 这下就有点麻烦,在全新的svn里,这些.svn需要删除,又不可能一个一个手工去删除 网上翻了一下,发现 ...

  8. &commat;OnetoOne &commat;OnetoMany &commat;ManyToOne(2)

    在班主任(id,name,bjid) 班级(id name) 学生(id name bjid)的 关系中 班主任一对一关联班级 班级一对多关联学生 @OnetoOne @joinColumn(bjid ...

  9. Json解析包FastJson使用

    阿里巴巴FastJson是一个Json处理工具包,包括“序列化”和“反序列化”两部分,它具备如下特征:速度最快,测试表明,fastjson具有极快的性能,超越任其他的Java Json parser. ...

  10. 采用太平洋AI集装箱箱号识别接口实现集装箱箱号识别

    识别 示例图片 1 太平洋AI集装箱箱号识别接口(文档下方有详细操作指南) 1.1 接口一:提交base64格式的图片 地址:http://218.1.125.60:88/container_num_ ...