docker 运行k3d clusterRun时主机头无效

oxcyiej7  于 2023-08-03  发布在  Docker
关注(0)|答案(1)|浏览(372)

我正在尝试使用以下配置在linux ubuntu机器上运行k3 d集群:

{
    "clusterToken": "123123123132",
    "imageVolume": "k3d-tl-images",
    "InitNode": null,
    "kubeAPI": {
        "Binding": {
            "HostIp": "0.0.0.0",
            "HostPort": "43077"
        },
        "host": "0.0.0.0",
        "Port": "6443"
    },
    "kubeconfig": {
        "switchCurrentContext": true,
        "updateDefaultKubeconfig": true
    },
    "name": "tl",
    "network": {
        "id": "123123123123123",
        "ipam": {
            "ipPrefix": "172.19.0.0/16",
            "ipsUsed": [
                "172.19.0.1",
                "172.19.0.3"
            ],
            "Managed": false
        },
        "Members": [
            {
                "IP": "172.19.0.3",
                "Name": "k3d-tl-registry"
            }
        ],
        "name": "k3d-tl"
    },
    "nodes": [
        {
            "agentOpts": {
            },
            "Cmd": [
                "server"
            ],
            "created": "2023-07-16T09:08:47.253631752Z",
            "env": [
                "all_proxy=",
                "ALL_PROXY=",
                "http_proxy=",
                "HTTP_PROXY=",
                "https_proxy=",
                "HTTPS_PROXY=",
                "no_proxy=",
                "NO_PROXY=",
                "K3S_TOKEN=123123123123",
                "K3S_KUBECONFIG_OUTPUT=/output/kubeconfig.yaml"
            ],
            "extraArgs": [
                "--disable=traefik",
                "--tls-san",
                "0.0.0.0"
            ],
            "ExtraHosts": null,
            "GPURequest": "",
            "image": "docker.io/rancher/k3s:v1.21.7-k3s1",
            "IP": {
                "IP": "",
                "Static": false
            },
            "Memory": "",
            "name": "k3d-tl-server-0",
            "Networks": [
                "k3d-tl"
            ],
            "portMappings": {
                "6443": [
                    {
                        "HostIp": "0.0.0.0",
                        "HostPort": "43077"
                    }
                ],
                "80/tcp": [
                    {
                        "HostIp": "",
                        "HostPort": "4589"
                    }
                ]
            },
            "restart": true,
            "role": "server",
            "runtimeLabels": {
                "app": "k3d",
                "k3d.cluster": "tl",
                "k3d.cluster.imageVolume": "k3d-tl-images",
                "k3d.cluster.network": "k3d-tl",
                "k3d.cluster.network.external": "true",
                "k3d.cluster.network.id": "123123123123123",
                "k3d.cluster.network.iprange": "172.19.0.0/16",
                "k3d.cluster.token": "hjeriYqaurJuGhjUxVrg",
                "k3d.cluster.url": "https://k3d-tl-server-0:6443",
                "k3d.role": "server",
                "k3d.server.api.host": "0.0.0.0",
                "k3d.server.api.hostIP": "0.0.0.0",
                "k3d.server.api.port": "43077",
                "k3d.server.loadbalancer": "",
                "k3d.version": "v5-dev"
            },
            "serverOpts": {
                "kubeAPI": {
                    "Binding": {
                        "HostIp": "0.0.0.0",
                        "HostPort": "43077"
                    },
                    "host": "0.0.0.0",
                    "Port": "6443"
                }
            },
            "State": {
                "Running": true,
                "Started": "2023-07-16T09:08:47.969985394Z",
                "Status": ""
            },
            "volumes": [
                "/var/lib/tl/standalone:/var/lib/tl/standalone",
                "/home/tl/tl/data:/home/tl/tl/data",
                "k3d-tl-images:/k3d/images"
            ]
        }
    ],
    "options": {
        "disableLoadbalancer": true,
        "globalEnv": [
            "K3S_TOKEN=123123123"
        ],
        "globalLabels": {
            "app": "k3d",
            "k3d.cluster": "tl",
            "k3d.cluster.imageVolume": "k3d-tl-images",
            "k3d.cluster.network": "k3d-tl",
            "k3d.cluster.network.external": "true",
            "k3d.cluster.network.id": "123123123123",
            "k3d.cluster.network.iprange": "172.19.0.0/16",
            "k3d.cluster.token": "123123123123",
            "k3d.cluster.url": "https://k3d-tl-server-0:6443",
            "k3d.server.loadbalancer": ""
        },
        "nodeHooks": [
            {
                "action": {
                    "Content": "123123123123123123",
                    "Description": "Write LocalRegistryHosting Configmap",
                    "Dest": "/tmp/localRegistryHostingCM.yaml",
                    "Mode": 420,
                    "Runtime": {
                    }
                },
                "stage": "preStart"
            },
            {
                "action": {
                    "Content": "123123123123123123123123",
                    "Description": "Write Registry Configuration",
                    "Dest": "/etc/rancher/k3s/registries.yaml",
                    "Mode": 420,
                    "Runtime": {
                    }
                },
                "stage": "preStart"
            }
        ],
        "registries": {
            "config": {
                "Auths": null,
                "Configs": null,
                "Mirrors": {
                    "docker.elastic.co": {
                        "Endpoints": null,
                        "Rewrites": null
                    },
                    "docker.io": {
                        "Endpoints": null,
                        "Rewrites": null
                    },
                    "gcr.io": {
                        "Endpoints": null,
                        "Rewrites": null
                    },
                    "k8s.gcr.io": {
                        "Endpoints": null,
                        "Rewrites": null
                    },
                    "quay.io": {
                        "Endpoints": null,
                        "Rewrites": null
                    },
                    "us-central1-docker.pkg.dev": {
                        "Endpoints": null,
                        "Rewrites": null
                    }
                }
            },
            "use": [
                {
                    "ClusterRef": "",
                    "expose": {
                        "Binding": {
                            "HostIp": "0.0.0.0",
                            "HostPort": "5699"
                        },
                        "Port": "5000/tcp"
                    },
                    "host": "k3d-tl-registry",
                    "image": "sha256:123123123123123123123",
                    "options": {
                        "proxy": {
                            "remoteURL": ""
                        }
                    }
                }
            ]
        },
        "waitForServer": true
    },
    "volumes": [
        "k3d-tl-images"
    ]
}

字符串
命令(golang):

k3dCluster.ClusterGet(ctx, runtimes.SelectedRuntime, &clusterConfig.Cluster)


这将导致以下错误:

Failed Cluster Start: error during post-start cluster preparation: error overwriting contents of /etc/hosts: docker failed to attach to exec process in node 'k3d-tl-server-0': http: invalid Host header


我尝试手动设置etc/hosts文件的权限,确保其有效,将http_proxy更新为localhost和127.0.0.1等,但总是遇到同样的问题。
我在日志中看到,当docker命令失败时,它试图运行,错误是:

Executing command '[sh -c cat /tmp/-etc-hosts-123123 > /etc/hosts]' in node 'k3d-tl-server-0'


任何帮助了解原因和解决方案将不胜感激

3bygqnnd

3bygqnnd1#

HTTP:无效主机标头
可能是这个bug in docker
要检查是否是这种情况,请尝试执行docker exec以附加到正在运行的容器。如果你看到这个错误,就是这个bug。

**如果是这种情况:**要么降级,要么等到发布修复程序

  • (由操作系统维护人员或外部存储库的维护人员执行,以适用者为准)。*
  • 我在使用“docker exec”命令时,我当前的docker(24.0.4-ce,使用go1.20.6构建)出现了此错误。*

相关问题