1、编写Dockerfile
1)、Dockerfile 文件
FROM openjdk:8-jdk-alpine
ARG JAR_FILE=kafka-demo-0.0.1-SNAPSHOT.jar
ADD ${JAR_FILE} kafka.jar
ENTRYPOINT ["java","-jar","/kafka.jar"]
2)、制作镜像
docker build -t kafka-demo:latest . #制作本地镜像
docker tag kafka-demo:latest 172.171.2.148:5000/kafka-demo:latest # 标记本地镜像,将其归入某一仓库
docker push 172.171.2.148:5000/kafka-demo:latest #上传本地镜像
2、配置yaml 文件
apiVersion: v1
kind: Service
metadata:
name: kafka-demo
namespace: dev
labels:
app: kafka-demo
spec:
type: NodePort
ports:
- port: 8090
nodePort: 30091 #service对外开放端口
selector:
app: kafka-demo
---
apiVersion: apps/v1
kind: Deployment #对象类型
metadata:
name: kafka-demo #名称
namespace: dev
labels:
app: kafka-demo #标注
spec:
replicas: 1 #运行容器的副本数,修改这里可以快速修改分布式节点数量
selector:
matchLabels:
app: kafka-demo
template:
metadata:
labels:
app: kafka-demo
spec:
containers: #docker容器的配置
- name: kafka-demo
image: 172.171.2.148:5000/kafka-demo:latest # pull镜像的地址 ip:prot/dir/images:tag
imagePullPolicy: Always #pull镜像时机,
ports:
- containerPort: 8080 #容器对外开放端口,需与springboot配置文件一致
#从私有仓库拉取镜像凭证
#imagePullSecrets:
#- name: regcred
~