Skip to content

Instantly share code, notes, and snippets.

@littlecxm
Forked from triangletodd/README.md
Created May 3, 2024 15:10
Show Gist options
  • Save littlecxm/908ab5b095bce49bb9bff17e7ed4b66f to your computer and use it in GitHub Desktop.
Save littlecxm/908ab5b095bce49bb9bff17e7ed4b66f to your computer and use it in GitHub Desktop.

Revisions

  1. Todd Edwards revised this gist Nov 22, 2020. 1 changed file with 10 additions and 0 deletions.
    10 changes: 10 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -31,6 +31,16 @@ sysctl --system
    ![confirm.png](https://gist.github.com/triangletodd/02f595cd4c0dc9aac5f7763ca2264185/raw/confirm.png)


    ## Back on the Host

    Edit the config file for the container (`/etc/pve/lxc/$ID.conf`) and add the following:
    ```text
    lxc.apparmor.profile: unconfined
    lxc.cgroup.devices.allow: a
    lxc.cap.drop:
    lxc.mount.auto: "proc:rw sys:rw"
    ```

    ## In the container
    #### /etc/rc.local

  2. Todd Edwards revised this gist Nov 22, 2020. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,3 @@
    # k3s in LXC on Proxmox

    ## On the host
    #### Ensure these modules are loaded
    ```shell
  3. Todd Edwards revised this gist Nov 16, 2020. 1 changed file with 7 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -73,6 +73,13 @@ k3sup install --ip $CONTAINER_IP --user root
    #### Test
    ```shell
    KUBECONFIG=kubeconfig kubectl get pods --all-namespaces
    NAMESPACE NAME READY STATUS RESTARTS AGE
    kube-system metrics-server-7566d596c8-zm7tj 1/1 Running 0 69m
    kube-system local-path-provisioner-6d59f47c7-ldbcl 1/1 Running 0 69m
    kube-system helm-install-traefik-glt48 0/1 Completed 0 69m
    kube-system coredns-7944c66d8d-67lxp 1/1 Running 0 69m
    kube-system traefik-758cd5fc85-wzcst 1/1 Running 0 68m
    kube-system svclb-traefik-cwd9h 2/2 Running 0 42m
    ```

    ## References
  4. Todd Edwards revised this gist Nov 16, 2020. 5 changed files with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -21,16 +21,16 @@ sysctl --system

    ## Create the k3s container
    #### Uncheck unprivileged container
    ![Screenshot from 2020-11-16 04-15-08.png](:/cd3cbb3c473d42f783790b020077b21a)
    ![general.png](https://gist.github.com/triangletodd/02f595cd4c0dc9aac5f7763ca2264185/raw/general.png)

    #### Set swap to 0
    ![Screenshot from 2020-11-16 04-18-37.png](:/3d06672ee1444cf3a485c0598e38ba3d)
    ![memory.png](https://gist.github.com/triangletodd/02f595cd4c0dc9aac5f7763ca2264185/raw/memory.png)

    #### Enable DHCP
    ![Screenshot from 2020-11-16 04-16-38.png](:/b64d8e297bd5475e8e38d119c655c237)
    ![network.png](https://gist.github.com/triangletodd/02f595cd4c0dc9aac5f7763ca2264185/raw/network.png)

    #### Results
    ![Screenshot from 2020-11-16 04-17-03.png](:/d9e5cd33f2ef428ab9d8064541c39774)
    ![confirm.png](https://gist.github.com/triangletodd/02f595cd4c0dc9aac5f7763ca2264185/raw/confirm.png)


    ## In the container
    File renamed without changes
    File renamed without changes
    File renamed without changes
    File renamed without changes
  5. Todd Edwards revised this gist Nov 16, 2020. 4 changed files with 0 additions and 0 deletions.
    Binary file added 3d06672ee1444cf3a485c0598e38ba3d.png
    Loading
    Sorry, something went wrong. Reload?
    Sorry, we cannot display this file.
    Sorry, this file is invalid so it cannot be displayed.
    Binary file added b64d8e297bd5475e8e38d119c655c237.png
    Loading
    Sorry, something went wrong. Reload?
    Sorry, we cannot display this file.
    Sorry, this file is invalid so it cannot be displayed.
    Binary file added cd3cbb3c473d42f783790b020077b21a.png
    Loading
    Sorry, something went wrong. Reload?
    Sorry, we cannot display this file.
    Sorry, this file is invalid so it cannot be displayed.
    Binary file added d9e5cd33f2ef428ab9d8064541c39774.png
    Loading
    Sorry, something went wrong. Reload?
    Sorry, we cannot display this file.
    Sorry, this file is invalid so it cannot be displayed.
  6. Todd Edwards revised this gist Nov 16, 2020. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -76,4 +76,6 @@ KUBECONFIG=kubeconfig kubectl get pods --all-namespaces
    ```

    ## References
    https://github.com/MarijnKoesen/kubernetes-in-proxmox-with-kubeadm-lxc-and-wireshark
    - https://github.com/MarijnKoesen/kubernetes-in-proxmox-with-kubeadm-lxc-and-wireshark
    - https://github.com/kubernetes-sigs/kind/issues/662
    - https://medium.com/@kvaps/run-kubernetes-in-lxc-container-f04aa94b6c9c
  7. Todd Edwards created this gist Nov 16, 2020.
    79 changes: 79 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,79 @@
    # k3s in LXC on Proxmox

    ## On the host
    #### Ensure these modules are loaded
    ```shell
    cat /proc/sys/net/bridge/bridge-nf-call-iptables
    ```

    #### Disable swap
    ```shell
    sysctl vm.swappiness=0
    swapoff -a
    ```

    #### Enable IP Forwarding
    The first time I tried to get this working, once the cluster was up, the traefik pods were in CrashloopBackoff due to ip_forwarding being disabled. Since LXC containers share the host's kernel, we need to enable this on the host.
    ```
    echo 'net.ipv4.ip_forward=1' >> /etc/sysctl.conf
    sysctl --system
    ```

    ## Create the k3s container
    #### Uncheck unprivileged container
    ![Screenshot from 2020-11-16 04-15-08.png](:/cd3cbb3c473d42f783790b020077b21a)

    #### Set swap to 0
    ![Screenshot from 2020-11-16 04-18-37.png](:/3d06672ee1444cf3a485c0598e38ba3d)

    #### Enable DHCP
    ![Screenshot from 2020-11-16 04-16-38.png](:/b64d8e297bd5475e8e38d119c655c237)

    #### Results
    ![Screenshot from 2020-11-16 04-17-03.png](:/d9e5cd33f2ef428ab9d8064541c39774)


    ## In the container
    #### /etc/rc.local

    /etc/rc.local doesn't exist in the default 20.04 LXC template provided by Rroxmox. Create it with these contents:
    ```sh
    #!/bin/sh -e

    # Kubeadm 1.15 needs /dev/kmsg to be there, but it's not in lxc, but we can just use /dev/console instead
    # see: https://github.com/kubernetes-sigs/kind/issues/662
    if [ ! -e /dev/kmsg ]; then
    ln -s /dev/console /dev/kmsg
    fi

    # https://medium.com/@kvaps/run-kubernetes-in-lxc-container-f04aa94b6c9c
    mount --make-rshared /
    ```

    Then run this:
    ```shell
    chmod +x /etc/rc.local
    reboot
    ```


    ## Installing k8s
    #### k3sup Installation
    Assuming $HOME/bin is in your PATH:
    ```shell
    curl -sLS https://get.k3sup.dev | sh
    mv k3sup ~/bin/k3sup && chmod +x ~/bin/k3sup
    ```

    #### k8s Installation
    ```shell
    k3sup install --ip $CONTAINER_IP --user root
    ```

    #### Test
    ```shell
    KUBECONFIG=kubeconfig kubectl get pods --all-namespaces
    ```

    ## References
    https://github.com/MarijnKoesen/kubernetes-in-proxmox-with-kubeadm-lxc-and-wireshark