Pods are the smallest deployable units in Kubernetes, capable of hosting one or more containers. While directly creating Pods isn’t typically the recommended approach for production deployments, understanding how to work with Pods is fundamental to grasping Kubernetes concepts.
Kubernetes has become the de facto standard for container orchestration, but getting started can be intimidating. In this tutorial, we’ll walk through the process of creating a pod on Kubernetes using a Makefile. This approach simplifies the process and makes it easy to reproduce, perfect for beginners and experienced developers looking to streamline their workflow.
In this guide, we’ll use a Makefile to simplify the process, making it easy for you to follow along and experiment on your own.
requirements
Before we begin, make sure you have the following set up on your computer:
- Docker
- Kind (Kubernetes in Docker)
If you haven’t installed these tools yet, don’t worry! Check out the links in the video description for my tutorials on installing them on Windows, Mac, and Ubuntu.
Steps
1. Clone the Repository
First, we’ll clone the repository containing our Makefile and Kubernetes configurations:
git clone git@github.com:thiagousa/youtube.git
cd youtube/20/
This command clones the repository and changes to the project directory.
2. Create a Kind Cluster
Next, we’ll create a Kubernetes cluster using Kind:
make create-cluster
This command creates a Kind cluster named “pod” using a predefined configuration.
3. Create a Pod
Now, let’s create our first pod:
make create-pod
This command creates a pod running the latest version of nginx.
4. List Pods
To verify that our pod was created successfully, we can list all pods:
make list-pods
This will display all pods in the current namespace, including our newly created nginx pod.
5. Apply Pod Configuration
If we want to use a custom pod configuration, we can apply it using:
make apply-pod-config
This applies the configuration from the pod.yaml
file.
6. Execute Commands in the Pod
To run commands inside the pod, use:
make exec-pod
This opens a bash shell inside the Nginx container.
7. Check NGINX Configuration
We can verify the NGINX configuration with:
check-nginx
This runs the nginx -t
command inside the pod to check the configuration.
8. Delete the Pod
When we’re done, we can delete the pod:
make delete-pod
This removes the pod we created.
9. Clean Up
Finally, to delete the entire Kind cluster:
make delete-all
This command deletes the Kind cluster, cleaning up all resources.
Conclusion
Congratulations! You’ve just learned how to create, interact with, and delete a Pod on Kubernetes using a Makefile. This approach simplifies the process and makes it easy to reproduce, which is great for learning and experimentation.
Remember, while we’ve created a Pod directly in this tutorial, it’s important to note that this isn’t typically how you’d deploy applications in a production Kubernetes environment. For more advanced deployment strategies, check out my video on best practices for Kubernetes deployments (link in the description).
The power of Kubernetes lies in its ability to orchestrate complex applications across multiple containers and Pods. This tutorial has given you a solid foundation to build upon as you explore more advanced Kubernetes concepts.