DevOps Blog - Commands for Docker & Kubernetes

in #kubernetes6 years ago (edited)

Today I will share some commands I've added to my .bashrc that have been useful for practicing docker and k8s (on local system, not production).

Most of these aren't very useful because you only really need to clear out a full system when you've been experimenting with the technology for the first time.

The first simply removes all Docker containers:

# command to remove all containers but not images
rmcontainers() {
  docker kill $(docker ps -q)
  docker rm $(docker ps -a -q)
}

The second I only really made because I downloaded too many images on a device without much memory. It removes all containers, images, and volumes on Docker:

 # command to remove all containers and images, with y/N prompt
rmdocker() {
read -r -p "Are you sure you want to remove all docker data? [y/N] " response
  case "$response" in
      [yY][eE][sS]|[yY])
          docker kill $(docker ps -q)
          docker rm $(docker ps -a -q)
          docker rmi $(docker images -q)
          docker volume rm $(docker volume ls -q)
          docker network rm $(docker network ls -q)
          ;;
      *)
  esac
}

I never use the command above anymore as I'm on a machine with more storage but I wanted something similar for k8s. Reason being I do so many experiments and tests that leave a bunch k8s objects I don't want. This seems to get me back to the state my system started in:

# command to remove all deployments, services, and pods, with y/N prompt
cleankube() {
  read -r -p "Are you sure you want to delete all deployments, services, and pods? [y/N] " response
  case "$response" in
      [yY][eE][sS]|[yY])
          kubectl delete deployment --all
          kubectl delete pods --all
          kubectl delete services --all
          ;;
      *)
  esac
}

Most of these won't be very useful in day to day work once the system is actually up and running.

I'd love to hear what other people are doing. What commands have you added to your .bashrc and found useful?

Also I'm currently trying to get a persistent volume setup with a mongodb replica set on k8s. If you think you can help check out my question on StackoverFlow!

Thanks for reading.

cowsay.png

Sort:  

Thanks for sharing your tips on Kubernetes and Docker.

Are you working with Minishift as well?

I'm looking at it now, not familiar with openshift. Is it just something to help you simulate a cluster locally?

As I understand it, yes, but I have no experience with it. But will learn it in the next weeks.

Do you have some good tutorials on the topic that you could share?

DigitalOcean has some helpful​ tutorials. Hope these will help you on your way to mastery :)

Thanks I'll have a look!

Needed to free up some space on my Mac. This certainly helped!

I Upvoted And Followed you. do The same for me and we could help each other Earn.

Coin Marketplace

STEEM 0.17
TRX 0.15
JST 0.028
BTC 62227.11
ETH 2400.78
USDT 1.00
SBD 2.50