Wednesday, May 16, 2018

Check whether all nodes are in sync(timewise)




To check whether time is in sync (ntp) you can make use of ansible.

First fillup your inventory file with all nodes.

Then,

ansible all -m shell -a "date"

all here will contact all the nodes in inventory and get time.


If it varies widely you have an issue. check whether ntp service like
chronyd/ntpd running in the nodes.



Running out of space in /var directory due to docker images



docker images are stored under /var/lib/docker

If you run out of space in /var partition.?

ok move /var/lib/docker directory to /root (considering space is available under /root) and create a symlink from /var/lib/docker to /root/docker.

Ensure you stop docker service before moving and verify docker daemon works fine after creating symlink.

so, all the commands put together:

systemctl stop docker

mv /var/lib/docker /root/

ln -sf  /root/docker /var/lib/docker

systemctl start docker

systemctl status  docker

thats it :) 

git push only the current branch




# This will make git push to push only the current branch

git config --global push.default simple

Tuesday, May 8, 2018

Delete all evicted pods in openshift


Delete all evicted pods in openshift:

Please check the commands thoroughly before executing it.

# This is for the current namespace
# eval "$(oc get pods -o json | jq -r '.items[] | select(.status.phase == "Failed" and .status.reason == "Evicted") | "oc delete pod --namespace " + .metadata.namespace + " " + .metadata.name')"


# This is for all namespaces
# eval "$(oc get pods -o json --all-namespaces | jq -r '.items[] | select(.status.phase == "Failed" and .status.reason == "Evicted") | "oc delete pod --namespace " + .metadata.namespace + " " + .metadata.name')"


Here,  jq - commandline JSON processor
You need to install jq first.


PS: Thanks to Stackoverflow!

Another PS:
As per the reader's comment :
Another way per-namespace without jq.

# for evicted in $(oc get pods | grep "Evicted" | awk '{print $1}'); do oc delete pod ${evicted}; done



Friday, May 4, 2018

Show only stopped docker containers

# show running containers
docker ps


# show running and stopped containers
docker ps -a


# adding q make it quiter :o)
docker ps -q
docker ps -q -a


# Now show only the stopped container
diff <(docker ps -a -q) <(docker ps -q )
 
   This shows difference between the two commands and
in this case the difference is stopped containers.

 




Thursday, May 3, 2018

delete dangling docker images and remove stopped containers

--------
delete dangling docker images :

docker rmi $(sudo docker images --filter "dangling=true" -q --no-trunc)

--------

Delete stopped containers ( and not running containers):

docker rm $(docker ps -a -q)
--------

Delete untagged docker images :

docker rmi `docker images | grep "^<none>" | awk '{print $3}' ` --force

If no force is used, it throws error "image is being used by stopped container"

---------

# To delete a image remotely, and it has s3-apb as its name:


ssh remotee_server 'docker rmi `docker images | grep s3-apb | awk '"'"'{print $3}'"'"' ` --force'

Having double quote with remote command is tricky. it is getting evaluated as part of local shell itself. to avoid you need use like above.

source: https://stackoverflow.com/questions/20498599/how-to-escape-the-single-quote-character-in-an-ssh-remote-bash-command