zeabur-server-ssh
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseZeabur Server SSH + kubectl
Zeabur Server SSH + kubectl
Always useto invoke Zeabur CLI. Never usenpx zeabur@latestdirectly or any other installation method.zeabur
Run commands on a user's dedicated server, and use kubectl to debug Kubernetes
workloads on servers that run ZeaburOS.
始终使用调用Zeabur CLI。 切勿直接使用npx zeabur@latest或其他任何安装方式。zeabur
在用户的专属服务器上运行命令,并使用kubectl调试运行ZeaburOS的服务器上的Kubernetes工作负载。
Check which kind of server you are on before using kubectl
使用kubectl前先确认服务器类型
- ZeaburOS servers run k3s with kubectl pre-installed. Everything in this skill applies.
- Ubuntu — a rented server that is not running ZeaburOS. It has
no k3s and no kubectl; every command below fails with
kubectl.command not foundstill works for ordinary shell commands.server exec
Renting provisions Ubuntu only, so never assume kubectl exists.
Read the machine's kind from the CLI — do not SSH in to work it out:
bash
npx zeabur@latest server get <server-id> -i=false --json | jq -r .osZeaburOSUbuntuserver listOSosNeeds CLI 0.21.0 or newer. Ifcomes backos, the CLI is older — either letnullfetch the current version, or fall back to the API (see thenpx zeabur@latestskill for the token setup that defineszeabur-server-rent):$ZAPI_CFGbashcurl -sS --max-time 30 -K "$ZAPI_CFG" https://api.zeabur.com/graphql \ -H "Content-Type: application/json" \ -d '{"query":"query($id: ObjectID!) { server(_id: $id) { hasK3s } }","variables":{"id":"<server-id>"}}'is three-state and the third state is a trap:hasK3sis ZeaburOS,trueis Ubuntu only, andfalseis a server predating the field — which does run ZeaburOS. So the test isnull, neverhasK3s === false; the latter sweeps in every older server and wrongly reports it as a plain VPS.!hasK3s
If you did not check first and a command fails with , that is the same signal — tell the user the server is a plain Ubuntu VPS
instead of retrying the command. Installing ZeaburOS is what adds kubectl; the
skill covers how.
kubectlcommand not foundzeabur-server-rentOne exception. All of the above answers what kind of machine this is. If
the user asks specifically whether some binary is present, check the machine —
a ZeaburOS server always has , but a plain Ubuntu VPS may have had it
installed by its owner, and the OS field cannot tell you that.
kubectl- ZeaburOS服务器 运行k3s且预安装了kubectl。本技能的所有内容均适用。
- Ubuntu服务器 —— 未运行ZeaburOS的租用服务器。这类服务器没有k3s和kubectl;以下所有命令都会因
kubectl失败。command not found仍可用于普通shell命令。server exec
租用的服务器仅提供Ubuntu系统,因此切勿默认kubectl已存在。
通过CLI查看服务器类型——不要通过SSH登录来判断:
bash
npx zeabur@latest server get <server-id> -i=false --json | jq -r .os返回结果为或。命令会一次性列出所有服务器的该信息,显示为列和字段。
ZeaburOSUbuntuserver listOSos需要CLI版本0.21.0或更高。如果返回os,说明CLI版本较旧——可以让null获取最新版本,或者改用API(参考npx zeabur@latest技能中的令牌设置,定义zeabur-server-rent):$ZAPI_CFGbashcurl -sS --max-time 30 -K "$ZAPI_CFG" https://api.zeabur.com/graphql \ -H "Content-Type: application/json" \ -d '{"query":"query($id: ObjectID!) { server(_id: $id) { hasK3s } }","variables":{"id":"<server-id>"}}'有三种状态,第三种状态需要注意:hasK3s表示ZeaburOS,true表示仅为Ubuntu,false表示该服务器早于该字段的添加——这类服务器确实运行ZeaburOS。因此判断条件应为null,而非hasK3s === false;后者会将所有旧服务器错误地归类为普通VPS。!hasK3s
如果未提前检查,导致命令因失败,这同样表明服务器是普通Ubuntu VPS,此时应告知用户,而非重试命令。安装ZeaburOS会添加kubectl;技能涵盖了安装方法。
kubectlcommand not foundzeabur-server-rent一个例外情况。以上所有内容都是判断服务器类型。如果用户明确询问某个二进制文件是否存在,则需要检查服务器——ZeaburOS服务器始终有,但普通Ubuntu VPS可能已被其所有者安装了该工具,而OS字段无法告知这一点。
kubectlRun a command: server exec
(recommended)
server exec运行命令:server exec
(推荐)
server execRun a command on the server in one step. The CLI fetches the credentials and opens
the connection internally, so you never handle the password — passwords with
special characters just work, and no / is needed.
ssh2sshpassbash
npx zeabur@latest server exec --id <server-id> -- <command>Examples:
bash
undefined一步到位在服务器上运行命令。CLI会自动获取凭证并建立连接,因此你无需处理密码——含特殊字符的密码也能正常工作,无需使用/。
ssh2sshpassbash
npx zeabur@latest server exec --id <server-id> -- <command>示例:
bash
undefinedSingle command
单个命令
npx zeabur@latest server exec --id <server-id> -- sudo kubectl get pods -A -o wide
npx zeabur@latest server exec --id <server-id> -- sudo kubectl get pods -A -o wide
Compound command — quote it as ONE argument so && / | stay intact
复合命令——将其作为单个参数引用,以保证&& / | 保持完整
npx zeabur@latest server exec --id <server-id> -- 'echo "=== PODS ===" && sudo kubectl get pods -A && echo "=== EVENTS ===" && sudo kubectl get events -A --sort-by=.lastTimestamp | tail -20'
Notes:
- Everything after `--` is the remote command, joined like `ssh host <command>`.
Quote a compound command (with `&&` / `|` / redirects) as a **single argument**.
- stdout/stderr stream live; the remote command's **exit code is propagated**
(a pipeline reports only its **last** stage's status — `… | tail` hides an
upstream failure, so don't rely on the exit code across a pipe).
- If you don't know the server ID, list servers first:
```bash
npx zeabur@latest server list -i=false(or use the skill).
zeabur-server-listnpx zeabur@latest server exec --id <server-id> -- 'echo "=== PODS ===" && sudo kubectl get pods -A && echo "=== EVENTS ===" && sudo kubectl get events -A --sort-by=.lastTimestamp | tail -20'
注意事项:
- `--`之后的所有内容都是远程命令,格式类似于`ssh host <command>`。复合命令(含`&&` / `|` / 重定向)需作为**单个参数**引用。
- stdout/stderr实时流式传输;远程命令的**退出码会被传递**(管道命令仅报告**最后**一个阶段的状态——`… | tail`会隐藏上游的失败,因此不要依赖管道命令的退出码)。
- 如果不知道服务器ID,先列出服务器:
```bash
npx zeabur@latest server list -i=false(或使用技能)。
zeabur-server-listCommon kubectl Commands
常用kubectl命令
ZeaburOS servers only. On a plain Ubuntu VPS these all fail with— see the section above.kubectl: command not found
Pass any of these as the command to . Always use —
the SSH user may not have direct access to the k3s kubeconfig. Any command with a
pipe () or must be quoted as a single argument, or the local shell
splits it and runs part locally — e.g.
.
server execsudo kubectl|&&server exec --id <id> -- 'sudo kubectl top pods -A --sort-by=memory | head -20'| Task | Command |
|---|---|
| List all pods | |
| Problem pods only | |
| Pod logs | |
| Exec into container | |
| Node resources | |
| Pod resources | |
| Describe pod | |
| Recent events | |
| Restart deployment | |
仅适用于ZeaburOS服务器。在普通Ubuntu VPS上,这些命令都会因失败——请参考上文的说明。kubectl: command not found
将这些命令作为参数传递给。始终使用——SSH用户可能没有直接访问k3s kubeconfig的权限。任何含管道符()或的命令都必须作为单个参数引用,否则本地shell会将其拆分并在本地执行部分命令——例如:。
server execsudo kubectl|&&server exec --id <id> -- 'sudo kubectl top pods -A --sort-by=memory | head -20'| 任务 | 命令 |
|---|---|
| 列出所有pod | |
| 仅列出有问题的pod | |
| 查看pod日志 | |
| 进入容器执行命令 | |
| 查看节点资源 | |
| 查看pod资源 | |
| 查看pod详情 | |
| 查看近期事件 | |
| 重启Deployment | |
Fallback: manual SSH (only if server exec
is unavailable)
server exec备选方案:手动SSH(仅当server exec
不可用时使用)
server execUse this only if isn't available (e.g. an older CLI). Otherwise
prefer above — this path is fragile with special-character passwords.
server execserver exec仅在不可用(例如CLI版本较旧)时才使用此方法。否则优先使用上文的——此方法在处理含特殊字符的密码时较为脆弱。
server execserver execStep 1: Get SSH credentials
步骤1:获取SSH凭证
bash
npx zeabur@latest server ssh-info --id <server-id> -i=falseOutput is JSON:
{"ip":"1.2.3.4","port":22,"username":"root","password":"xxx"}bash
npx zeabur@latest server ssh-info --id <server-id> -i=false输出为JSON格式:
{"ip":"1.2.3.4","port":22,"username":"root","password":"xxx"}Step 2: Connect
步骤2:建立连接
Use the Node.js method by default; use only when its availability
is already known. Do NOT run to check — it wastes a step where it's
never installed.
ssh2sshpasswhich sshpassbash
undefined默认使用Node.js的方法;仅当已知可用时才使用它。不要运行来检查——这会浪费时间,因为它通常未安装。
ssh2sshpasswhich sshpassbash
undefinedsshpass (only if already known to be available)
sshpass(仅当已知可用时使用)
sshpass -p '<password>' ssh -o StrictHostKeyChecking=no -p <port> <username>@<ip> sudo kubectl get pods -A
```bashsshpass -p '<password>' ssh -o StrictHostKeyChecking=no -p <port> <username>@<ip> sudo kubectl get pods -A
```bashNode.js ssh2 (the Zeabur agent sandbox has it pre-installed)
Node.js ssh2(Zeabur代理沙箱已预安装)
NODE_PATH=$([ -d /root/.global/node_modules ] && echo /root/.global/node_modules || echo /home/vercel-sandbox/.global/node_modules) node -e "
const {Client} = require('ssh2');
const c = new Client();
c.on('ready', () => {
c.exec('<command>', (err, stream) => {
if (err) { console.error(err); process.exit(1); }
let out = '', errOut = '';
stream.on('data', d => out += d);
stream.stderr.on('data', d => errOut += d);
stream.on('close', code => {
if (out) console.log(out);
if (errOut) console.error(errOut);
c.end();
process.exit(code);
});
});
}).connect({host:'<ip>', port:<port>, username:'<username>', password:'<password>'});
"
undefinedNODE_PATH=$([ -d /root/.global/node_modules ] && echo /root/.global/node_modules || echo /home/vercel-sandbox/.global/node_modules) node -e "
const {Client} = require('ssh2');
const c = new Client();
c.on('ready', () => {
c.exec('<command>', (err, stream) => {
if (err) { console.error(err); process.exit(1); }
let out = '', errOut = '';
stream.on('data', d => out += d);
stream.stderr.on('data', d => errOut += d);
stream.on('close', code => {
if (out) console.log(out);
if (errOut) console.error(errOut);
c.end();
process.exit(code);
});
});
}).connect({host:'<ip>', port:<port>, username:'<username>', password:'<password>'});
"
undefinedTips
小贴士
- Combine commands: batch related checks with in a single
&&call to reduce round trips.server exec - Use : adds node name and IP to pod listings, useful for scheduling issues.
-o wide - Namespace matters: Zeabur services usually run in non-default namespaces. Use
(all namespaces) first to locate the right one, then scope with
-A.-n <namespace> - Read project docs first: if a fix attempt fails, exec into the container and
check README/config before blindly checking metrics:
sudo kubectl exec <pod> -n <ns> -- cat /app/README.md - To find server IDs, use the skill. For simpler container commands that don't need server-level access, use the
zeabur-server-listskill.zeabur-service-exec
- 组合命令:在单个调用中使用
server exec批量执行相关检查,以减少往返次数。&& - 使用:在pod列表中添加节点名称和IP,有助于排查调度问题。
-o wide - 命名空间很重要:Zeabur服务通常运行在非默认命名空间中。先使用(所有命名空间)定位正确的命名空间,再用
-A限定范围。-n <namespace> - 先查看项目文档:如果修复尝试失败,进入容器查看README/配置文件,不要盲目检查指标:
sudo kubectl exec <pod> -n <ns> -- cat /app/README.md - 如需查找服务器ID,使用技能。对于无需服务器级别访问权限的简单容器命令,使用
zeabur-server-list技能。zeabur-service-exec