{"id":22709234,"date":"2023-06-10T07:00:45","date_gmt":"2023-06-10T14:00:45","guid":{"rendered":"https:\/\/thenewstack.io\/?p=22709234"},"modified":"2023-06-06T08:44:43","modified_gmt":"2023-06-06T15:44:43","slug":"deploy-a-kubernetes-development-environment-with-kind","status":"publish","type":"post","link":"https:\/\/thenewstack.io\/deploy-a-kubernetes-development-environment-with-kind\/","title":{"rendered":"Deploy a Kubernetes Development Environment with Kind"},"content":{"rendered":"\n
Let me set the stage: You’re just starting your journey into Kubernetes and you’re thrilled at the idea of developing your first application or service. Your first step is to deploy a Kubernetes cluster so you can start building but almost immediately realize how challenging a task that is.<\/p>\n
All you wanted to do was take those first steps into the world of container development but actually getting Kubernetes up and running in a decent amount of time has proven to be a bit of a challenge<\/a>.<\/p>\n Would that there was something a bit kinder.<\/p>\n There is and it’s called kind.<\/p>\n From the official kind website<\/a>: kind is a tool for running local Kubernetes clusters using Docker container “nodes.” kind was primarily designed for testing Kubernetes itself but may be used for local development or continuous integration.<\/p>\n Kind is one of the easiest ways of starting out with Kubernetes development, especially if you’re just beginning your work with containers. In just a few minutes you can get kind installed and running, ready for work.<\/p>\n Let me show you how it’s done.<\/p>\n You can install kind on Linux, macOS, and Windows. I’ll demonstrate how to install kind on all three platforms. Before you install kind on your operating system of choice, you will need to have both Docker and Go installed. I’ll demonstrate it on Ubuntu Server 22.04. If you use a different Linux distribution, you’ll need to alter the installation steps accordingly.<\/p>\n The first thing to do is install Docker. Here’s how on Each OS.<\/p>\n Log into your Ubuntu instance and access a terminal window. Add the official Docker GPG key with the command:<\/p>\n Add the Docker repository:<\/p>\n Install the necessary dependencies with the command:<\/p>\n Update apt:<\/p>\n Install the latest version of the Docker CE runtime engine:<\/p>\n Add your user to the docker group with the command:<\/p>\n Log out and log back in for the changes to take effect.<\/p>\n The easiest method of installing Docker on macOS and Windows is by way of Docker Desktop. You can download the installers for macOS Intel<\/a>, macOS Apple Silicon<\/a>, or Windows<\/a>, double-click the files, and walk through the installation wizards.<\/p>\n Next, install Go. Here’s how.<\/p>\n To install Go on Ubuntu, open a terminal window and issue the command:<\/p>\n To install Go on macOS or Windows, simply download and run the installer file which can be found for macOS Intel<\/a>, macOS Apple Silicon<\/a>, and Windows<\/a>.<\/p>\n Now, we can install kind. Here’s how for each platform.<\/p>\n Download the binary file with the command:<\/p>\n Give the file the necessary permissions with:<\/p>\n Move it to \/usr\/bin with:<\/p>\n Open the terminal application. For macOS Intel, download kind with:<\/p>\n For Apple Silicon, issue the command:<\/p>\n Give the file executable permissions with:<\/p>\n Move kind so that it can be run globally with the command:<\/p>\n Open the terminal window app. Download kind with:<\/p>\n Move the executable file to the directory of your choice with the command:<\/p>\n Where DIRECTORY is the name of the directory to house kind.<\/p>\n It’s now time to deploy your first Kubernetes cluster with kind. Let’s create one called tns-test with the command:<\/p>\n You should see the following output in the terminal window:<\/p>\n ✓ Ensuring node image (kindest\/node:v1.24.0) 🖼<\/em><\/p>\n ✓ Preparing nodes 📦<\/em><\/p>\n ✓ Writing configuration 📜<\/em><\/p>\n ✓ Starting control-plane 🕹️<\/em><\/p>\n ✓ Installing CNI 🔌<\/em><\/p>\n ✓ Installing StorageClass 💾<\/em><\/p>\n Once the output completes, you’re ready to go. One thing to keep in mind, however, is that the command only deploys a single node cluster. Say you have to start developing on a multinode cluster. How do you pull that off? First, you would need to delete the single node cluster with the command:<\/p>\n Next, you must create a YML file that contains the information for the nodes. Do this with the command:<\/p>\n In that file, paste the following contents:<\/p>\n Save and close the file. You can then deploy with the command:<\/p>\n To verify your cluster is running, issue the command:<\/p>\n You should see tns-multi-test<\/em> in the output.<\/p>\n If you want to interact with kubectl, you first must install it. On Ubuntu, that’s as simple as issuing the command:<\/p>\nWhat You’ll Need<\/h2>\n
Installing Docker<\/h2>\n
Linux<\/h3>\n
curl -fsSL https:\/\/download.docker.com\/linux\/ubuntu\/gpg &&\r\n\r\n| sudo gpg --dearmor -o \/usr\/share\/keyrings\/docker-archive-keyring.gpg<\/pre>\n
echo \"deb [arch=amd64 signed-by=\/usr\/share\/keyrings\/docker-archive-keyring.gpg] https:\/\/download.docker.com\/linux\/ubuntu $(lsb_release -cs) stable\" | sudo tee \/etc\/apt\/sources.list.d\/docker.list > \/dev\/null<\/pre>\n
sudo apt-get install apt-transport-https ca-certificates curl gnupg lsb-release git -y<\/pre>\n
sudo apt-get update<\/pre>\n
sudo apt-get install docker-ce docker-ce-cli containerd.io -y<\/pre>\n
sudo usermod -aG docker $USER<\/pre>\n
MacOS\/Windows<\/h3>\n
Installing Go<\/h2>\n
Ubuntu Linux<\/h3>\n
sudo apt-get install golang-go -y<\/pre>\n
MacOS\/Windows<\/h3>\n
Installing kind<\/h2>\n
Linux<\/h3>\n
curl -Lo .\/kind https:\/\/kind.sigs.k8s.io\/dl\/v0.14.0\/kind-linux-amd64<\/pre>\n
chmod +x kind<\/pre>\n
sudo mv kind \/usr\/bin\/<\/pre>\n
MacOS<\/h3>\n
[ $(uname -m) = x86_64 ]&& curl -Lo .\/kind https:\/\/kind.sigs.k8s.io\/dl\/v0.14.0\/kind-darwin-amd64<\/pre>\n
[ $(uname -m) = arm64 ] && curl -Lo .\/kind https:\/\/kind.sigs.k8s.io\/dl\/v0.14.0\/kind-darwin-arm64<\/pre>\n
chmod +x kind<\/pre>\n
mv .\/kind \/usr\/local\/bin\/kind<\/pre>\n
Windows<\/h3>\n
curl.exe -Lo kind-windows-amd64.exe https:\/\/kind.sigs.k8s.io\/dl\/v0.14.0\/kind-windows-amd64<\/pre>\n
Move-Item .\\kind-windows-amd64.exe c:\\DIRECTORY\\kind.exe<\/pre>\n
Create a Dev Environment<\/h2>\n
kind create cluster --name=tns-test<\/pre>\n
kind delete cluster --name=tns-test<\/pre>\n
nano kindnodes.yml<\/pre>\n
kind: Cluster\r\napiVersion: kind.x-k8s.io\/v1alpha4\r\nnodes:\r\n- role: control-plane\r\n- role: worker<\/pre>\n
kind create cluster --name=tns-multi-test --config=kindnodes.yml<\/pre>\n
kind get clusters<\/pre>\n
sudo snap install kubectl --classic<\/pre>\n