Kubernetes in a Linux Container

Kubernetes Home Page
Kubernetes Home Page

Kubernetes is an open source container orchestration tool promising a catch all solution to issues that arise when deploying applications. Kubernetes creates a framework that models how infrastructure and services should interact.

The industry is trending in a direction where a Tech marketing works its wonders. of people will be running k8s (Kubernetes) setups in one form or the other. Let’s exploit Linux Containers (LXC) as a mock infrastructure and create a local k8s cluster to experiment.

The Base System

We will use CentOS Linux Pinning down moving targets (versions) prevents you from losing your mind if something breaks and things do break. 8.1.1911 as our base system for a cluster running k8s version 1.17. You can download the CentOS version of choice using lxc-create.

shell
lxc-create -n k8s-centos8 -t download

In my case the rootfs for lxc is In ideal scenarios, transitioning between a chroot, container, virtual machine, and bare metal should be easy. with docker using a Dockerfile. We docker export to obtain the container’s filesystem. This build bootstraps openssh-server and python for ansible to quickly setup the clusters.

dockerfile
FROM centos:centos8.1.1911

RUN dnf -y update

RUN  dnf install -y --setopt=install_weak_deps=False \
  openssh-server network-scripts python3

RUN  systemctl enable network
RUN  systemctl disable kdump

RUN  usermod -p "$(uuidgen)" root

COPY centos8/files/ifcfg-ens3 /etc/sysconfig/network-scripts/ifcfg-ens3
COPY common/sshd_config /etc/ssh/sshd_config

RUN mkdir -p /root/.ssh
RUN chmod 700 /root/.ssh
COPY common/authorized_keys /root/.ssh/authorized_keys
RUN chmod 400 /root/.ssh/authorized_keys

The Container Configuration

For Kubernetes to work inside the container, we’ll need to tweak its lxc configuration. This is a This should work on Debian and Arch Linux based systems. for the base container k8s-centos8 in /var/lib/lxc/k8s-centos8/config.

ini
# Uncomment the following line to support nesting containers
lxc.include = /usr/share/lxc/config/nesting.conf

# Distribution configuration
lxc.include = /usr/share/lxc/config/common.conf
lxc.arch = x86_64

# Allow access to all cgroups
lxc.cgroup.devices.allow = a

# Set proc mount to read and write
lxc.mount.auto = cgroup:mixed proc:rw sys:mixed

# No capability drops
lxc.cap.drop =

# Bind host kmsg for oom killer
lxc.mount.entry = /dev/kmsg dev/kmsg none defaults,bind,create=file

# Apparmor unconfined and allow nesting
lxc.apparmor.profile = unconfined
lxc.apparmor.allow_nesting = 1

# Network configuration
lxc.net.0.type = veth
lxc.net.0.link = lxcbr0
lxc.net.0.flags = up
lxc.net.0.hwaddr = 00:16:3e:e0:c3:1d
lxc.rootfs.path = dir:/var/lib/lxc/k8s-centos8/rootfs
lxc.uts.name = k8s-centos8

Kubernetes Cluster Installation

The base system is now ready. You can add -B overlayfs -s onto the end of the lxc-copy command for super fast cloning. a master node and If you have a domain defined in /etc/default/lxc-net then you can ping a running container by name. worker nodes by cloning the base system.

shell
lxc-copy -n k8s-centos8 -N k8s-master
lxc-copy -n k8s-centos8 -N k8s-node1
lxc-copy -n k8s-centos8 -N k8s-node2
lxc-copy -n k8s-centos8 -N k8s-node3

Manually setting up each system is troublesome. We automate the rest using this ansible This playbook is a distillation of the standard installation documentation, with the addition of the Kubernetes Dashboard.

Running Kubernetes Playbook
Running Kubernetes Playbook
29 February 2020 — Written
29 February 2020 — Updated
Thedro Neely — Creator
kubernetes-in-a-linux-container.md — Article

More Content

Openring

Web Ring

Comments

