Skip to content

Instantly share code, notes, and snippets.

@stolsma
Last active August 7, 2022 16:19
Show Gist options
  • Select an option

  • Save stolsma/12457f4db016a86fea631fecee419989 to your computer and use it in GitHub Desktop.

Select an option

Save stolsma/12457f4db016a86fea631fecee419989 to your computer and use it in GitHub Desktop.
Centos repo files for installing KVM, docker, kubernetes, Helm and Tiller

Installing KVM, libvirt, Docker-CE and Kubernetes on Centos 7.x

Installing KVM

Install KVM

yum install qemu-kvm qemu-img virt-manager libvirt libvirt-python libvirt-client virt-install virt-viewer bridge-utils systemctl start libvirtd systemctl enable libvirtd lsmod | grep kvm

If needed, install xwindows for use of graphical virt manager:

sudo yum groupinstall "GNOME Desktop" "Graphical Administration Tools" sudo ln -sf /lib/systemd/system/runlevel5.target /etc/systemd/system/default.target reboot

Before Start creating VMs, let’s first create the bridge interface. Bridge interface is required if you want to access virtual machines from outside of your hypervisor network.

cd /etc/sysconfig/network-scripts/ cp ifcfg-eno1 ifcfg-br0

Edit the Interface file and set followings:

[root@ network-scripts]# vi ifcfg-eno1 TYPE=Ethernet BOOTPROTO=static DEVICE=eno1 ONBOOT=yes BRIDGE=br0

Edit the Bridge file (ifcfg-br0) and set the followings:

[root@ network-scripts]# vi ifcfg-br0 TYPE=Bridge BOOTPROTO=static DEVICE=br0 ONBOOT=yes

Replace the IP address and DNS server details as per your setup.

Restart the network Service to enable the bridge interface.

systemctl restart network

Check the Bridge interface using below command:

ip addr show br0

Installing Docker and K8S

Disable SELinux and swap

First we need to disable both SELinux and swap. Issue the following commands:

setenforce 0 sed -i --follow-symlinks 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux

Next, disable swap with the following command:

swapoff -a

We must also ensure that swap isn't re-enabled during a reboot on each server. Open up the /etc/fstab and comment out the swap entry like this:

# /dev/mapper/centos-swap swap swap defaults 0 0

Enable br_netfilter

Enable the br_netfilter kernel module. This is done with the following commands:

modprobe br_netfilter echo '1' > /proc/sys/net/bridge/bridge-nf-call-iptables

Install Docker-ce

Install the Docker-ce dependencies with the following command:

yum install -y yum-utils device-mapper-persistent-data lvm2

Next, add the Docker-ce repository with the command:

yum-config-manager --add-repo https://gist.githubusercontent.com/stolsma/12457f4db016a86fea631fecee419989/raw/ef412fc4e282a3d83fa216b0be53757ecf1edf37/docker-ce.repo

Install Docker-ce with the command:

yum install -y docker-ce

Install Kubernetes

First we need to create a repository entry for yum. To do this, issue the following command :

yum-config-manager --add-repo https://gist.githubusercontent.com/stolsma/12457f4db016a86fea631fecee419989/raw/ef412fc4e282a3d83fa216b0be53757ecf1edf37/kubernetes.repo

Install Kubernetes with the command:

yum install -y kubelet kubeadm kubectl

Once the installation completes, reboot the machine.

Cgroup changes

Now we need to ensure that both Docker-ce and Kubernetes belong to the same control group (cgroup). By default, Docker should already belong to cgroupfs (you can check this with the command docker info | grep -i cgroup). To add Kubernetes to this, issue the command:

sed -i 's/cgroup-driver=systemd/cgroup-driver=cgroupfs/g' /etc/systemd/system/kubelet.service.d/10-kubeadm.conf

Restart the systemd daemon and the kubelet service with the commands:

systemctl daemon-reload systemctl restart kubelet

Initialize the Kubernetes cluster

We're now ready to initialize the Kubernetes cluster. This is done on kubemaster (and only on that machine). On kubemaster, issue the command (again, adjusting the IP addresses to fit your needs):

