docs: update guide for exposing hosts file (#348)

This commit is contained in:
kurokobo 2024-04-20 01:34:23 +09:00 committed by GitHub
parent 6225665bc4
commit ee564d5566
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -6,7 +6,9 @@ This is necessary for AWX to resolve the hostname for your private Git repositor
One easy way to do this is to use `dnsmasq`. One easy way to do this is to use `dnsmasq`.
1. Add entries to `/etc/hosts` on your K3s host. Note that the IP addresses have to be replaced with your K3s host's one. Note that any IP addresses in the following steps have to be replaced with your K3s host's one.
1. Add entries to `/etc/hosts` on your K3s host.
```bash ```bash
sudo tee -a /etc/hosts <<EOF sudo tee -a /etc/hosts <<EOF
@ -17,14 +19,27 @@ One easy way to do this is to use `dnsmasq`.
EOF EOF
``` ```
2. Install and start `dnsmasq` with default configuration. 2. Install `dnsmasq`.
```bash ```bash
sudo dnf install dnsmasq sudo dnf install dnsmasq
```
3. Add minimal configuration file for `dnsmasq`.
```bash
sudo tee /etc/dnsmasq.d/10-k3s.conf <<EOF
listen-address=192.168.0.221
EOF
```
4. Enable and start `dnsmasq`.
```bash
sudo systemctl enable dnsmasq --now sudo systemctl enable dnsmasq --now
``` ```
3. Create new `resolv.conf` to use K3s. Note that the IP addresses have to be replaced with your K3s host's one. 5. Create new `resolv.conf` for K3s.
```bash ```bash
sudo tee /etc/rancher/k3s/resolv.conf <<EOF sudo tee /etc/rancher/k3s/resolv.conf <<EOF
@ -32,11 +47,11 @@ One easy way to do this is to use `dnsmasq`.
EOF EOF
``` ```
4. Add `--resolv-conf /etc/rancher/k3s/resolv.conf` as an argument for `k3s server` command. 6. Add `--resolv-conf /etc/rancher/k3s/resolv.conf` as an argument for `k3s server` command.
```bash ```bash
# Change configuration using script: # Change configuration using script:
$ curl -sfL https://get.k3s.io | sh -s - --write-kubeconfig-mode 644 --resolv-conf /etc/rancher/k3s/resolv.conf $ curl -sfL https://get.k3s.io | INSTALL_K3S_VERSION=v1.28.7+k3s1 sh -s - --write-kubeconfig-mode 644 --resolv-conf /etc/rancher/k3s/resolv.conf
# If you don't want to use the script, modify /etc/systemd/system/k3s.service manually: # If you don't want to use the script, modify /etc/systemd/system/k3s.service manually:
$ cat /etc/systemd/system/k3s.service $ cat /etc/systemd/system/k3s.service
@ -49,15 +64,15 @@ One easy way to do this is to use `dnsmasq`.
'/etc/rancher/k3s/resolv.conf' \ 👈👈👈 '/etc/rancher/k3s/resolv.conf' \ 👈👈👈
``` ```
5. Restart K3s and CoreDNS. The K3s service can be safely restarted without affecting the running resources. 7. Restart K3s and CoreDNS. The K3s service can be safely restarted without affecting the running resources.
```bash ```bash
sudo systemctl daemon-reload sudo systemctl daemon-reload
sudo systemctl restart k3s sudo systemctl restart k3s
kubectl -n kube-system delete pod -l k8s-app=kube-dns kubectl -n kube-system rollout restart deployment coredns
``` ```
6. Ensure that your hostname can be resolved as defined in `/etc/hosts`. 8. Ensure that your hostname can be resolved as defined in `/etc/hosts`.
```bash ```bash
$ kubectl run -it --rm --restart=Never busybox --image=busybox:1.28 -- nslookup git.example.com $ kubectl run -it --rm --restart=Never busybox --image=busybox:1.28 -- nslookup git.example.com
@ -69,7 +84,7 @@ One easy way to do this is to use `dnsmasq`.
pod "busybox" deleted pod "busybox" deleted
``` ```
7. If you update your `/etc/hosts`, restarting `dnsmasq` is required. 9. If you update your `/etc/hosts`, restarting `dnsmasq` is required.
```bash ```bash
sudo systemctl restart dnsmasq sudo systemctl restart dnsmasq