1.1 把你的springboot项目打包成可执行jar包
1.2 把jar包上传到Linux服务器
vim Dockerfile
内容
FROM java:8
MAINTAINER luozhanfeng
ADD demo.jar /demo.jar
EXPOSE 80
ENTRYPOINT ["java","-jar","/demo.jar"]
docker build -t luozhanfeng/demo:v1 .
docker images
apiVersion: v1
kind: Service
metadata:
name: demo
namespace: default
labels:
app: demo
spec:
type: NodePort #对外访问的类型
ports:
- port: 8030
nodePort: 30090 #service对外开放端口
selector:
app: demo
---
apiVersion: apps/v1
kind: Deployment #对象类型
metadata:
name: demo #名称
labels:
app: demo #标注
spec:
replicas: 3 #运行容器的副本数,修改这里可以快速修改分布式节点数量
selector:
matchLabels:
app: demo
template:
metadata:
labels:
app: demo
spec:
containers: #docker容器的配置
- name: demo
image: luozhanfeng/demo:v1 #本地镜像
#image: harbor.saas.xxx-ift.com/luozhanfeng/demo:v1 #远程仓库
imagePullPolicy: IfNotPresent # Always:总是拉取; IfNotPresent:默认值,本地有则使用本地镜像, 不拉取; Never:只使用本地镜像,从不拉取
ports:
- containerPort: 8030 #容器对外开放端口
kubectl create -f demo.yaml
kubectl get pods
curl 127.0.0.1:30333/test/test
kubectl delete -f demo.yaml
我们的私有harbor地址:https://harbor.saas.xxx-ift.com/
账号密码是BIP
docker tag luozhanfeng/demo:v1 harbor.saas.xxx-ift.com/luozhanfeng/demo:v1
cd /etc/pki/tls/certs/
rz
docker login https://harbor.saas.xxx-ift.com
docker push harbor.saas.xxx-ift.com/luozhanfeng/demo:v1
1、需要修改docker.service
vim /usr/lib/systemd/system/docker.service
EnvironmentFile=-/etc/sysconfig/docker
ExecStart=/usr/bin/dockerd $OPTIONS
2、修改/etc/docker/daemon.json
{
“insecure-registries”: [“http://192.168.19.4”]
}
然后重启docker即可
systemctl daemon-reload
systemctl restart docker.service
[root@test3 ~]# docker push 192.168.0.7/gitlab/gitlab_back:v1
The push refers to a repository [192.168.0.7/gitlab/gitlab_back]
Get https://192.168.0.7/v1/_ping: read tcp 192.168.0.6:40306->192.168.0.7:443: read: connection reset by peer
解决办法:
编辑vim /etc/sysconfig/docker文件。如果没有则创建。
docker推送镜像到harbor
https://blog.51cto.com/lovejxs/2446037?source=dra
自签署ssl根证书 certificate signed by unknown authority
https://segmentfault.com/q/1010000000938076
docker push到私有仓库
https://www.cnblogs.com/jifeng/p/9410003.html
K8S部署SpringBoot应用
https://blog.csdn.net/m0_37063785/article/details/101303898
k8s使用本地镜像
https://blog.csdn.net/u010039418/article/details/86578420