kubeadm init --apiserver-advertise-address=<MASTER_IP> --pod-network-cidr=<POD_NETWORK>/<POD_NETWORK_SUBNET_BITS>

When this completes (it'll take anywhere from 30 seconds to 5 minutes), the output should include the joining command for your nodes.

Once that completes, head over to kube2 and issue the command (adjusting the IP address to fit your needs):

kubeadm join <MASTER_IP>:6443 --token TOKEN --discovery-token-ca-cert-hash DISCOVERY_TOKEN

Where TOKEN and DISCOVERY_TOKEN are the tokens displayed after the initialization command completes.

Configuring Kubernetes

Before Kubernetes can be used, we must take care of a bit of configuration. Issue the following three commands (to create a new .kube configuration directory, copy the necessary configuration file, and give the file the proper ownership):

mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config

Deploy flannel network

Now we must deploy the flannel network to the cluster with the command:

kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

Checking your nodes

Once the deploy command completes, you should be able to see both nodes on the master, by issuing the command kubectl get nodes

All ready

Congratulations, you now have a Kubernetes cluster ready for pods.

Remove Kubernetes from your system

sudo kubeadm reset

[docker-ce-stable]
name=Docker CE Stable - $basearch
baseurl=https://download.docker.com/linux/centos/7/$basearch/stable
enabled=1
gpgcheck=1
gpgkey=https://download.docker.com/linux/centos/gpg
[docker-ce-stable-debuginfo]
name=Docker CE Stable - Debuginfo $basearch
baseurl=https://download.docker.com/linux/centos/7/debug-$basearch/stable
enabled=0
gpgcheck=1
gpgkey=https://download.docker.com/linux/centos/gpg
[docker-ce-stable-source]
name=Docker CE Stable - Sources
baseurl=https://download.docker.com/linux/centos/7/source/stable
enabled=0
gpgcheck=1
gpgkey=https://download.docker.com/linux/centos/gpg
[docker-ce-edge]
name=Docker CE Edge - $basearch
baseurl=https://download.docker.com/linux/centos/7/$basearch/edge
enabled=0
gpgcheck=1
gpgkey=https://download.docker.com/linux/centos/gpg
[docker-ce-edge-debuginfo]
name=Docker CE Edge - Debuginfo $basearch
baseurl=https://download.docker.com/linux/centos/7/debug-$basearch/edge
enabled=0
gpgcheck=1
gpgkey=https://download.docker.com/linux/centos/gpg
[docker-ce-edge-source]
name=Docker CE Edge - Sources
baseurl=https://download.docker.com/linux/centos/7/source/edge
enabled=0
gpgcheck=1
gpgkey=https://download.docker.com/linux/centos/gpg
[docker-ce-test]
name=Docker CE Test - $basearch
baseurl=https://download.docker.com/linux/centos/7/$basearch/test
enabled=0
gpgcheck=1
gpgkey=https://download.docker.com/linux/centos/gpg
[docker-ce-test-debuginfo]
name=Docker CE Test - Debuginfo $basearch
baseurl=https://download.docker.com/linux/centos/7/debug-$basearch/test
enabled=0
gpgcheck=1
gpgkey=https://download.docker.com/linux/centos/gpg
[docker-ce-test-source]
name=Docker CE Test - Sources
baseurl=https://download.docker.com/linux/centos/7/source/test
enabled=0
gpgcheck=1
gpgkey=https://download.docker.com/linux/centos/gpg
[docker-ce-nightly]
name=Docker CE Nightly - $basearch
baseurl=https://download.docker.com/linux/centos/7/$basearch/nightly
enabled=0
gpgcheck=1
gpgkey=https://download.docker.com/linux/centos/gpg
[docker-ce-nightly-debuginfo]
name=Docker CE Nightly - Debuginfo $basearch
baseurl=https://download.docker.com/linux/centos/7/debug-$basearch/nightly
enabled=0
gpgcheck=1
gpgkey=https://download.docker.com/linux/centos/gpg
[docker-ce-nightly-source]
name=Docker CE Nightly - Sources
baseurl=https://download.docker.com/linux/centos/7/source/nightly
enabled=0
gpgcheck=1
gpgkey=https://download.docker.com/linux/centos/gpg
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg
https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment