Featured image of post Kubernetes Basics: Cluster Setup & Deployment

Kubernetes Basics: Cluster Setup & Deployment

Discover how to set up a Kubernetes cluster and deploy containerized applications. Boost your DevOps skills with essential K8s knowledge

In this tutorial, we’ll walk you through the basics of Kubernetes, focusing on setting up a Kubernetes cluster and deploying a containerized application. By the end of this guide, you’ll have a solid understanding of Kubernetes fundamentals and be ready to manage containerized applications with ease.

Article Outline

Introduction to Kubernetes
Kubernetes Components
  a. Nodes
  b. Pods
  c. Services
  d. Deployments
Setting Up a Kubernetes Cluster
  a. Using a managed Kubernetes service
  b. Setting up a cluster manually
Deploying a Containerized Application
  a. Creating a deployment
  b. Exposing the application using a service
  c. Scaling the application
  d. Updating the application
Conclusion

Part 1: Introduction to Kubernetes

Kubernetes is an open-source container orchestration platform that automates the deployment, scaling, and management of containerized applications. Developed by Google and now maintained by the Cloud Native Computing Foundation (CNCF), Kubernetes has become the industry standard for container orchestration, supporting a wide range of container runtimes, including Docker and containerd.

Part 2: Kubernetes Components

Kubernetes uses various components to manage containerized applications:

a. Nodes: These are the worker machines that run containers. Nodes can be virtual or physical machines, and a Kubernetes cluster can consist of one or more nodes.

b. Pods: The smallest and simplest unit in Kubernetes, pods are used to deploy containers. A pod can contain one or more containers that share the same network namespace and storage volumes.

c. Services: A Kubernetes service is an abstraction that defines a logical set of pods and a policy to access them. Services are used to expose applications running in pods to the network, either within the cluster or externally.

d. Deployments: Deployments are used to declaratively manage the desired state of your containerized application. They can automatically manage and update pods based on the specified configuration.

Part 3: Setting Up a Kubernetes Cluster

To set up a Kubernetes cluster, you have two options:

a. Using a managed Kubernetes service: Many cloud providers offer managed Kubernetes services, such as Google Kubernetes Engine (GKE), Amazon Elastic Kubernetes Service (EKS), and Azure Kubernetes Service (AKS). These services simplify cluster setup and management by automating tasks like node provisioning and updates.

b. Setting up a cluster manually: For more control over your cluster, you can set it up manually using tools like kubeadm, Minikube, or Kops. This approach requires more hands-on management but offers greater customization.

Part 4: Deploying a Containerized Application

Once your Kubernetes cluster is set up, follow these steps to deploy a containerized application:

a. Creating a deployment: Write a YAML manifest file to define your application’s deployment, specifying the container image, desired replicas, and other configuration details. Use the kubectl apply command to create the deployment.

For example:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp-deployment
spec:
  replicas: 3
  selector:
    matchLabels:
      app: myapp
  template:
    metadata:
      labels:
        app: myapp
    spec:
      containers:
      - name: myapp-container
        image: myapp-image:v1
        ports:
        - containerPort: 8080

b. Exposing the application using a service: To make your application accessible, create a Kubernetes service by defining a YAML manifest file and applying it with kubectl apply. The service will expose the application on a specific port or load balancer, depending on the chosen service type.

apiVersion: v1
kind: Service
metadata:
  name: myapp-service
spec:
  selector:
    app: myapp
  ports:
    - protocol: TCP
      port: 80
      targetPort: 8080
  type: LoadBalancer

c. Scaling the application: To scale your application, update the replicas field in your deployment manifest, and reapply the configuration using kubectl apply. Kubernetes will automatically create or remove pods to match the desired replica count.

# Update the replicas field in your deployment manifest
# For example, change the replicas from 3 to 5, then run:

kubectl apply -f myapp-deployment.yaml

d. Updating the application: To update your application, modify the container image or other configuration details in your deployment manifest, and reapply the updated manifest using kubectl apply. Kubernetes will perform a rolling update, replacing old pods with new ones while maintaining the desired replica count and minimizing downtime.

# Update the container image or other configuration details in your deployment manifest
# For example, change the image from myapp-image:v1 to myapp-image:v2, then run:

kubectl apply -f myapp-deployment.yaml

Part 5: Conclusion

Congratulations! You’ve now learned the basics of Kubernetes, including its key components, setting up a cluster, and deploying a containerized application. As you become more comfortable with Kubernetes, you can explore additional features like persistent storage, ingress controllers, and custom resource definitions to further enhance your container orchestration skills.

For more basic Kubernetes information I highly recommend you read: Phippy goes to the zoo by the Cloud Native Computing Foundation. Yes, it looks like a kid’s book but it clears out a lot of decent information.

By mastering Kubernetes basics, you’ll be well-equipped to manage and scale containerized applications efficiently, and take your DevOps and sysadmin career to new heights. Don’t forget to keep learning and experimenting with new Kubernetes features and best practices to stay ahead in the rapidly evolving world of container orchestration. update, replacing old pods with new ones

Built with Hugo