- 准备 Java 项目, 把 Java 进行打包(jar包 或者 war包)
- 制作镜像
- 上传到 阿里云
- 部署镜像, 暴露应用
准备 Java 项目, 这里我准备了一个打包好的 jar包
$ vim Dockerfile
FROM openjdk:8-jdk-alpine
VOLUME /tmp
ADD demojenkins.jar demojenkins.jar
ENTRYPOINT ["java","-jar","/demojenkins.jar","&"]
$ docker build -t java-demo-01:latest .
Sending build context to Docker daemon 17.57MB
Step 1/4 : FROM openjdk:8-jdk-alpine
8-jdk-alpine: Pulling from library/openjdk
...
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
java-demo-01 latest 9a2447a2c0ca 15 seconds ago 122MB
$ docker run -d -p 8111:8111 java-demo-01:latest -t
27ecdf7f084eaddfcc94cc78b83336a5ef760e87890ea94cf0e314774bb11de8
在浏览器中输入: IP:8111/user 即可返回 hello
停止该容器
$ docker stop 27ecdf7f084eaddfcc94cc78b83336a5ef760e87890ea94cf0e314774bb11de8
$ kubectl create deployment javademo1 --image=registry.cn-hangzhou.aliyuncs.com/kino-k8s/java-demo-01:1.0.0 --dry-run -o yaml > javamode.yaml
$ kubectl apply -f javamode.yaml
$ kubectl expose deployment javademo1 --port=8111 --target-port=8111 --type=NodePort
$ kubectl get pod,svc
NAME READY STATUS RESTARTS AGE
pod/javademo1-ccbbb4b96-sg84z 1/1 Running 0 2m17s
pod/pod-vol-pvc 1/1 Running 0 67m
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/javademo1 NodePort 10.103.59.83 <none> 8111:31761/TCP 87s
service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 155m