References

  1. https://thedroneely.com/git/
  2. https://thedroneely.com/
  3. https://thedroneely.com/posts/
  4. https://thedroneely.com/projects/
  5. https://thedroneely.com/about/
  6. https://thedroneely.com/contact/
  7. https://thedroneely.com/abstracts/
  8. https://ko-fi.com/thedroneely
  9. https://thedroneely.com/tags/k8s/
  10. https://thedroneely.com/tags/lxc/
  11. https://thedroneely.com/posts/kubernetes-in-a-linux-container/#isso-thread
  12. https://thedroneely.com/posts/rss.xml
  13. https://thedroneely.com/images/kubernetes-in-a-linux-container.png
  14. https://kubernetes.io/
  15. https://thedroneely.com/posts/kubernetes-in-a-linux-container/#the-base-system
  16. https://thedroneely.com/posts/kubernetes-in-a-linux-container/#code-block-252f953
  17. https://docs.docker.com/engine/reference/commandline/build/
  18. https://docs.docker.com/engine/reference/commandline/export/
  19. https://thedroneely.com/posts/kubernetes-in-a-linux-container/#code-block-7df8ff2
  20. https://thedroneely.com/posts/kubernetes-in-a-linux-container/#the-container-configuration
  21. https://thedroneely.com/posts/kubernetes-in-a-linux-container/#code-block-aaea7b4
  22. https://thedroneely.com/posts/kubernetes-in-a-linux-container/#kubernetes-cluster-installation
  23. https://angristan.xyz/2018/02/setup-network-bridge-lxc-net/
  24. https://thedroneely.com/posts/kubernetes-in-a-linux-container/#code-block-66df9e3
  25. https://www.thedroneely.com/git/thedroneely/playbooks/tree/roles/k8s/main.yml
  26. https://kubernetes.io/docs/tasks/access-application-cluster/web-ui-dashboard/
  27. https://thedroneely.com/images/ansible-kubernetes-lxc.gif
  28. https://www.thedroneely.com/posts/kubernetes-in-a-linux-container.md
  29. https://thedroneely.com/posts/website-auditing-tools/
  30. https://thedroneely.com/posts/web-browsers/
  31. https://thedroneely.com/posts/writing-strategy/
  32. https://git.sr.ht/~sircmpwn/openring
  33. https://drewdevault.com/2022/11/12/In-praise-of-Plan-9.html
  34. https://drewdevault.com/
  35. https://mxb.dev/blog/the-indieweb-for-everyone/
  36. https://mxb.dev/
  37. https://www.taniarascia.com/simplifying-drag-and-drop/
  38. https://www.taniarascia.com/
  39. https://thedroneely.com/posts/kubernetes-in-a-linux-container#isso-thread
  40. https://thedroneely.com/posts/kubernetes-in-a-linux-container#the-base-system
  41. https://thedroneely.com/posts/kubernetes-in-a-linux-container#code-block-252f953
  42. https://thedroneely.com/posts/kubernetes-in-a-linux-container#code-block-7df8ff2
  43. https://thedroneely.com/posts/kubernetes-in-a-linux-container#the-container-configuration
  44. https://thedroneely.com/posts/kubernetes-in-a-linux-container#code-block-aaea7b4
  45. https://thedroneely.com/posts/kubernetes-in-a-linux-container#kubernetes-cluster-installation
  46. https://thedroneely.com/posts/kubernetes-in-a-linux-container#code-block-66df9e3
  47. https://thedroneely.com/posts/cooking-and-baking-linux-distributions-in-nix/
  48. https://thedroneely.com/posts/making-web-pages/
  49. https://thedroneely.com/posts/kubernetes-in-a-linux-container/
  50. https://thedroneely.com/archives/abstracts/
  51. https://thedroneely.com/posts/installing-isso-from-source/
  52. https://thedroneely.com/projects/bulma-resume/
  53. https://drewdevault.com/2022/09/16/Open-source-matters.html
  54. https://mxb.dev/blog/make-free-stuff/
  55. https://thedroneely.com/sitemap.xml
  56. https://thedroneely.com/index.json
  57. https://thedroneely.com/resume/
  58. https://gitlab.com/tdro
  59. https://github.com/tdro
  60. https://codeberg.org/tdro
  61. https://thedroneely.com/analytics
  62. https://thedroneely.com/posts/kubernetes-in-a-linux-container#
  63. https://creativecommons.org/licenses/by-sa/2.0/
  64. https://thedroneely.com/git/thedroneely/thedroneely.com
  65. https://opensource.org/licenses/GPL-3.0
  66. https://www.thedroneely.com/
  67. https://thedroneely.com/posts/kubernetes-in-a-linux-container/#