This content originally appeared on DEV Community and was authored by Amanda Guan
Introduction
In this article, we'll recap the essential parts of the "Getting Started with Kubernetes" course, focusing on basic concepts, microservices, containerization, and practical steps for deploying applications both locally and in the cloud. We'll integrate illustrations to visualize key concepts and provide code snippets and terminal commands for practical understanding.
What Is Kubernetes?
Kubernetes is an open-source platform that automates the deployment, scaling, and operation of application containers. It orchestrates containerized applications to ensure reliable operations.
What Are Microservices?
Microservices are a design pattern that allows for fault isolation and the independent management of application features. They enable faster development and iteration by smaller, specialized teams but can be complex to manage.
What Is Cloud Native?
Cloud-native applications are specifically designed to leverage the advantages of cloud computing, such as scaling on demand, self-healing, supporting zero-downtime rolling updates, and running anywhere with Kubernetes.
Why Do We Need Kubernetes?
Kubernetes organizes microservices, scales applications automatically, self-heals by replacing failed containers, and allows for seamless updates with zero downtime, making it essential for managing complex microservices architectures.
Illustration: Microservices Architecture
What Does Kubernetes Look Like?
Masters and Nodes
A Kubernetes cluster consists of Master Nodes (control plane) and Worker Nodes (running user applications). Masters handle the cluster's control plane, while Nodes execute the application workloads.
Illustration: Kubernetes Cluster Components
Kubernetes in the Cloud with Linode Kubernetes Engine (LKE)
LKE simplifies the setup and management of Kubernetes clusters in the cloud, handling the control plane while users manage their applications and worker nodes.
Introduction to Containerization
Containerization involves packaging an application with its dependencies and configurations into a container image. This ensures consistent operation across different environments.
Build and Host the Image
Steps to containerize the application include writing a Dockerfile, building the image, and pushing it to a registry like Docker Hub.
Dockerfile Example
FROM node:current-slim
# Copy source code to /src in container
COPY . /src
# Install app and dependencies into /src in container
RUN cd /src; npm install
# Document the port the app listens on
EXPOSE 8080
# Run this command (starts the app) when the container starts
CMD cd /src && node ./app.js
Illustration: Containerization Workflow
Get Hands-on With Kubernetes
Setup Required
Ensure you have Docker Desktop, Git, and optional accounts for Linode and DockerHub. Familiarize yourself with the kubectl
command-line tool.
Deploy the Application Locally
-
Define the Pod in
pod.yml
:
apiVersion: v1
kind: Pod
metadata:
name: first-pod
labels:
project: qsk-course
spec:
containers:
- name: web-ctr
image: educative1/qsk-course:1.0
ports:
- containerPort: 8080
- Deploy the Pod:
kubectl apply -f pod.yml
- Verify Pod is running:
kubectl get pods
- Forward port to access the application:
kubectl port-forward --address 0.0.0.0 first-pod 8080:8080
- Access at
http://localhost:8080
.
Illustration: Kubernetes Pod Definition
Deploy the Application on Cloud
-
Copy-paste kubeconfig to
config
file and configurekubectl
:
export KUBECONFIG=/usercode/config
- Deploy the Pod:
kubectl apply -f pod.yml
Connect to the Application
-
Define a Service in
svc-cloud.yml
orsvc-local.yml
:
apiVersion: v1
kind: Service
metadata:
name: svc-local
spec:
type: NodePort
selector:
app: web
ports:
- protocol: TCP
port: 80
targetPort: 8080
- Deploy the Service:
kubectl apply -f svc-local.yml
- Verify the Service:
kubectl get svc
- Access the application via the Service.
Kubernetes Deployments
-
Define Deployment in
deploy.yml
:
apiVersion: apps/v1
kind: Deployment
metadata:
name: qsk-deploy
spec:
replicas: 5
selector:
matchLabels:
project: qsk-course
template:
metadata:
labels:
project: qsk-course
spec:
containers:
- name: hello-pod
image: educative1/qsk-course:1.0
ports:
- containerPort: 8080
- Deploy the Deployment:
kubectl apply -f deploy.yml
-
Self-healing from failures:
- Monitor and manually delete a Pod to see Kubernetes self-heal.
- Delete a Node and observe automatic Pod replacement.
Illustration: Kubernetes Deployment
Scaling an Application
-
Scale up:
- Edit
deploy.yml
to set replicas to 10. - Apply changes and verify:
kubectl apply -f deploy.yml kubectl get pods
- Edit
Scale down:
kubectl scale --replicas=5 deployment/qsk-deploy
kubectl get pods
Rolling Update
-
Perform rolling updates by modifying
deploy.yml
:- Set
minReadySeconds
,maxSurge
, andmaxUnavailable
. - Apply updates and monitor progress.
- Set
Clean up resources after update:
kubectl delete deployment qsk-deploy
kubectl delete svc svc-local
Conclusion
The "Getting Started with Kubernetes" course provides a comprehensive overview of Kubernetes, from understanding microservices and cloud-native applications to deploying and managing containerized applications. Through practical exercises and hands-on labs, you gain the skills needed to effectively use Kubernetes in both local and cloud environments.
By following this recap and using the provided illustrations and code snippets, you should have a solid foundation to continue exploring and mastering Kubernetes.
This content originally appeared on DEV Community and was authored by Amanda Guan

Amanda Guan | Sciencx (2024-07-15T20:47:24+00:00) Recap of “Getting Started with Kubernetes” Course. Retrieved from https://www.scien.cx/2024/07/15/recap-of-getting-started-with-kubernetes-course/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.