【GO】K8s 管理系统项目34[Linux环境–应用部署]
【GO】K8s 管理系统项目34[Linux环境–应用部署]
·
K8s 管理系统项目[Linux环境–应用部署]
1. 启动数据库
1.1 配置yum仓库
rm -f /etc/yum.repos.d/*.repo
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo
1.2 安装mariadb
mkdir -p /data/RPMS
cd /data/RPMS
wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.28-1.el7.x86_64.rpm-bundle.tar
tar xf mysql-5.7.28-1.el7.x86_64.rpm-bundle.tar
yum install ./*.rpm -y
systemctl enable --now mysqld
1.3 启动连接数据库
# 启动mysql
systemctl enable --now mysqld
# 取密码
grep pass /var/log/mysqld.log |awk '{print $NF}'
## 这里得到密码SYxFQYqA>2QM
# 登录mysql
mysql -uroot -p'SYxFQYqA>2QM'
# 重置localhost密码
set global validate_password_policy=0;
set global validate_password_length=1;
alter user 'root'@'localhost' identified by '123456';
# 创建远程用户(这里可以是其他用户名)
create user 'root'@'%' identified by '123456';
1.4 初始化数据库
create database k8s_dashboard charset utf8;
1.5 建表
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;
1.5 数据库授权
grant all privileges on k8s_dashboard.* to 'root'@'%';
exit
2. 后端部署
2.1 拉取代码
2.1.1 配置go代理
# 配置go代理
cd /data
echo "export GO111MODULE=on" >> ~/.profile
echo "export GOPROXY=https://goproxy.cn" >> ~/.profile
source ~/.profile
2.1.2 安装git
yum install git -y
2.1.3 拉取代码
git config --global user.name "qqmiller"
git config --global user.email "13917099322@139.com"
git clone https://gitee.com/qqmiller/k8s-plantform.git
输出结果
Cloning into 'k8s-plantform'...
Username for 'https://gitee.com': qqmiller
Password for 'https://qqmiller@gitee.com': 输入密码
remote: Enumerating objects: 80, done.
remote: Counting objects: 100% (80/80), done.
remote: Compressing objects: 100% (75/75), done.
remote: Total 80 (delta 31), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (80/80), done.
2.2 安装Golang
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
2.3 配置依赖
开始安装依赖
cd /data/k8s-plantform
go mod tidy
输出的结果
go: downloading github.com/gin-gonic/gin v1.8.1
go: downloading github.com/wonderivan/logger v1.0.0
go: downloading github.com/jinzhu/gorm v1.9.16
go: downloading github.com/gorilla/websocket v1.4.2
go: downloading k8s.io/api v0.26.0
go: downloading k8s.io/apimachinery v0.26.0
go: downloading k8s.io/client-go v0.25.4
go: downloading github.com/dgrijalva/jwt-go v3.2.0+incompatible
go: downloading github.com/gin-contrib/sse v0.1.0
go: downloading github.com/mattn/go-isatty v0.0.14
go: downloading golang.org/x/net v0.3.1-0.20221206200815-1e63c2f08a10
go: downloading google.golang.org/protobuf v1.28.1
go: downloading github.com/jinzhu/inflection v1.0.0
go: downloading github.com/stretchr/testify v1.8.0
go: downloading github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5
go: downloading github.com/jinzhu/now v1.0.1
go: downloading github.com/go-sql-driver/mysql v1.5.0
go: downloading github.com/gogo/protobuf v1.3.2
go: downloading gopkg.in/inf.v0 v0.9.1
go: downloading github.com/google/gofuzz v1.1.0
go: downloading github.com/spf13/pflag v1.0.5
go: downloading k8s.io/klog/v2 v2.80.1
go: downloading sigs.k8s.io/yaml v1.3.0
go: downloading github.com/imdario/mergo v0.3.6
go: downloading golang.org/x/term v0.3.0
go: downloading github.com/go-playground/validator/v10 v10.10.0
go: downloading github.com/pelletier/go-toml/v2 v2.0.1
go: downloading github.com/ugorji/go/codec v1.2.7
go: downloading gopkg.in/yaml.v2 v2.4.0
go: downloading github.com/goccy/go-json v0.9.7
go: downloading github.com/json-iterator/go v1.1.12
go: downloading golang.org/x/sys v0.3.0
go: downloading github.com/google/go-cmp v0.5.9
go: downloading github.com/denisenkom/go-mssqldb v0.0.0-20191124224453-732737034ffd
go: downloading github.com/lib/pq v1.1.1
go: downloading github.com/mattn/go-sqlite3 v1.14.0
go: downloading github.com/davecgh/go-spew v1.1.1
go: downloading github.com/pmezard/go-difflib v1.0.0
go: downloading gopkg.in/yaml.v3 v3.0.1
go: downloading sigs.k8s.io/structured-merge-diff/v4 v4.2.3
go: downloading k8s.io/utils v0.0.0-20221107191617-1a15be271d1d
go: downloading sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2
go: downloading github.com/golang/protobuf v1.5.2
go: downloading github.com/google/gnostic v0.5.7-v3refs
go: downloading golang.org/x/time v0.0.0-20220210224613-90d013bbcef8
go: downloading github.com/go-logr/logr v1.2.3
go: downloading github.com/moby/spdystream v0.2.0
go: downloading github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5
go: downloading github.com/elazarl/goproxy v0.0.0-20180725130230-947c36da3153
go: downloading github.com/go-playground/universal-translator v0.18.0
go: downloading github.com/leodido/go-urn v1.2.1
go: downloading golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd
go: downloading golang.org/x/text v0.5.0
go: downloading github.com/go-playground/assert/v2 v2.0.1
go: downloading github.com/go-playground/locales v0.14.0
go: downloading gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c
go: downloading github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd
go: downloading github.com/modern-go/reflect2 v1.0.2
go: downloading github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe
go: downloading k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280
go: downloading golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8
go: downloading github.com/kr/pretty v0.3.0
go: downloading github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822
go: downloading github.com/go-openapi/swag v0.19.14
go: downloading github.com/kr/text v0.2.0
go: downloading github.com/rogpeppe/go-internal v1.8.0
go: downloading github.com/emicklei/go-restful/v3 v3.8.0
go: downloading github.com/go-openapi/jsonreference v0.19.5
go: downloading github.com/onsi/ginkgo/v2 v2.4.0
go: downloading github.com/onsi/gomega v1.23.0
go: downloading github.com/mailru/easyjson v0.7.6
go: downloading github.com/PuerkitoBio/purell v1.1.1
go: downloading github.com/go-openapi/jsonpointer v0.19.5
go: downloading google.golang.org/appengine v1.6.7
go: downloading github.com/josharian/intern v1.0.0
go: downloading github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578
2.4 运行环境
2.4.1 配置修改
这里需要修config/config.go的一些内容,将以下内容改为自己环境中数据库配置.
数据库创建详见https://blog.csdn.net/qq_29974229/article/details/129044435
//数据库配置
DbType = "mysql"
DbHost = "192.168.31.24"
DbPort = 3306
DbName = "k8s_dashboard"
DbUser = "root"
DbPwd = "123456"
修改Kubecofnig配置 config/config.go的第9行
Kubeconfig = "config/cka"
将自己k8s服务器~/.kube/config取出来放到config/下,如果不改名的话,就把第9行改为config/config.否则就改为cka放到目录下覆盖原来文件即可.
可以用命令
# 这里192.168.31.57是本次部署节点的ip,替换这部分就可以了
sed -i 's/192.168.31.24/192.168.31.57/g' config/config.go
2.4.2 运行后端
go run main.go
这里如果卡住不动有2个可能
-
没有配置go代理,解决方法确认1.1的命令都被正常执行
-
数据库没有启动.
检查方法 telnet 1.4.1配置的地址和端口号
telnet 192.168.31.24 3306
如果端口通,确认DbName里的库是否创建,详见1.4.1
这里要多等一会
2.5 测试
2.5.1 本地测试
curl "http://127.0.0.1:9091/api/k8s/pods?namespace=default&filter_name=app-01-dffbb57c4-mzr67"
2.5.2 远程测试
通过postman测试
3. 前端部署
3.1 拉取代码
cd /data
git clone https://gitee.com/qqmiller/k8s-plantform-fe.git
输出结果
Cloning into 'k8s-plantform-fe'...
Username for 'https://gitee.com': qqmiller
Password for 'https://qqmiller@gitee.com':
remote: Enumerating objects: 81, done.
remote: Counting objects: 100% (81/81), done.
remote: Compressing objects: 100% (72/72), done.
remote: Total 81 (delta 23), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (81/81), done.
3.2 安装npm
cd /data/
yum install gcc gcc-c++ -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
rm -f node-v16.15.0-linux-x64.tar.gz
ln -sf /data/node-v16.15.0-linux-x64 /usr/local/node
echo 'export NODE_HOME=/usr/local/node' >> /etc/profile
echo 'export PATH=$NODE_HOME/bin:$PATH' >> /etc/profile
source /etc/profile
echo 'export NODE_HOME=/usr/local/node' >> /etc/rc.local
echo 'export PATH=$NODE_HOME/bin:$PATH' >> /etc/rc.local
chmod +x /etc/rc.local
确认npm版本
node -v
v16.15.0
npm -v
8.5.5
3.3 安装依赖包
cd /data/k8s-plantform-fe/
npm install
3.4 运行环境
3.4.1 配置修改
如果前后端在一台服务器上,那么不需要修改.
如果在不同服务器或者pod上,修改src/views/common/Config.js搜索红框内的localhost改为后端的服务器ip即可
我这里api服务器ip是192.168.31.57
sed -i 's/localhost/192.168.31.57/g' /data/k8s-plantform-fe/src/views/common/Config.js
3.4.2 运行前端
npm run serve
3.5 登录访问
使用账号admin,密码123456
更多推荐
已为社区贡献47条内容
所有评论(0)