Posted On April 18, 2019

Getting Started with Kubernetes on Linux

kimconnect 0 comments
blog.KimConnect.com >> Virtualization >> Getting Started with Kubernetes on Linux
Update 01-24-21: there’s new blog to succeed this article here.

1. Install Kubectl

Redhat-based commands:

# Add a new repo and use Yellowdog Updater Modified (yum) install
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[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
EOF
yum install -y kubectl

Debian-based commands:

# Obtain the kubectl public key for Apt. Pipe key to main then append output to apt sources directory 
sudo apt-get update && sudo apt-get install -y apt-transport-https
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
echo "deb https://kubernetes.io/blog/2023/08/31/legacy-package-repository-deprecation/ kubernetes-xenial main" | sudo tee -a /etc/apt/sources.list.d/kubernetes.list
sudo apt-get update
sudo apt-get install -y kubectl

2. Install Minikube

Although Minikube is useful for testing and development purposes, labs and production would necessitate multi-node Kubernetes systems as illustrated here.

For purposes of this article, Minikube is an implementation of Kubernetes cluster onto localhost using kvm2 driver or VirtualBox (prerequisites). VT-x/AMD-v virtualization must also be enabled in system BIOS for this to work. It’s a recommended step to test this simple deployment prior to applying more advanced deployments. Minikube works by starting a single node kubernetes cluster locally. It conveniently packages and configures a Linux VM, Docker and all Kubernetes components, optimized for local environment, a la carte.

First, install the virtual environment dependency. Minikube requires either VirtualBox or KVM. Since the latter is more robust and production-grade, here are some commands for various popular linux flavors.

Debian-based systems:

sudo apt -y install libvirt-clients libvirt-daemon-system qemu-kvm libvirt-bin virt-top libosinfo-bin libguestfs-tools virtinst bridge-utils
sudo modprobe vhost_net
sudo lsmod | grep vhost
echo "vhost_net" | sudo tee -a /etc/modules

Redhat-based systems:

sudo yum install libvirt-daemon-kvm qemu-kvm
sudo systemctl enable libvirtd.service
sudo systemctl start libvirtd.service

# Add current login to libvirt group
sudo usermod -a -G libvirt $(whoami)

# Join group
newgrp libvirt

# Install driver
curl -LO https://storage.googleapis.com/minikube/releases/latest/docker-machine-driver-kvm2 \
&& sudo install docker-machine-driver-kvm2 /usr/local/bin/

Second, Minikube is then ready to be plugged into the system. Here’s a manual method:

curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 && sudo install minikube-linux-amd64 /usr/local/bin/minikube

Minikube Commands:

# Set kvm2 as default driver for minikube, instead of VirtualBox
minikube config set vm-driver kvm2
# Initiate minikube
minikube start
# Deploy a hello-world container
kubectl run hello-minikube --image=k8s.gcr.io/echoserver:1.4 --port=8080
# Expose deployment service to the external network zone (NodePort)
kubectl expose deployment hello-minikube --type=NotePort
# List all pods of current deployment
kubectl get pod
# Check exposed hello-minikube html contents
curl $(minikube service hello-minikube --url)
# Delete the deployment
kubectl delete deployment hello-minikube
# Stop the local cluster
minikube stop
# Terminate minikube
minikube delete

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post

How to Clone VMWare Virtual Machine using CLI

1. SSH into the ESXi host to perform VM cloning via Command Line Interface (CLI)…

Set up ESX with QNAP iSCCI targets

1. Download Qfinder: http://download.qnap.com/webstart/QNAPQfinder_Windows.exe 2. Login as admin / admin; then, set a new password…

How To Change VMWare ESXi Hypervisor’s IP Address and Host Name

# List hypervisor's network interfaces esxcli network ip interface ipv4 get # Sample output [root@esx76:~]…
Other project: DragonCoin.com