【问题标题】:Cannot attach visual studio code (remote) to WordPress Bitnami helm release pod (Kubernetes)无法将 Visual Studio 代码(远程)附加到 WordPress Bitnami helm release pod (Kubernetes)
【发布时间】:2021-04-06 03:15:44
【问题描述】:

在尝试将 Visual Studio 代码附加到 WordPress pod(使用 kubernetes 扩展)时获得以下信息:

An error occurred attaching to the container

在终端中显示以下内容:

[3 ms] Remote-Containers 0.166.0 in VS Code 1.55.0 (c185983a683d14c396952dd432459097bc7f757f).
[48 ms] Start: Resolving Remote
[51 ms] Start: Run: kubectl exec -it wp-test-2-wordpress-65859bfc97-qtr9w --namespace default --container wordpress -- /bin/sh -c VSCODE_REMOTE_CONTAINERS_SESSION='5875030e-bcef-47a6-ada5-7f69edb5d9091617678415893' /bin/sh
[56 ms] Start: Run in container: id -un
[279 ms] 1001
[279 ms] Unable to use a TTY - input is not a terminal or the right kind of file
id: cannot find name for user ID 1001
[279 ms] Exit code 1
[281 ms] Command in container failed: id -un

在任何其他 helm 版本上执行完全相同的操作时,我没有这样的问题。仅适用于 Bitnami WordPress helm 版本。

【问题讨论】:

    标签: kubernetes visual-studio-code kubernetes-helm bitnami rancher


    【解决方案1】:

    这是因为 Bitnami WordPress 图像(版本 9.0.0)被迁移到“非 root”用户方法。从现在开始,容器和 Apache 守护进程都以用户 1001 的身份运行。

    您可以在Bitnami WordPress documentation找到更多信息:

    Bitnami WordPress 图像已迁移到“非 root”用户方法。以前,容器以 root 用户身份运行,而 Apache 守护程序以守护程序用户身份启动。从现在开始,容器和 Apache 守护程序都以用户 1001 运行。您可以通过将参数 securityContext.runAsUser 和 securityContext.fsGroup 设置为 0 来恢复此行为。图表标签和 Ingress 配置也经过调整以最好地遵循 Helm 图表实践。

    出现此问题是因为在 WordPress Pod 内运行id -un 命令导致错误:

    $ kubectl exec -it my-1-wordpress-756c595c9c-497xr -- bash
    I have no name!@my-1-wordpress-756c595c9c-497xr:/$ id -un
    id: cannot find name for user ID 1001
    

    作为一种解决方法,您可以通过将参数securityContext.runAsUsersecurityContext.fsGroup 设置为0root 运行WordPress,如Bitnami WordPress documentation 中所述。

    出于演示目的,我只更改了containerSecurityContext.runAsUser 参数:

    $ helm install --set containerSecurityContext.runAsUser=0 my-1 bitnami/wordpress
    

    然后我们可以查看id -un命令的输出:

    $ kubectl exec -it my-1-wordpress-7c44f695ff-f9j9f -- bash
    root@my-1-wordpress-7c44f695ff-f9j9f:/# id -un
    root
    

    如您所见,id -un 命令不会导致任何问题,因此我们现在可以成功连接到特定容器。

    我知道这种解决方法并不理想,因为使用非根容器有很多优点。 不幸的是,在这种情况下,如果不修改 Dockerfile,我不知道任何其他解决方法。

    【讨论】:

    • 哇,这是一个很棒的答案,非常感谢@matt_j!
    • 很高兴为您提供帮助:)
    猜你喜欢
    • 2021-04-22
    • 2023-03-11
    • 2020-08-24
    • 1970-01-01
    • 2011-03-31
    • 2011-09-20
    • 1970-01-01
    • 1970-01-01
    • 2016-07-30
    相关资源
    最近更新 更多