DEV Community

Ammar Yasir Ali
Ammar Yasir Ali

Posted on

Getting Started with Kubernetes: A Beginner’s Guide

Introduction:

Kubernetes, often abbreviated as K8s, has become a cornerstone technology in modern application development and deployment. It provides a robust framework for managing containerized applications, scaling them effortlessly, and ensuring high availability. If you’re new to Kubernetes, this article will guide you through the basics, including what Kubernetes is, how to set it up locally and on remote environments like AWS, and how to use it to deploy a basic client-server application written in Go (GoLang).

What is Kubernetes?

Kubernetes, often abbreviated as K8s, is an open-source container orchestration platform. It provides a robust and scalable infrastructure for deploying, managing, and scaling containerized applications. Whether you have a small application or a complex microservices architecture, Kubernetes simplifies deploying and managing these applications, making them more reliable and resilient.

Setting up Kubernetes:

To get started with Kubernetes, you have two options: setting it up locally or on a remote environment such as AWS. Let’s look at both scenarios:

Local Setup:

For a local setup, you can use a tool like Minikube. Follow these steps:

Step 1: Install Minikube:

Visit the Minikube website https://minikube.sigs.k8s.io/ and follow the installation instructions for your operating system.

Step 2: Start Minikube:

Open a terminal and run the command minikube start to launch a local Kubernetes cluster.

Step 3: Verify the Cluster:

Run kubectl cluster-info to ensure your cluster is up and running. You should see information about the cluster and its components.

Remote Setup (AWS):

If you prefer using a remote environment like AWS, you can utilize the managed Kubernetes service called Amazon Elastic Kubernetes Service (EKS). Here’s a brief overview of the setup:

Step 1: Create an EKS Cluster:

Log in to your AWS console, navigate to EKS, and create a new cluster. Follow the step-by-step instructions provided by AWS to create your cluster.

Step 2: Configure kubectl:

Install the AWS CLI and configure it with your AWS credentials. Then, install kubectl and configure it to interact with your EKS cluster. AWS provides detailed documentation on how to achieve this.

Using Kubernetes with a Basic App:

Now that you have Kubernetes set up let’s walk through creating a basic client-server app using Go and deploying it on Kubernetes.

Step 1: Write the Go Application:

Write a simple client-server application in Go. You can create a server that listens on a specific port and a client that sends requests to that server. Numerous resources are available online for learning Go and creating basic client-server applications. You can also find an example application/project with client and server code and Dockerfiles and Kubernetes Manifest (yaml) files on my GitHub repository: https://github.com/ammar-alee/SimpleGoClientServer.

Step 2: Containerize the App:

Create a Dockerfile for your application to containerize it. This file describes the steps to build an image for your application.

Step 3: Build and Push the Docker Image:

Build the Docker image by running docker build -t your-image-name . in the application directory. Once the image is built, push it to a container registry like Docker Hub or Amazon ECR.

Step 4: Create Kubernetes Deployment:

Write a Kubernetes deployment manifest that describes how to run your application as a container within a Kubernetes cluster. Specify the image you pushed to the container registry, desired replicas, ports, and other necessary configurations.

Step 5: Deploy the Application:

Apply the deployment manifest using kubectl apply -f your-manifest.yaml to deploy your application to the Kubernetes cluster.

Use kubectl get pods to verify that your application pods are running. You can also access the logs and other information using kubectl logs -f <POD_NAME > and kubectl describe pod <POD_NAME>.

Conclusion:

Congratulations! You have now embarked on your journey into the exciting world of Kubernetes. In this guide, we explained what Kubernetes is, how to set it up in local and remote environments, and demonstrated deploying a basic client-server app using Go. As you dive deeper, you’ll discover the power and flexibility that Kubernetes offers in managing containerized applications. Happy Kubernet-ing!

Top comments (0)