mkdir -p /data/mysql5.7/
docker run --name mysql -itd -h mysql-server -e MYSQL_ROOT_PASSWORD=root -v /data/mysql5.7:/var/lib/mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql:5.7.34 --character-set-server=utf8mb4 --collation-server=utf8mb4_general_ci
docker exec -it mysql mysql -uroot -p123456
create database k8s_dashboard charset utf8;
use k8s_dashboard
CREATE TABLE `workflow` (
`id` int NOT NULL AUTO_INCREMENT,
`name` varchar(32) COLLATE utf8mb4_general_ci NOT NULL,
`namespace` varchar(32) COLLATE utf8mb4_general_ci DEFAULT NULL,
`replicas` int DEFAULT NULL,
`deployment` varchar(32) COLLATE utf8mb4_general_ci DEFAULT NULL,
`service` varchar(32) COLLATE utf8mb4_general_ci DEFAULT NULL,
`ingress` varchar(32) COLLATE utf8mb4_general_ci DEFAULT NULL,
`type` varchar(32) COLLATE utf8mb4_general_ci DEFAULT NULL,
`created_at` datetime DEFAULT NULL,
`updated_at` datetime DEFAULT NULL,
`deleted_at` datetime DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE,
UNIQUE KEY `name` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
# ss -ntlp|grep 3306
LISTEN 0 128 *:3306 *:* users:(("docker-proxy",pid=134749,fd=4))
telnet 192.168.31.24 3306
确认表可以正常被访问到
mkdir -p /data/Dockerfile/k8s-plantform
cd /data/Dockerfile/k8s-plantform
git clone https://gitee.com/qqmiller/k8s-plantform.git
tar czf k8s-plantform.tar k8s-plantform
rm -rf k8s-plantform
start.sh
#!/bin/bash
echo "export GO111MODULE=on" >> ~/.profile
echo "export GOPROXY=https://goproxy.cn" >> ~/.profile
source ~/.profile
cd /data/k8s-plantform
go run main.go
# 设置基础镜像
FROM centos:7.9.2009
# 设置作者信息
LABEL maintainer="qiuqin <[email protected]>"
# 创建目录
RUN mkdir -p /data/
# 复制应用程序
Add ./k8s-plantform.tar /data/
# 安装 Go 和创建目录
RUN cd /etc/yum.repos.d && \
rm -f *.repo
RUN cd /data/k8s-plantform&& \
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo && \
echo "export GO111MODULE=on" >> ~/.profile&& \
echo "export GOPROXY=https://goproxy.cn" >> ~/.profile&& \
source ~/.profile&& \
rpm --import https://mirror.go-repo.io/centos/RPM-GPG-KEY-GO-REPO &&\
curl -s https://mirror.go-repo.io/centos/go-repo.repo | tee /etc/yum.repos.d/go-repo.repo &&\
yum install go -y &&\
go mod tidy
WORKDIR /data/k8s-plantform
ADD ./start.sh /data/k8s-plantform
# 暴露端口
EXPOSE 9091
# 启动应用程序
CMD ["/data/k8s-plantform/start.sh"]
docker build -t k8s-plantform:v1 .
docker run -it --name k8s-plantform -p 9091:9091 k8s-plantform:v1
有9091端口就可以
# ss -ntlp |grep 9091
LISTEN 0 128 *:9091 *:* users:(("docker-proxy",pid=137636,fd=4))
有正常返回则说明到k8s-api验证正常,否则检查config文件
http://192.168.31.24:9091/api/k8s/pods?namespace=default
这一步如果没有报错则数据库配置正确,否则检查数据库相关配置
http://192.168.31.24:9091/api/k8s/workflows
mkdir -p /data/Dockerfile/k8s-plantform-fe
cd /data/Dockerfile/k8s-plantform-fe
git clone https://gitee.com/qqmiller/k8s-plantform-fe.git
tar czf k8s-plantform-fe.tar k8s-plantform-fe
rm -rf k8s-plantform-fe
start.sh
#!/bin/bash
echo 'export NODE_HOME=/usr/local/node' >> /etc/profile
echo 'export PATH=$NODE_HOME/bin:$PATH' >> /etc/profile
source /etc/profile
cd /data/k8s-plantform-fe/
npm run serve
# 设置基础镜像
FROM centos:7.9.2009
# 设置作者信息
LABEL maintainer="qiuqin <[email protected]>"
# 创建目录
RUN mkdir -p /data/
# 复制应用程序
Add ./k8s-plantform-fe.tar /data/
# 安装 Go 和创建目录
RUN cd /etc/yum.repos.d && \
rm -f *.repo
RUN cd /data && \
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo && \
yum install gcc gcc-c++ wget -y &&\
wget https://registry.npmmirror.com/-/binary/node/latest-v16.x/node-v16.15.0-linux-x64.tar.gz && \
tar xf node-v16.15.0-linux-x64.tar.gz &&\
ln -sf /data/node-v16.15.0-linux-x64 /usr/local/node &&\
ln -sf /data/node-v16.15.0-linux-x64/bin/npm /usr/bin/npm &&\
echo 'export NODE_HOME=/usr/local/node' >> /etc/profile &&\
echo 'export PATH=$NODE_HOME/bin:$PATH' >> /etc/profile &&\
source /etc/profile &&\
rm -f node-v16.15.0-linux-x64.tar.gz &&\
cd /data/k8s-plantform-fe/ &&\
npm install &&\
sed -i 's/localhost/192.168.31.24/g' /data/k8s-plantform-fe/src/views/common/Config.js
WORKDIR /data/k8s-plantform-fe
ADD ./start.sh /data/k8s-plantform-fe/
# 暴露端口
EXPOSE 9090
# 启动应用程序
CMD ["/data/k8s-plantform-fe/start.sh"]
docker build -t k8s-plantform-fe:v1 .
docker run -it --name k8s-plantform-fe -p 9090:9090 k8s-plantform-fe:v1
有9090端口就可以
# ss -ntlp|grep 9090
LISTEN 0 128 *:9090 *:* users:(("docker-proxy",pid=138018,fd=4))
用户名:admin,密码:123456
登录后自动跳转到/home页
确认各资源是否与实际相符
wget https://github.com/docker/compose/releases/download/v2.15.1/docker-compose-linux-x86_64
mv docker-compose-linux-x86_64 /usr/bin/docker-compose
chmod +x /usr/bin/docker-compose
mkdir /data/k8s-dashboard
cd /data/k8s-dashboard
cat docker-compose.yaml
如果之前运行过可以直接用docker-compose创建
如果没有创建过库可以在打数据库镜像的时候加个初始化脚本
version: '3'
services:
db:
image: 'mysql:5.7.34'
container_name: dashboard-mysql
restart: always
ports:
- '3306:3306'
environment:
MYSQL_ROOT_PASSWORD: "root"
MYSQL_ROOT_PASSWORD: "123456"
volumes:
- /data/mysql2:/var/lib/mysql
api:
image: 'k8s-plantform:v7'
container_name: dashboard-api
restart: always
ports:
- '9091:9091'
web:
image: 'k8s-plantform-fe:v2'
container_name: dashboard-web
restart: always
ports:
- '9090:9090'
cd /data/k8s-dashboard
docker-compose up -d
# docker-compose up -d
[+] Running 4/4
⠿ Network k8s-dashboard_default Created 0.0s
⠿ Container dashboard-api Started 2.1s
⠿ Container dashboard-web Started 1.0s
⠿ Container dashboard-mysql Started 3.1s