美文网首页我爱编程
spring boot和docker和k8s实践

spring boot和docker和k8s实践

作者: 青岛大桥_Android到后端 | 来源:发表于2018-04-11 14:08 被阅读160次

2018/4/11

实践出真知,实践能记住。光理论只是知道,我们需要实践加深理解。
以下都在一台阿里云一台ECS机器上实验。(应该是多台才更好,钱不够啊)

spring boot 和 docker实践

关于spring boot开发和docker这个文章非常好,基本上是照它做出来的
http://www.spring4all.com/article/992

我实验的源码在这里 https://github.com/zhugscn/springboottest_lovekids

如何在一台机器上实验k8s

  1. 使用minikube(localkube)
    而k8s呢,由于网上大多数文章都建议有3台主机(一台总控,2个node),自己实验难度很大。如何在一台但是现在有专门介绍快速入门,在一台机器上熟悉k8s概念的文章:
    https://yq.aliyun.com/articles/221687?do=login&accounttraceid=168e104c-1526-49da-a1a5-c51da98b7456
    不过minikube很少人人用了,不太推荐了

  2. 少见的在一台机器搭建原装k8s的文章
    https://blog.csdn.net/wangtonglin2009/article/details/79024820
    但你可以发现它的例子mysql, 这是docker官网标准的镜像。在新创建pods时会自动去官网下载。 而我们经常用到的是自己创建的镜像,这方面没有详细介绍,具体实现有一些坑。

  3. 使用自己创建的镜象而不是默认从docker官网下载
    官方其实已经说明了,只是没有详细看文档;https://kubernetes.io/docs/concepts/containers/images/

By default, the kubelet will try to pull each image from the specified registry. However, if the imagePullPolicy property of the container is set to IfNotPresent or Never, then a local image is used (preferentially or exclusively, respectively).

默认情况是会根据配置文件中的镜像地址去拉取镜像,如果设置为IfNotPresent 和Never就会使用本地镜像。

IfNotPresent :如果本地存在镜像就优先使用本地镜像。

Never:直接不再去拉取镜像了,使用本地的;如果本地不存在就报异常了。

参数的作用范围:

spec:
containers:
- name: nginx
image: image: reg.docker.lc/share/nginx:latest
imagePullPolicy: IfNotPresent #或者使用Never

  1. 由docker直接创建的镜像能访问,用k8s却不能
    docker run -p 30001:8080 -t springboot/lovekidsdemo
    这样在外网地址直接访问 xx.xx.xx.xx: 30001就可以访问自己写的页面了

但是用k8s以下:
kubectl create -f lovekidsdemo-rc.yaml
kubectl create -f lovekidsdemo-svc.yaml
虽然也创建rc 了, 也创建pod了, 也创建svc了, 但是还是没找到外网访问的办法,只是在pod(ECS本机)上打了个30001的洞,所以可以用links 127.0.0.1:30001来看网页是能连能。

  1. 配置K8S管理界面
    https://www.cnblogs.com/ericnie/p/6826908.html
    也许这篇文章更好:http://www.bubuko.com/infodetail-2242562.html

相关文章

网友评论

    本文标题:spring boot和docker和k8s实践

    本文链接:https://www.haomeiwen.com/subject/camnhftx.html