运维工具
在 vecps 内有一些需要通过在平台部署完成之后进行操作,例如替换证书,查看相关信息等,由于这些操作可能会涉及到替换多处,并且直接通过 k8s 命令行不容易操作,因此将这些操作全部集中集成起来。
详细功能说明
公共参数
说明:程序需要一些公共的参数
--kubeconfig 设置控制集群的 kube config 路径, default($HOME/.kube/config)
-v, --verbose 打印更全的 debug 信息, default(false)
-n, --namespace 设置程序运行的默认 namespace,default(vke-system),会在此 namespace 下寻找对应的 pod 做相应的操作。
数据库暴露
说明:在集群内通过命令行操作数据库可能会有一些不方便,可能需要将数据库暴露在集群外,通过一些可视化的工具连接数据库。
# 将 mongo 的 primary 节点暴露到集群外
vecps --kubeconfig path/to/kubeconfig export mongo
# 将 mysql 的 primary 节点暴露到集群外
vecps --kubeconfig path/to/kubeconfig export mysql
# 将 pg 的 primary 节点暴露到集群外
vecps --kubeconfig path/to/kubeconfig export pg
# 将 redis 的 master 节点暴露到集群外
vecps --kubeconfig path/to/kubeconfig export redis
# 将 minio 暴露到集群外
vecps --kubeconfig path/to/kubeconfig export minio
# 以上命令运行时都会打印连接数据库等相关信息,将程序 ctrl_c 之后端口暴露将会结束。
- 暴露 MongoDB
- 暴露 PostgreSQL
- 暴露 MySQL
- 暴露 Redis
- 暴露 Minio
公共镜像仓库
说明:在平台内需要一些公共镜像到平台内,故在平台内的运维端自动的创建一个运维账户,并且在运维账户下创建镜像仓库的相关信息,创建一个 library 的 namespace,在这个 namespace 下创建其各种公共的镜像 repo。
# 一步完成,创建用户,初始化镜像仓库,创建公共镜像 repo 并上传镜像
vecps cr public-repo --kubeconfig path/to/kubeconfig --tarball ./images.tar --images ./images.yaml
# --tarball 是预先准备好的镜像集合,可以是 docker save xx xx > images.tar 得到的 tar 包,也可以是通过 https://code.byted.org/infcp/vecps-image-sync 仓库内工具生成的 tar 包
# --images 是指明压缩包内所有的镜像列表,有一定的格式,参考:https://code.byted.org/infcp/vecps-cli/blob/release/images.yaml
# --external-iam 设置参数后则使用外部的 iam,例如:10.250.32.9:6789
# --external-top 设置参数后则使用外部的 top,例如:10.250.32.9:8000
# --image-namespace 上传镜像的 namespace
# --region 镜像仓库的 region (默认:cn-north-1)
# --username 设置账户的 username (默认:container-registry)
# --password 设置账户的 password (默认:Pwd123456!)
# --tel 设置账户的 tel (默认:17010001000)
# --email 设置账户的 email (默认:vecps@bytedance.com)
# --registry 镜像仓库的域名,确保本地可以解析 (默认:registry.vecps.com)
在 iam 侧创建的运维账户是可以登录的,使用如上设置的 username 和 password 在平台的运维侧可以登录,并且创建的镜像仓库侧的账户也是可以登录的,用户名需要从命令行回显日志中查看(格式:username@userid),例如:docker login registry.vecps.com --username container-registry@71 --password Pwd123456!
镜像
说明: 操作远程镜像。
# 登陆至远程镜像仓库,并默认将登陆信息保存在 $HOME/.docker/config.json
vecps image login hub.tosone.cn --username test --password Pwd123456
# 同步单个镜像到目标地址,同时支持同步多架构的镜像到目标地址
vecps image copy docker.io/library/busybox:stable hub.byted.org/infcprelease/busybox:stable
# 拉取远程的镜像,并保存到本地的 test.tar 中
vecps image pull --platform linux/amd64 docker.io/library/busybox:stable test.tar
# Pull all images and save to tarball file
vecps image pull docker.io/library/alpine:3.10 docker.io/library/alpine:3.15 target.tar
# Pull all images from yaml file and save to tarball file
# src.yaml:
# docker.io:
# library/alpine:
# - 3.10
# - 3.15
# library/busybox:
# - 1.31.1-uclibc
# registry2:
# library/alpine:
# - 3.10
vecps image pull --image-list src.yaml target.tar
# Pull all images from raw file and save to tarball file
# images.list:
# docker.io/library/alpine:3.10
# docker.io/library/alpine:3.15
# docker.io/library/busybox:1.31.1-uclibc
vecps image pull --raw images.list target.tar
vecps image push test.tar --registry hub.tosone.cn
# 加载 test.tar 中的镜像,并将其中所有镜像的域名替换成 hub.tosone.cn,并推送至远程
集群 resource 相关
说明:使用 kubectl 有时不太容易操作集群内的 resource 会有一些不方便。
# 将一个字符串或文件添加到 secret 内,若指定的 my-secret.yaml 文件不存在则将字符串放进去
vecps operate secret --namespace=default my-secret secret-key my-secret.yaml
# --namespace, -n 设置 secret 所在的 ns
# 使一个 job 重新运行
vecps operate job postgresql-ha-postgresql-init --namespace vke-system
# --namespace, -n 设置 job 所在的 ns
# --release, -r 若 job 已经被删除,可以从 helm release 中查找 job,再运行起来
集成工具相关
说明:集成一些比较方便的工具以便于在集群节点上快速 debug 问题。
# 集成 k9s
vecps k9s # 或者 vecps k8s
# 集成 btop
vecps btop # 或者 vecps top
# 集成 neofetch
vecps neofetch # 或者 vecps sysinfo
CA cert 证书相关
说明:生成包含 vecps 等私有信息的自签 ca 证书,并且可以根据指定的 CA 证书签名相应的域名。
# 生成含有 vecps 相关信息的 ca 证书,ca 证书默认是有效期 10 年
vecps cert ca
# 生成泛域名证书
vecps cert "*.vecps.com"
# 生成指定域名证书
vecps cert "webhook.vecps.com"
# 根据指定的 ca 证书生成指定域名证书
vecps cert "webhook.vecps.com" --ca-cert path/to/cert.crt --ca-key path/to/cert.key
# 生成指定证书,并且设置证书的过期时间,默认 24 个月
vecps cert "webhook.vecps.com" --expiration 24
# 获取证书的签名算法,过期时间,签名信息等等信息
vecps cert inspect cert.crt
# 示例输出:
# IsCA: true
# Issuer: CN=vecps bytedance@C02D204NML87,OU=bytedance@C02D204NML87,O=vecps development CA
# NotBefore: 2021-08-13 02:48:59 +0000 UTC
# NotAfter: 2031-08-13 02:48:59 +0000 UTC
# SerialNumber: 274997167748486220382263282238611003087
# SignatureAlgorithm: SHA256-RSA
集成的二进制工具
neofetch
作为获取系统一些关键信息的脚本工具,没有外部依赖。
wget -c -O neofetch-v7.1.0.zip https://github.com/dylanaraps/neofetch/archive/refs/tags/7.1.0.zip
btop
作为替代 top 的工具,有更加丰富的信息输出。
wget -c -O btop-1.1.2-x86_64-macos-monterey.tar.bz2 https://github.com/aristocratos/btop/releases/download/v1.1.2/btop-1.1.2-x86_64-macos-monterey.tbz
wget -c -O btop-1.1.2-arm64-macos-monterey.tar.bz2 https://github.com/aristocratos/btop/releases/download/v1.1.2/btop-1.1.2-arm64-macos-monterey.tbz
wget -c -O btop-1.1.2-x86_64-linux-musl.tar.bz2 https://github.com/aristocratos/btop/releases/download/v1.1.2/btop-1.1.2-x86_64-linux-musl.tbz
wget -c -O btop-1.1.2-aarch64-linux-musl.tar.bz2 https://github.com/aristocratos/btop/releases/download/v1.1.2/btop-1.1.2-aarch64-linux-musl.tbz
k9s
Kubernetes cli 工具。
wget -c -O k9s_Darwin_x86_64.tar.gz https://github.com/derailed/k9s/releases/download/v0.25.8/k9s_Darwin_x86_64.tar.gz
wget -c -O k9s_Darwin_arm64.tar.gz https://github.com/derailed/k9s/releases/download/v0.25.8/k9s_Darwin_arm64.tar.gz
wget -c -O k9s_Linux_x86_64.tar.gz https://github.com/derailed/k9s/releases/download/v0.25.8/k9s_Linux_x86_64.tar.gz
wget -c -O k9s_Linux_arm64.tar.gz https://github.com/derailed/k9s/releases/download/v0.25.8/k9s_Linux_arm64.tar.gz
helm
The Kubernetes Package Manager.
wget -c -O helm-v3.7.2-darwin-amd64.tar.gz https://get.helm.sh/helm-v3.7.2-darwin-amd64.tar.gz
wget -c -O helm-v3.7.2-darwin-arm64.tar.gz https://get.helm.sh/helm-v3.7.2-darwin-arm64.tar.gz
wget -c -O helm-v3.7.2-linux-amd64.tar.gz https://get.helm.sh/helm-v3.7.2-linux-amd64.tar.gz
wget -c -O helm-v3.7.2-linux-arm64.tar.gz https://get.helm.sh/helm-v3.7.2-linux-arm64.tar.gz
mongosh
MongoDB 的 cli 工具,使用 typescript 并且打包成二进制可执行文件,系统间的兼容性较好,但是在 vecps-cli 中退出有些问题。
wget -c -O mongosh-1.1.6-darwin-x64.zip https://downloads.mongodb.com/compass/mongosh-1.1.6-darwin-x64.zip
wget -c -O mongosh-1.1.6-darwin-arm64.zip https://downloads.mongodb.com/compass/mongosh-1.1.6-darwin-arm64.zip
wget -c -O mongosh-1.1.6-linux-x64.tgz https://downloads.mongodb.com/compass/mongosh-1.1.6-linux-x64.tgz
wget -c -O mongosh-1.1.6-linux-arm64.tgz https://downloads.mongodb.com/compass/mongosh-1.1.6-linux-arm64.tgz
usql
Universal command-line interface for SQL databases.
# building in the repo
GOOS=linux GOARCH=arm64 ./most.sh -m -v -t "pgx postgres moderncsqlite mymysql mysql csvq"
GOOS=linux GOARCH=amd64 ./most.sh -m -v -t "pgx postgres moderncsqlite mymysql mysql csvq"
GOOS=darwin GOARCH=arm64 ./most.sh -m -v -t "pgx postgres moderncsqlite mymysql mysql csvq"
GOOS=darwin GOARCH=amd64 ./most.sh -m -v -t "pgx postgres moderncsqlite mymysql mysql csvq"
redis
Redis is an in-memory database that persists on disk. The data model is key-value, but many different kind of values are supported: Strings, Lists, Sets, Sorted Sets, Hashes, Streams, HyperLogLogs, Bitmaps.
mc
MinIO Client is a replacement for ls, cp, mkdir, diff and rsync commands for filesystems and object storage.
wget -c -O mc-linux-amd64 https://dl.min.io/client/mc/release/linux-amd64/mc
wget -c -O mc-linux-arm64 https://dl.min.io/client/mc/release/linux-arm64/mc
wget -c -O mc-darwin-amd64 https://dl.min.io/client/mc/release/darwin-amd64/mc
wget -c -O mc-darwin-arm64 https://dl.min.io/client/mc/release/darwin-arm64/mc
openssl
Cryptography and SSL/TLS Toolkit.
wget https://www.openssl.org/source/openssl-3.0.1.tar.gz
sudo apt install musl-tools
# static compile with musl gcc
CC="musl-gcc -fPIE -pie -static -idirafter /usr/include/ -idirafter /usr/include/aarch64-linux-gnu" ./Configure no-shared no-async --prefix=/musl --openssldir=/musl/ssl
make -j4
jq
Command-line JSON processor
wget -c -O jq-a9f97e9e61a910a374a5d768244e8ad63f407d3e.zip https://github.com/stedolan/jq/archive/a9f97e9e61a910a374a5d768244e8ad63f407d3e.zip
sudo apt install libtool automake musl-tools
git submodule update --init # if building from git to get oniguruma
autoreconf -fi # if building from git
# static compile with musl gcc
CC=musl-gcc ./configure --with-oniguruma=builtin
make LDFLAGS=-all-static
yq
yq is a portable command-line YAML processor
wget -c -O yq-darwin-amd64 https://github.com/mikefarah/yq/releases/download/v4.16.1/yq_darwin_amd64
wget -c -O yq-darwin-arm64 https://github.com/mikefarah/yq/releases/download/v4.16.1/yq_darwin_arm64
wget -c -O yq-linux-amd64 https://github.com/mikefarah/yq/releases/download/v4.16.1/yq_linux_amd64
wget -c -O yq-linux-arm64 https://github.com/mikefarah/yq/releases/download/v4.16.1/yq_linux_arm64
gping
Ping, but with a graph.
wget -c -O gping-aarch64-unknown-linux-musl.tar.gz https://github.com/orf/gping/releases/download/gping-v1.2.6/gping-aarch64-unknown-linux-musl.tar.gz
wget -c -O gping-x86_64-unknown-linux-musl.tar.gz https://github.com/orf/gping/releases/download/gping-v1.2.6/gping-x86_64-unknown-linux-musl.tar.gz
coreutils
Cross-platform Rust rewrite of the GNU coreutils.
wget -c -O coreutils-0.0.8-aarch64-unknown-linux-gnu.tar.gz https://github.com/uutils/coreutils/releases/download/0.0.8/coreutils-0.0.8-aarch64-unknown-linux-gnu.tar.gz
wget -c -O coreutils-0.0.8-x86_64-unknown-linux-musl.tar.gz https://github.com/uutils/coreutils/releases/download/0.0.8/coreutils-0.0.8-x86_64-unknown-linux-musl.tar.gz
skopeo
Work with remote images registries - retrieving information, images, signing content.
make local-gen




