Skip to main content

Command Palette

Search for a command to run...

Getting Started with Kubernetes on Ubuntu: A Beginner’s Hands-On Guide

Kubernetes Deployment

Updated
4 min read
Getting Started with Kubernetes on Ubuntu: A Beginner’s Hands-On Guide

This guide walks you through the fundamentals of Kubernetes using the Ubuntu terminal. It explains how to navigate Kubernetes documentation, work with both imperative and declarative commands, and manage applications using YAML files and kubectl commands. You’ll learn how to:

  • Create and edit Kubernetes YAML files with text editors like vim.

  • Use imperative commands (e.g., kubectl run, kubectl create deployment) to quickly create pods and deployments.

  • Use declarative format (kubectl apply -f file.yaml) to define and manage resources with YAML files.

  • Check the status and details of deployments, pods, services, and events.

  • Expose deployments for communication, view cluster IPs and endpoints, and scale replicas.

  • Finally, clean up by deleting deployments when they’re no longer needed.

In short, this guide is an introductory hands-on walkthrough of creating, scaling, exposing, and managing Kubernetes resources — a starting point for anyone who wants to practice Kubernetes directly from the terminal.

Navigate your way and know more about Kubernetes using the Ubuntu terminal.

Go to your browser and search for kubernetes.io.

Click on documentation and learn or search for what you want to learn about. Also, check the Kubernetes reference within the Kubernetes documentation.

Example:

To create a YAML file in Declarative format.

Run - vim main.yaml To open a text editor

Get your YAML code and paste it into the text editor. Type ecs:wq to save and exit.

After saving and exiting, run the kubectl create command.

To create a YAML file in an Imperative format.

Run - kubectl run (your container) —image=nginx

To Create a Deployment In Imperative Format

Run - kubectl create deployment (name of your deployment) —image=nginx To create an application and want it to run.

Run - kubectl get deployment To see if your deployment is created and ready. But if you have multiple deployments, you have to specify them.

Run - kubectl get event To see every detail related to both your minikube, nodes, etc.

Run - kubectl describe deployment (name of deployment) To provide you with much more information about your deployment.

Run - kubectl get deployment (your deployment name) -o yaml To show the detailed deployment in a YAML format in a declarative format.

Run - kubectl run nginx —image=(give your pod a name) To create a pod.

Run - kubectl get pod (name of pod) -o yaml To show the detailed pod in a YAML file format.

To Create a Deployment in a declarative format and Scale from 3 replicas to 6 replicas.

Run - vi (your deployment name).yaml To enter a text editor and input your YAML code.

Go to your browser and search kubernetes.io, navigate to documentation, and search for deployment. you will find the deployment commands.

We Are Creating A Deployment: The following is an example of a deployment. It creates a replica set to bring up three nginx pods.

Copy the code and go back to your Linux terminal within your text editor and paste the commands.

Edit the command to your desired format.

I will change the metadata name to my app name.

Add the same name everywhere you see app: delete nginx and write your app name.

Under container port: 80, write the protocol command and make sure it aligns like this:

- container port: 80

-protocol: TCP

Type esc:wq to save and exit.

After exiting Run - kubectl apply -f (your deployment name.yaml) To create your declarative YAML deployment file.

Run - kubectl get deployment To show all the deployments you have.

Run - kubectl get pods To see each pod with their different ID.

Run - kubectl expose deployment (your deployment name) To expose our deployment, that is to make it publicly accessible.

Run - kubectl get service (your deployment name) To check if your deployment is exposed successfully. You will only have a cluster IP.

Cluster IP: is basically for networking within your deployment, so that your pods can communicate internally with each other.

After having our default cluster IP.

Now, let’s get our endpoint. It will ensure each of the pods we replicated will get an endpoint, which is an IP address.

Run - kubectl get ep (your deployment name) To get endpoints (IP address) for both replicated deployments since the deployment comes with 3 replicas/pods.

Run - kubectl scale deployment (your deployment name) —replicas=6 To scale your replicas to 6 from 3.

Run - kubectl get deployment To see all the deployments you have.

Run - kubectl get pods To see each pod with their different ID.

Run - kubectl get pod -o wide To have a clearer view of your pods/replicas.

Run - kubectl get pod (your pod/replicaname -io) To check only one pod/replica.

Run - kubectl delete deployment (name of the deployment) To delete your deployment.

SUCCESS…..

Join me on this cloud adventure and elevate your tech skills! Sign in to the Azure portal, follow my easy instructions, and unleash the power of Being in the cloud.

Subscribe to my blog for more tech tips and tricks that will keep you ahead in the digital game. Your journey to mastering Cloud computing starts here!

🌟 Thank you for being a part of this incredible journey! Together, let's unlock new opportunities and make the most out of our digital experiences. Happy computing! 🌟