进入目录spring-cloud-kubernetes-1.0.1.RELEASE/spring-cloud-kubernetes-examples/kubernetes-hello-world-example,这里面就是官方的入门demo,执行以下命令开始构建并且会部署到minikube:
mvn clean package fabric8:deploy -Pkubernetes构建和部署完成后,控制台输出以下信息:
... [INFO] Installing /usr/local/work/demo/spring-cloud-kubernetes-1.0.1.RELEASE/spring-cloud-kubernetes-examples/kubernetes-hello-world-example/target/kubernetes-hello-world-1.0.1.RELEASE-sources.jar to /root/.m2/repository/org/springframework/cloud/kubernetes-hello-world/1.0.1.RELEASE/kubernetes-hello-world-1.0.1.RELEASE-sources.jar [INFO] [INFO] <<< fabric8-maven-plugin:3.5.37:deploy (default-cli) < install @ kubernetes-hello-world <<< [INFO] [INFO] [INFO] --- fabric8-maven-plugin:3.5.37:deploy (default-cli) @ kubernetes-hello-world --- [INFO] F8: Using Kubernetes at https://192.168.121.133:8443/ in namespace default with manifest /usr/local/work/demo/spring-cloud-kubernetes-1.0.1.RELEASE/spring-cloud-kubernetes-examples/kubernetes-hello-world-example/target/classes/META-INF/fabric8/kubernetes.yml [INFO] Using namespace: default [INFO] Creating a Service from kubernetes.yml namespace default name kubernetes-hello-world [INFO] Created Service: spring-cloud-kubernetes-examples/kubernetes-hello-world-example/target/fabric8/applyJson/default/service-kubernetes-hello-world.json [INFO] Using namespace: default [INFO] Creating a Deployment from kubernetes.yml namespace default name kubernetes-hello-world [INFO] Created Deployment: spring-cloud-kubernetes-examples/kubernetes-hello-world-example/target/fabric8/applyJson/default/deployment-kubernetes-hello-world.json [INFO] F8: HINT: Use the command `kubectl get pods -w` to watch your pods start up [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 16.047 s [INFO] Finished at: 2019-06-08T19:50:50+08:00 [INFO] ------------------------------------------------------------------------查看服务,已经创建了,类型是NodePort ,并且将8080端口映射到宿主机的30700端口,说明可以用宿主机IP:30700来访问此服务:
[root@minikube kubernetes-hello-world-example]# kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 10h kubernetes-hello-world NodePort 10.108.214.207 <none> 8080:30700/TCP 4m查看部署,发现始终未能进入READY状态:
[root@minikube kubernetes-hello-world-example]# kubectl get deployments NAME READY UP-TO-DATE AVAILABLE AGE kubernetes-hello-world 0/1 1 0 4m46s查看pod,发现新建的pod始终未能进入READY状态:
[root@minikube kubernetes-hello-world-example]# kubectl get pods NAME READY STATUS RESTARTS AGE kubernetes-hello-world-7578f45c5d-hr4r7 0/1 Running 1 6m
从上面的信息可以看出,部署虽然已经完成,但是pod是不可用的,访问网页试试,如下图,果然无法访问:
执行命令kubectl describe pod kubernetes-hello-world-7578f45c5d-hr4r7检查pod的具体情况,如下图红框所示,两个探针检查都失败了:
再看看控制台输出的pod基本情况,里面有探针的信息,如下图所示,两个探针的地址都是/health:
打开demo的源码,如下所示,根本就没有路径为/health的服务:
@RestController public class HelloController { private static final Log log = LogFactory.getLog(HelloController.class); @Autowired private DiscoveryClient discoveryClient; @RequestMapping("http://www.likecs.com/") public String hello() { return "Hello World"; } @RequestMapping("/services") public List<String> services() { return this.discoveryClient.getServices(); } }现在真相大白了:部署到minikube上的pod,配置了探针地址是/health,但是服务中并没有此路径,因此探针检查一直无法通过;
解决问题