Kubernetes Practical Hands-on
Kubernetes Installation
To get started with Kubernetes, you'll need to set up a Kubernetes cluster. You can do this by installing a Kubernetes distribution like minikube or kind on your local machine, or by using a managed Kubernetes service like Google Kubernetes Engine (GKE) or Amazon Elastic Kubernetes Service (EKS).
Here's an example of how to install minikube on Ubuntu 22.04:
curl -LO
sudo install minikube-linux-amd64 /usr/local/bin/minikube
minikube start
Kubernetes Pod Creation
Once you have a Kubernetes cluster set up, you can start deploying applications. The basic unit of deployment in Kubernetes is a Pod, which represents one or more containers that share the same network and storage resources.
Here's an example of creating a simple nginx pod:
apiVersion: v1
kind: Pod
metadata:
name: nginx-pod
spec:
containers:
- name: nginx
image: nginx:latest
ports:
- containerPort: 80
Save this as nginx-pod.yaml
and apply it to your cluster:
kubectl apply -f nginx-pod.yaml
Kubernetes Configuration
Kubernetes provides several ways to configure your applications, including:
- ConfigMaps: For storing non-sensitive configuration data.
- Secrets: For storing sensitive information like passwords or API keys.
- Volumes: For providing persistent storage to your applications.
Here's an example of creating a ConfigMap and using it in a Pod:
apiVersion: v1
kind: ConfigMap
metadata:
name: app-config
data:
APP_ENV: production
APP_LOG_LEVEL: info
---
apiVersion: v1
kind: Pod
metadata:
name: app-pod
spec:
containers:
- name: app
image: myapp:v1
envFrom:
- configMapRef:
name: app-config
Kubernetes Troubleshooting
When things go wrong, Kubernetes provides several tools and commands for troubleshooting:
- Kubectl: Use
kubectl get
, kubectl describe
, and kubectl logs
to inspect the state of your cluster and deployed resources.
- Kubernetes Dashboard: The web-based UI can provide a visual overview of your cluster and help you identify issues.
- Kubernetes Events: Monitor the events generated by the Kubernetes control plane to identify errors or warnings.
By following these practical hands-on steps, you'll be well on your way to becoming a Kubernetes expert!