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

PowerShell: Gather All Guess VM of All Hyper-V Clusters in the Domain

# getAllVms.ps1 $clusterName='*' function includeRSAT{ $ErrorActionPreference='stop' [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 #$rsatWindows7x32='https://download.microsoft.com/download/4/F/7/4F71806A-1C56-4EF2-9B4F-9870C4CFD2EE/Windows6.1-KB958830-x86-RefreshPkg.msu' $rsatWindows7x64='https://download.microsoft.com/download/4/F/7/4F71806A-1C56-4EF2-9B4F-9870C4CFD2EE/Windows6.1-KB958830-x64-RefreshPkg.msu' $rsatWindows81='https://download.microsoft.com/download/1/8/E/18EA4843-C596-4542-9236-DE46F780806E/Windows8.1-KB2693643-x64.msu' $rsat1709 = "https://download.microsoft.com/download/1/D/8/1D8B5022-5477-4B9A-8104-6A71FF9D98AB/WindowsTH-RSAT_WS_1709-x64.msu"…

A Quick Note On How To Preserve Client Source IP’s on K8s Services

namespace=ingress-nginx servicename=ingress-nginx-controller kubectl edit svc $servicename -n $namespace # edit this value from Cluster to…

How To Setup ClamAV Antivirus Scanner in Kubernetes

Assumptions: A Kubernetes cluster is already setupThese are installed prior: Helm, MetalLB Load Balancer,A static…
Other project: DragonCoin.com