我的
minikube
环境如下:-
CentOS Linux release 7.7.1908 (Core)
Docker Engine - Community 20.10.7
minikube version: v1.20.0
我想添加一些额外的主机映射(5+ IP 和名称)到
/etc/hosts
容器内的 minikube
。然后我使用 minikube ssh
进入 shell 并尝试 echo "172.17.x.x my.some.host" >> /etc/hosts
。由于登录此 shell 的用户是 -bash: /etc/hosts: Permission denied
,而不是 docker
,因此出现 root
错误。
我还发现,通过使用
minikube
,主机上有一个名为 docker container ls
的 docker 容器正在运行。即使我也可以通过使用 root
来使用 docker exec -it -u root minikube /bin/bash
进入这个容器。我知道这是一种调整,可能是一种不好的做法。尤其是任务太多了。
关于
docker
和docker-compose
分别提供了--add-host
和extra_hosts
来添加主机名映射,minikube
有提供吗?从minikube
和/或系统管理员的角度来看,是否有任何好的实践可以实现这一点?
在
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
在 hosts
创建整个 ~/.minikube/files/etc/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
已正常启动。
Minikube 有一个内置同步机制,可以使用以下示例部署所需的 /etc/hosts:
mkdir -p ~/.minikube/files/etc
echo 127.0.0.1 localhost > ~/.minikube/files/etc/hosts
minikube start
然后去检查它是否正常工作:
minikube ssh
进入容器后,您可以使用以下命令查看 /etc/hosts 文件的内容:
cat /etc/hosts
/etc/hosts 的内置同步很有帮助,但是,如果您不添加 Minikube 通常添加的条目 - 特别是 control-plane.minikube.internal,Minikube 将无法启动。