13.Kubernetes应用部署完整流程:从Dockerfile到Ingress发布完整流程

本文以一个简单的Go应用Demo来演示Kubernetes应用部署的完整流程

1、Dockerfile多阶段构建

Dockerfile多阶段构建

[root@docker github]# git clone https://gitee.com/yxydde/http-dump.git
[root@docker github]# cd http-dump/
[root@docker http-dump]# cat Dockerfile
FROM golang:1.19.0 AS builder
WORKDIR /app
COPY main.go .
COPY go.mod .
RUN go build -a -o http-dump .

# 这里使用多阶段构建,只复制编译结果到最终镜像,可以明显减小镜像大小
FROM debian:stable-slim
WORKDIR /app/
COPY --from=0 /app/http-dump .
EXPOSE 8080
CMD ["./http-dump"]

2、构建镜像并推送到私有仓库

结合 12.Harbor构建私有镜像仓库 ,构建镜像并推送的私有仓库

[root@docker http-dump]# docker build -t harbor.example.io/apps/http-dump .
Sending build context to Docker daemon  77.31kB
Step 1/10 : FROM golang:1.19.0 AS builder
 ---> 505a511fa01d

你可能感兴趣的:(Kubernetes入门实战,kubernetes,容器,云原生)