Skip to main content

Kubernetes

1. use eksctl or aws console to create a cluster, eksctl is a cli tool for creating clusters on EKS, it is written in Go, and uses CloudFormation.
2. use kubectl to get nodes, pods, services, deployments, etc.
  1. Create Cluster
eksctl create cluster \
--nodegroup-name eks-nodegroup \
--region eu-west-2 \
--name eks-cluster \
--version 1.14 \
--node-type t2.micro \
--nodes 2 \
--nodes-min 1 \
--nodes-max 3 \
--managed
  1. Get Nodes
kubectl get nodes
  1. Get Pods
kubectl get pods
  1. Get Services
kubectl get svc
  1. Get Deployments
kubectl get deployments
  1. write a deployment.yaml file for your application
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
labels:
app: my-app
spec:
replicas: 3
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: my-app
image: my-app:latest
ports:
- containerPort: 8080
  1. Deploy your application
# single file deployment
kubectl apply -f deployment.yaml

# multiple file deployment
kubectl apply -f deployment.yaml -f service.yaml

# deployment from a directory, if you have multiple files in a directory
kubectl apply -f ./k8s
  1. Get all resources
kubectl get all
  1. Get logs
kubectl logs -f <pod-name>
  1. Get shell access
kubectl exec -it <pod-name> -- /bin/bash
  1. Delete Cluster
eksctl delete cluster --name eks-cluster
  1. Delete all resources
kubectl delete all --all
  1. Delete all resources from a directory
kubectl delete -f ./k8s
  1. Delete all resources from a file
kubectl delete -f deployment.yaml