docker - 如何将主机映射添加到 minikube 的 /etc/host?
问题描述
我的minikube
环境如下: -
- 主机操作系统:
CentOS Linux release 7.7.1908 (Core)
- 码头工人:
Docker Engine - Community 20.10.7
- 迷你库:
minikube version: v1.20.0
我想在容器/etc/hosts
内部添加一些额外的主机映射(5+ IP 和名称)。minikube
然后我使用minikube ssh
进入 shell 并尝试echo "172.17.x.x my.some.host" >> /etc/hosts
. -bash: /etc/hosts: Permission denied
由于登录到此 shell 的用户是 a docker
,而不是 a ,因此出现错误root
。
我还发现在主机上有一个名为minikube
running 的 docker 容器,使用docker container ls
. 即使我可以root
使用docker exec -it -u root minikube /bin/bash
. 我知道这是一种调整,可能是一种不好的做法。尤其是任务太多。
关于docker
and docker-compose
which 提供--add-host
和extra_hosts
分别添加主机名映射,是否minikube
提供?minikube
在和/或系统管理员的观点良好实践中是否有任何良好实践可以实现这一目标?
编辑 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
创建一个完整的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:
mkidr -p ~/.minikube/files/etc
echo 127.0.0.1 localhost > ~/.minikube/files/etc/hosts
minikube start
然后去检查它是否工作:
minikube ssh
一旦你进入容器:
cat /etc/hosts
推荐阅读
- c++ - 我正在尝试获得一个使用 AWS 传输管理器的基本示例,但他们的示例无法编译
- marathontesting - JNLP 应用程序在通过马拉松 JavaProfile Webstart 启动时启动和加载停止之前
- python - 到达“创建时:”循环时游戏崩溃
- postgresql - Docker 上的 Postgres 立即退出并删除外部文件系统中的数据
- javascript - 在 gulp.rename() 调用中使用来自早期 gulp.src 的文件名
- php - 为什么这个准备好的语句绑定失败?
- c++ - boost::process 异步 IO 示例不起作用?
- git - 来自 fork 的 Git 同步分支
- linux - OmniSharp.MSBuild.ProjectManager 无法在 Linux 上加载项目
- ssl - 通过代理提升 Asio SSL,“握手:版本号错误”