k8s部署短视频网站(后台+web前端+web管理)

一、系统环境

系统 centos7
k8s v1.24
containerd v1.7.16
etcd v3.5.0

二、镜像生成工具准备

nerdctl v1.7.6
buildkit v0.13.2

1 nerdctl安装

下载:

 wget -c https://github.com/containerd/nerdctl/releases/download/v1.7.6/nerdctl-full-1.7.6-linux-amd64.tar.gz

解压:

tar -zxf nerdctl-full-1.7.6-linux-amd64.tar.gz -C /usr/local/nerdctl

配置:

将/usr/local/nerdctl/bin加入path

vi /etc/profile
source /etc/profile

2 buildkit安装

下载:

wget https://github.com/moby/buildkit/releases/download/v0.11.6/buildkit-v0.11.6.linux-amd64.tar.gz

解压:

tar -xf buildkit-v0.13.2.linux-amd64.tar.gz -C /usr/local/buildkit

配置:

将/usr/local/buildkit/bin加入path

vi /etc/profile
source /etc/profile

服务配置:

cat <<EOF > /usr/lib/systemd/system/buildkitd.service
[Unit]
Description=buildkitd
After=network.target

[Service]
ExecStart=/usr/local/buildkit/bin/buildkitd

[Install]
WantedBy=multi-user.target
EOF
# 重新加载Unit file
systemctl daemon-reload
# 启动服务
systemctl start buildkitd
# 开机自启动
systemctl enable buildkitd

需要特俗网络配置代理:

vi  /usr/lib/systemd/system/buildkitd.service.d/http-proxy.conf
[Service]
Environment="HTTP_PROXY=http://127.0.0.1:10809"
Environment="HTTPS_PROXY=http://127.0.0.1:10809"
Environment="NO_PROXY=localhost,127.0.0.1,::1,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16"
sudo systemctl daemon-reload
sudo systemctl restart buildkit

三、项目配置

1 go后台程序配置

1.1 项目根目录下Dockerfile文件

#使用官方的Golang映像创建构建工件。
FROM golang:1.21

# 设置代理
ENV HTTP_PROXY=http://127.0.0.1:10809
ENV HTTPS_PROXY=http://127.0.0.1:10809
ENV NO_PROXY=localhost,127.0.0.1

# 在容器内设置当前工作目录
WORKDIR /app

# 复制go mod和sum文件
COPY go.mod go.sum ./

# 下载所有依赖项。依赖项将被缓存。装好就走。Sum文件不会被更改
RUN go mod download

# 将源代码从当前目录复制到容器内的工作目录
COPY . .

# 构建Go应用程序
RUN CGO_ENABLED=0 GOOS=linux go build -o main .

# 设置代理
ENV HTTP_PROXY=http://127.0.0.1:10809
ENV HTTPS_PROXY=http://127.0.0.1:10809
ENV NO_PROXY=localhost,127.0.0.1

# 安装ffmpeg
RUN apt-get update && apt-get install -y ffmpeg

# 设置时区,解决时区问题
RUN echo "Asia/Shanghai" > /etc/timezone;
ENV LANG C.UTF-8

# 将端口8080暴露给外部世界
EXPOSE 8080

# 命令运行可执行文件
CMD ["./main", "-profile=prod"]

1.2 编译

[root@k8s-master01 zhiqu]# nerdctl --debug build -t leellun/zhiqu ./
DEBU[0000] Choosing the buildkit host "buildkit-default/build
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

流光影下

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值