Closed huapox closed 3 years ago
container 里面有shell吗,/bin/sh
, /bin/bash
, /bin/zsh
之类的?
container 里面有shell吗,
/bin/sh
,/bin/bash
,/bin/zsh
之类的?
有的 特意拿指定容器试了, k3s用的containerd不是docker, 初看项目中container/kube下代码 实现上是用的KubeCli, 正常讲这块应该没关系的,
具体抽空调试下这段代码:
func (kube KubeCli) exist(ctx context.Context, containerID, path string) bool {
...
restClient := kube.cli.CoreV1().RESTClient()
req := restClient.Post().
Resource("pods").
Name(info.PodName).
Namespace(info.Namespace).
SubResource("exec").
Param("container", info.ContainerName).
Param("command", "ls").
Param("command", path).
Param("stdout", "true").
Param("stdin", "false").
Param("tty", "false")
logrus.Debugf("POST to %s", req.URL())
exec, err := remotecommand.NewSPDYExecutor(kube.config, "POST", req.URL())
if err != nil {
logrus.Errorf("exist exec: setup executor error: [%v]", err)
return false
}
err = exec.Stream(remotecommand.StreamOptions{
Stdout: new(bytes.Buffer),
Tty: false,
})
cannot find a valid shell in container []
这个应该是没有拿到这个container的ID,但理论上能拿到containers list的话,就应该可以获取到它的ID。
k3s下可读取到容器列表
index页面可以列出全部namespace的容器吗?
DEBU[0006] POST to https://172.25.23.198:6443/api/v1/namespaces/kube-system/pods/svclb-traefik-jtmwv/exec?command=ls&command=%2Fbin%2Fash&container=lb-port-443&stdin=false&stdout=true&tty=false
DEBU[0006] container containerd://7092b551cb8a28b37f424f5a860ea0d6fd0333ee7d35e50f626ccf9ea44c6635 exist /bin/ash
DEBU[0006] get shell path /bin/ash
DEBU[0006] get logs of container: containerd://7092b551cb8a28b37f424f5a860ea0d6fd0333ee7d35e50f626ccf9ea44c6635
DEBU[0006] find cid: containerd://7092b551cb8a28b37f424f5a860ea0d6fd0333ee7d35e50f626ccf9ea44c6635
DEBU[0006] get pod logs: {containerd://7092b551cb8a28b37f424f5a860ea0d6fd0333ee7d35e50f626ccf9ea44c6635 lb-port-443 rancher/klipper-lb:v0.1.2 Ready / Running age: 2h19m42s; restart 0 [10.42.2.2 3.4.5.2] /bin/ash svclb-traefik-jtmwv lb-port-443 kube-system { false}}
找到问题了,K3S基于默认的containerd时获取的ID格式如: containerd://7092b551cb8a28b37f424f5a860ea0d6fd0333ee7d35e50f626ccf9ea44c6635
, 回到浏览器端时"/"干扰了。
如点击日志的链接为: http://172.25.23.197:8080/logs/containerd:/?follow=1&tail=10
PR: #59
resolved: #59