K8s 方式安装 light-agent
推送镜像到 Kubernetes 的镜像仓库
在安装 Lighthouse 的机器上,执行以下操作
注意
如果使用了私有仓库,请执行以下操作添加 编辑/etc/docker/daemon.json文件,添加:
{
"insecure-registries" : ["<registry_url>"]
}
修改完成后,执行下面命令重启 Docker
systemctl restart docker
推送镜像
cd /opt/lighthouse/downloads #/opt/lighthouse 是 Lighthouse 平台所在的目录
# 注意:请替换镜像仓库地址(需要加上项目名称, 比如 192.168.2.99/light-agent);如果需要用户名和密码,请添加-u和-p参数
REGISTRY_REPO=your_docker_registry_url ./image-pusher.sh -- -u <username> -p <password>
部署 light-agent
在Kubernetes 环境中执行一下操作,进行 light-agent 部署
获取 Kubernetes 部署脚本模板 light-agent-template.yaml
curl -O http://<Lighthouse IP>:8089/k8s/light-agent-template.yaml
获取 Docker 配置密钥
- 创建密钥
注意
- --docker-email: 请替换为您的邮箱
- --docker-username: 请替换为您的用户名
- --docker-password: 请替换为您的密码
- --docker-server: 请替换为您的镜像仓库地址 (不需要加上项目名称, 比如 192.168.2.99)
kubectl create secret docker-registry dockerconfig-secret \
--docker-email=<email> \
--docker-username=<username> \
--docker-password=<password> \
--docker-server=<registry_url>
- 获取密钥
kubectl get secret dockerconfig-secret -o jsonpath='{.data.*}'
执行结果如下:
eyJhdXRocyI6eyIxOTIuMTY4LjIuOTkiOnsidXNlcm5hbWUiOiJjaGVuZ3Vvd2VpIiwicGFzc3dvcmQiOiJTZWN2aXNpb24xMjMiLCJlbWFpbCI6ImNoZW5ndW93ZWlAdmFsaWRhdGlvbnMuY24iLCJhdXRoIjoiWTJobGJtZDFiM2RsYVRwVFpXTjJhWE5wYjI0eE1qTT0ifX19
使用 envsubst 生成 light-agent.yaml 文件
注意
- COLLECTOR_SERVER_IP: 请替换为 Lighthouse 的 IP 地址
- REGISTRY_REPO: 请替换为您的具体的镜像仓库地址 (需要加上项目名称, 比如 192.168.2.99/light-agent)
- REGISTRY_CRED: 请替换为上一步获取到的 dockerconfig-secret 密钥
- envsubst: 环境变量替换工具。里面包含的变量不需要修改
COLLECTOR_SERVER_IP=<Lighthouse IP> REGISTRY_REPO=<your_docker_registry_url> REGISTRY_CRED=<registry_crea_str> envsubst '${REGISTRY_REPO} ${COLLECTOR_SERVER_IP} ${REGISTRY_CRED}' <light-agent-template.yaml >light-agent.yaml
执行安装
kubectl apply -f light-agent.yaml
查看状态
watch -n 1 kubectl get all -n light-agent
卸载 light-agent
kubectl delete -f light-agent.yaml