Kubernetes (K8s) is an open-source container orchestration platform designed to automate the deployment, scaling, and management of containerized applications. It provides a robust framework for managing containerized applications across a cluster of machines. This guide will cover the basics of Kubernetes and include hands-on lab exercises to help you practice.
Kubernetes is a container orchestration platform that automates various aspects of application deployment, scaling, and management. It provides tools for managing containers in a distributed environment, ensuring that your applications are highly available and scalable.
You can set up a local Kubernetes environment using tools like Minikube, kind (Kubernetes IN Docker), or by using managed Kubernetes services like Google Kubernetes Engine (GKE), Amazon EKS, or Azure Kubernetes Service (AKS).
Create a YAML file named pod.yaml with the following content:
apiVersion: v1
kind: Pod
metadata:
name: my-pod
spec:
containers:
- name: my-container
image: nginx
kubectl apply -f pod.yaml.
kubectl get pods
to list all pods.kubectl describe pod my-pod
to get detailed information about the pod.kubectl logs my-pod
to view the logs of the container.Create a YAML file named deployment.yaml with the following content:
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-deployment
spec:
replicas: 3
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: my-container
image: nginx
kubectl apply -f deployment.yaml.
kubectl scale deployment my-deployment --replicas=5
.kubectl get deployments
to list deployments.kubectl describe deployment my-deployment
for detailed information.Create a YAML file named service.yaml with the following content:
apiVersion: v1
kind: Service
metadata:
name: my-service
spec:
selector:
app: my-app
ports:
- protocol: TCP
port: 80
targetPort: 80
type: LoadBalancer
kubectl apply -f service.yaml
.kubectl get services
to list services and find the external IP or URL.Create a YAML file named namespace.yaml with the following content:
apiVersion: v1
kind: Namespace
metadata:
name: my-namespace
kubectl apply -f namespace.yaml.
kubectl config set-context --current --namespace=my-namespace
.kubectl get pods -n my-namespace
.By understanding these Kubernetes fundamentals and completing the lab exercises, you’ll gain a solid foundation in managing containerized applications with Kubernetes. Practice these commands and concepts regularly to build your expertise and effectively manage your Kubernetes clusters.