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.
- 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
- Get Nodes
kubectl get nodes
- Get Pods
kubectl get pods
- Get Services
kubectl get svc
- Get Deployments
kubectl get deployments
- 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
- 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
- Get all resources
kubectl get all
- Get logs
kubectl logs -f <pod-name>
- Get shell access
kubectl exec -it <pod-name> -- /bin/bash
- Delete Cluster
eksctl delete cluster --name eks-cluster
- Delete all resources
kubectl delete all --all
- Delete all resources from a directory
kubectl delete -f ./k8s
- Delete all resources from a file
kubectl delete -f deployment.yaml