Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] add: config options to configure extra hosts #938

Merged
merged 1 commit into from
Jan 28, 2022

Conversation

iwilltry42
Copy link
Member

@iwilltry42 iwilltry42 commented Jan 27, 2022

Changelog

Legend:

  • 💻 = exposed change, visible to end users, e.g. CLI flags and config options
  • 🧰 = internal change, usually invisible for end users, but important for developers

Added

  • 💻 new CLI flag k3d cluster create --host-alias <ip>:<hostname>[,alias,...] (can be used multiple times)
    • will add /etc/hosts style entries to /etc/hosts in the node containers and in the NodeHosts section in CoreDNS, to make the names resolvable from within the cluster
    • Note: does not work in hostnetwork mode
  • 💻 new Simple config option for aforementioned CLI flag
     hostAliases:
     	- ip: 1.2.3.4
     	  hostnames:
     		- foo.bar.baz
     		- my.host.local
    • Note: does not work in hostnetwork mode

Changed

  • 🧰 hostname validation (e.g. for cluster and node names) now uses a Regexp to comply with RFC 1123)
  • 🧰 New RewriteFileActionOpts with option NoCopy to work around "Resource Busy" issue, e.g. when overwriting /etc/hosts in containers
  • 🧰 new field HostAliases in SimpleConfig, ClusterCreateOpts and ClusterStartOpts
  • 🧰 new NewHostAliasesInjectEtcHostsAction function to easily create a new action to inject entries into /etc/hosts in k3d node containers

References

Follow-Up To-Dos

@iwilltry42 iwilltry42 added this to the v5.3.0 milestone Jan 27, 2022
@iwilltry42 iwilltry42 self-assigned this Jan 27, 2022
@iwilltry42 iwilltry42 linked an issue Jan 27, 2022 that may be closed by this pull request
@iwilltry42 iwilltry42 force-pushed the feature/extrahosts branch 3 times, most recently from 0d94b14 to 7c68791 Compare January 27, 2022 17:05
@iwilltry42 iwilltry42 marked this pull request as ready for review January 27, 2022 17:10
@iwilltry42
Copy link
Member Author

Tests are not failing because of PR changes, so I'm merging this now ✔️

@iwilltry42 iwilltry42 merged commit aec4507 into main Jan 28, 2022
@iwilltry42 iwilltry42 deleted the feature/extrahosts branch January 28, 2022 06:34
@m33ch
Copy link

m33ch commented Mar 7, 2022

Hi, thanks for this change! He saved me!
I point out that after creating the cluster and turning it off and on again the defined hosts are absent in coreDns configMap.
The only thing I can do is delete the cluester and recreate it.

Thanks

@karthick-kk
Copy link

is it possible to persist the defined hosts across stop/start of the cluster? it makes no sense if the changes are lost after a system reboot and to see none of the changes seem to exist.

@iwilltry42
Copy link
Member Author

Persisting the changes across restarts is on the roadmap.
Due to the lack of contributors, it may take some time to land though.
Basically, the entries have to be re-injected on every start, as K3s overwrites them upon startup.

@m33ch
Copy link

m33ch commented Mar 31, 2022

Hi @iwilltry42,

looking at the cluster start code I noticed that host aliases injection is present, but apparently it doesn't work.
Is there a workaround so that i don't have to delete e create the cluster every time?

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants