DEV Community

shah-angita
shah-angita

Posted on

Deploying Your First Application on a Kubernetes Cluster

Kubernetes is an orchestration platform that automates the deployment, scaling, and management of containerized applications. It helps developers focus on innovating and creating valuable products. In this tutorial, we will guide you through each step of deploying your first application on Kubernetes.

Prerequisites for Kubernetes Deployment

Before we begin, ensure that you have installed kubectl and have a Kubernetes environment set up. If you need to install kubectl, visit the installation tools page.

Step 1: Installing Kubernetes on Master and Worker Nodes

To start, you need to install Kubernetes on both the master and worker nodes. This can be done using tools like kubeadm or minikube.

Step 2: Creating a Deployment

To create a deployment, you will need to specify the container image for your application and the number of replicas you want to run. You can change this information later by updating your deployment. For your first deployment, we will use a hello-node application packaged in a Docker container that uses NGINX to echo back all requests.

kubectl create deployment kubernetes-bootcamp --image=gcr.io/google-samples/kubernetes-bootcamp:v1
Enter fullscreen mode Exit fullscreen mode

This command performs several actions:

  • Searches for a suitable node where an instance of the application can be run.
  • Schedules the application to run on that node.
  • Configures the cluster to reschedule the instance on a new node when needed.

Step 3: Listing Deployments

To list your deployments, use the kubectl get deployments command:

kubectl get deployments
Enter fullscreen mode Exit fullscreen mode

This will show you that there is one deployment running a single instance of your application. The instance is running inside a container on your node.

Step 4: Scaling Deployments

To scale your deployment, you can use the kubectl scale command:

kubectl scale deployment kubernetes-bootcamp --replicas=3
Enter fullscreen mode Exit fullscreen mode

This will increase the number of replicas to three, ensuring that your application can handle increased traffic.

Step 5: Exposing Applications to External Users

To expose your application to external users, you can create a service. There are two primary ways to create and manage resources: using the Kubernetes command line interface (kubectl) or using Infrastructure-as-Code tools like Terraform.

For this example, we will use kubectl to create a service:

apiVersion: v1
kind: Service
metadata:
  name: kubernetes-bootcamp
spec:
  selector:
    app: kubernetes-bootcamp
  ports:
  - name: http
    port: 80
    targetPort: 8080
  type: LoadBalancer
Enter fullscreen mode Exit fullscreen mode

Apply the service configuration using kubectl apply:

kubectl apply -f service.yml
Enter fullscreen mode Exit fullscreen mode

Step 6: Accessing the Application

Once the service is created, you can access your application using the service's IP address and port. For example, if the service is exposed on nodeIP:30009, you can access it by visiting http://nodeIP:30009 in your web browser.

Conclusion

In this tutorial, we have successfully deployed a todo application on a Kubernetes cluster. We have covered the basic steps of creating a deployment, scaling it, and exposing it to external users. By mastering these techniques, you can unlock the full potential of Kubernetes and achieve unparalleled efficiency and scalability in your application deployments.

Additional Resources

For more information on Kubernetes and platform engineering, check out the following resources:

Final Thoughts

Kubernetes provides a powerful set of tools and strategies for controlling deployment, reducing cost, and improving reliability. By utilizing features such as rollbacks, Pods, Deployments, and advanced deployment strategies, you can reduce downtime and ultimately save money on infrastructure and operational expenses.

Top comments (0)