Docker and Kubernetes

Last updated 2 days ago

some docker and k8s commands I don't wanna search over internet

Docker ecosystem

docker-basics.sh
logger.sh
# access bash inside a running container
sudo docker exec -it container-name bash
# remove all stopped containers
docker rm -v $(docker ps -a -q -f status=exited)
# stop and remove all docker containers
docker stop $(docker ps -a -q) && docker rm $(docker ps -a -q)
# remove all docker images
docker rmi $(docker images -a -q)
# prune docker system
docker system prune
# one liner for docker cleanup
docker stop $(docker ps -a -q) && \
docker rm $(docker ps -a -q) && \
docker rmi $(docker images -a -q) && \
docker system prune

Kubernetes

deployments-using-kubectl.sh
# all commands: https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands
# get credentials for your gcp cluster
gcloud container clusters get-credentials dev-cluster --zone=us-central1-f
# create a deployment on your cluster
kubectl run website-deployment --image=gcr.io/ivikramtiwari/website
# check if deployment was successful
kubectl get deployments
# get pods
kubectl get pods
# scale deployments
kubectl scale deployment website-deployment --replicas=4