首先部署一个k8s 的环境
创建java项目并push到阿里云
开始部署启动项目
在master节点上执行
# 查看该容器里面的镜像
docker images
# 展示
REPOSITORY TAG IMAGE ID CREATED SIZE
eipwork/kuboard latest 0146965e6475 2 days ago 133MB
registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy v1.16.2 8454cbe08dc9 4 weeks ago 86.1MB
registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager v1.16.2 6e4bffa46d70 4 weeks ago 163MB
registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver v1.16.2 c2c9a0406787 4 weeks ago 217MB
registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler v1.16.2 ebac1ae204a2 4 weeks ago 87.3MB
calico/node v3.9.2 14a380c92c40 4 weeks ago 195MB
calico/cni v3.9.2 c0d73dd53e71 4 weeks ago 160MB
calico/kube-controllers v3.9.2 7f7ed50db9fb 4 weeks ago 56MB
calico/pod2daemon-flexvol v3.9.2 523f0356e07b 6 weeks ago 9.78MB
registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver v1.16.0 b305571ca60a 7 weeks ago 217MB
registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy v1.16.0 c21b0c7400f9 7 weeks ago 86.1MB
registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager v1.16.0 06a629a7e51c 7 weeks ago 163MB
registry.cn-hangzhou.aliyuncs.com/google_containers/etcd 3.3.15-0 b2756210eeab 2 months ago 247MB
registry.cn-hangzhou.aliyuncs.com/google_containers/coredns 1.6.2 bf261d157914 3 months ago 44.1MB
registry.cn-hangzhou.aliyuncs.com/google_containers/pause 3.1 da86e6ba6ca1 23 months ago 742kB
# 登陆阿里云
docker login --username=your user name registry.cn-hangzhou.aliyuncs.com
Password: your password
# pull 阿里云镜像
docker pull registry.cn-hangzhou.aliyuncs.com/sdongp-dkz/kubernetes:latest
再次查看master 当中的镜像这个时候就有自己想要的镜像了
查看 master 已经下载好的镜像
docker images
# 展示如下
REPOSITORY TAG IMAGE ID CREATED SIZE
registry.cn-hangzhou.aliyuncs.com/sdongp-dkz/kubernetes latest ca3dbc9962c8 49 years ago 119MB
运行镜像
kubectl run springboot01 --image=registry.cn-hangzhou.aliyuncs.com/sdongp-dkz/kubernetes:latest --port=9000
代码解释
springboot01 // 给将要运行的镜像取名字 可随意
registry.cn-hangzhou.aliyuncs.com/sdongp-dkz/kubernetes:latest //将要运行的镜像
9000 //绑定的端口
查看启动情况
kubectl get pod
NAME READY STATUS RESTARTS AGE
springboot-79b696b8ff-bl7rr 1/1 Running 0 37m
这个时候 STATUS 是 Running
查看更详细信息
kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
springboot-79b696b8ff-bl7rr 1/1 Running 0 39m 10.100.3.2 k8s-node2 <none> <none>
访问部署的服务
# 访问 springboot 服务
curl 10.100.3.2:9000 // 返回hello world (这里的10.100.3.2是node1的内部ip)
发布时发现的问题
- 我将镜像是pull在master 节点的 , 但是我启动之后发现 node1 节点也有了这个镜像 并且被启动了访问也是正常的 (这里还需要继续去研究)
- 我在node2 又pull 了一个同样的镜像 也启动了使用了 springboot01 这个命名也能启动这个时候不会同步到node1