kubernetes 如何将主机Map添加到minikube的/etc/host?

yhived7q  于 2022-11-28  发布在  Kubernetes
关注(0)|答案(2)|浏览(155)

我的minikube环境如下所示:-

  • 主机操作系统:CentOS Linux release 7.7.1908 (Core)
  • 扩展坞:Docker Engine - Community 20.10.7
  • 小型立方体:minikube version: v1.20.0

我想在minikube容器中添加一些额外的主机Map(5+ IP和名称)到/etc/hosts。然后我使用minikube ssh进入shell并尝试echo "172.17.x.x my.some.host" >> /etc/hosts。由于登录此shell的用户是docker,而不是root,因此出现-bash: /etc/hosts: Permission denied错误。
我还发现在主机上有一个名为minikube的docker容器正在运行,通过使用docker container ls。甚至我可以通过使用docker exec -it -u root minikube /bin/bash使用root进入这个容器。我明白这是一种调整,可能是一种不好的做法。特别是它的任务太多。
关于dockerdocker-compose(分别提供--add-hostextra_hosts以添加主机名Map),minikube是否提供此功能?在minikube和/或系统管理员Angular 的良好实践中,是否有实现此功能的良好实践?

编辑1

echo 172.17.x.x my.some.host > ~/.minikube/files/etc/hosts和启动minikube后,有如下一些错误:-

[kubelet-check] It seems like the kubelet isn't running or healthy.
[kubelet-check] The HTTP call equal to 'curl -sSL http://localhost:10248/healthz' failed with error: Get "http://localhost:10248/healthz": dial tcp: lookup localhost on 8.8.8.8:53: no such host.

        Unfortunately, an error has occurred:
                timed out waiting for the condition

        This error is likely caused by:
                - The kubelet is not running
                - The kubelet is unhealthy due to a misconfiguration of the node in some way (required cgroups disabled)

        If you are on a systemd-powered system, you can try to troubleshoot the error with the following commands:
                - 'systemctl status kubelet'
                - 'journalctl -xeu kubelet'

        Additionally, a control plane component may have crashed or exited when started by the container runtime.
        To troubleshoot, list all containers using your preferred container runtimes CLI.

        Here is one example how you may list all Kubernetes containers running in docker:
                - 'docker ps -a | grep kube | grep -v pause'
                Once you have found the failing container, you can inspect its logs with:
                - 'docker logs CONTAINERID'

然后我使用vi~/.minikube/files/etc/hosts创建一个完整的hosts文件,如下所示:-

127.0.0.1       localhost
::1     localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

172.17.x.x my.some.host1
172.17.x.y my.some.host2
...

此时,minikube已正确启动。

brccelvz

brccelvz1#

Minikube有一个built-in sync mechanism,可以部署所需的/etc/hosts,示例如下:

mkidr -p ~/.minikube/files/etc
echo 127.0.0.1 localhost > ~/.minikube/files/etc/hosts
minikube start

那就去检查一下它是否工作:

minikube ssh

一旦进入容器:

cat /etc/hosts
ippsafx7

ippsafx72#

/etc/hosts的内置同步功能很有用,但是,如果您不添加Minikube通常会添加的条目--特别是control-plane.minikube.internal,Minikube将无法启动。

相关问题