Workshops
Kubernetes Basics Workshop
Learn the basics of Kubernetes and how to deploy applications on a Kubernetes cluster
Benefits of containers
- Portable
- Cloud deployable
- Scalable (Scale-in and Scale-out)
- Declarative format
- Good for microservices
Challenge: Managing many containers in several servers
What is Kubernetes?
- Container orchestration system
- Deploying
- Scaling
- Networking
- Storage
- Security
- Monitoring
- Logging
- Automatic cluster resource management
kubectl
- CLI tool for Kubernetes
~/.kube/conifg
file stores cluster address and credentials- Kubernetes context: Cluster, namespace, user
Imperative vs. Declarative
- Imperative: Directly instruct Kubernetes to perform actions.
- Declarative: Define desired state in a config file; Kubernetes ensures current state matches it.
Imperative Example
# Imperative command to create a pod
kubectl run my-pod --image=nginx
Declarative Example
To create a pod declaratively, you define the pod in a YAML file and then apply it:
pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: my-pod
spec:
containers:
- name: nginx
image: nginx
Apply the configuration using kubectl apply
:
# Declarative command to create a pod
kubectl apply -f pod.yaml
Core Kubernetes Components
- Kubernetes API Server: Manages and validates requests.
- ETCD: Stores all cluster data.
- Controller Manager: Handles control loops.
- Scheduler: Assigns pods to nodes.
- Kubelet: Runs on nodes to manage pods.
- Kube Proxy: Handles network routing.
Helm
- Kubernetes package manager
- ArtifactHub.io: A public helm chart repository.
- Install/uninstall/upgrade helm charts
Kubernetes Certification
- CKAD (Certified Kubernetes Application Developer)
- CKA (Certified Kubernetes Administrator)
- CKS (Certified Kubernetes Security Specialist)
- KCNA (Kubernetes and Cloud Native Associate)
- KCSA (Kubernetes and Cloud Native Security Associate)
- Kubestronut (When you get all certifications)
Pod
- Smallest unit in Kubernetes
- Includes one or more containers
- Containers share network and storage
- Containers in a pod are scheduled on the same node
Pod Example
Declarative
apiVersion: v1
kind: Pod
metadata:
name: my-pod
spec:
containers:
- name: nginx
image: nginx
Imperative
# Imperative command to create a pod
kubectl run my-pod --image=nginx
Deployment
- Manages pods
- Ensures desired state
- Can scale pods
Deployment Example
Declarative
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-deployment
spec:
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx
Imperative
# Imperative command to create a deployment
kubectl create deployment my-deployment --image=nginx
Service
- Exposes pods to the network
- Load balances traffic
- Types: ClusterIP, NodePort, LoadBalancer, ExternalName
Service Example
Declarative
apiVersion: v1
kind: Service
metadata:
name: my-service
spec:
selector:
app: nginx
ports:
- protocol: TCP
port: 80
targetPort: 80
type: ClusterIP
Imperative
# Imperative command to create a service
kubectl expose deployment my-deployment --type=ClusterIP --port=80 --target-port=80
ConfigMap
- Stores configuration data
- Decouples configuration from pods
- Can be updated without restarting pods
ConfigMap Example
Declarative
apiVersion: v1
kind: ConfigMap
metadata:
name: my-config
data:
key: value
Imperative
# Imperative command to create a configmap
kubectl create configmap my-config --from-literal=key=value
Secret
- Stores sensitive data
- Encoded in base64
- Decouples secrets from pods
Secret Example
Declarative
apiVersion: v1
kind: Secret
metadata:
name: my-secret
type: Opaque
data:
username: dXNlcm5hbWU=
password: cGFzc3dvcmQ=
Imperative
# Imperative command to create a secret
kubectl create secret generic my-secret --from-literal=username=admin --from-literal=password=secretpass
Workload kinds in Kubernetes
- Pod
- Deployment
- StatefulSet
- DaemonSet
- Job
- CronJob
Namespace
- Logical partition of a cluster
- Used to divide resources
- Unique names within a namespace
kuberise.io
- An open-source Internal Developer Platform for Kubernetes
- GitOps-based deployment with ArgoCD
- DRY (Don't Repeat Yourself) approach
- Same templates for all environments
- Different values for each environment
- ArgoCD app of apps pattern
- Enable or disable platform tools
- Add your developer applications
- Single templates folder
- Values folder for each platform
Terminal
./scripts/install.sh minikube onprem https://github.com/kuberise/kuberise.io.git main onprem.kuberise.dev
Kuberise dashboards
- ArgoCD
- Grafana
- Keycloak (Single Sign-On)
- Sample Developer Applications
k9s
- k9s is a Terminal-based UI for Kubernetes
- namespaces
- pods
- deployments
- services
- secrets
- configmaps
- ingress