Skip to content

Instantly share code, notes, and snippets.

@PieterScheffers PieterScheffers/.bashrc
Last active Apr 23, 2019

What would you like to do?
Download new kubeconfig when it is older as 6 days for DigitalOcean kubernetes
#!/usr/bin/env bash
# DigitalOcean Kubernetes
# The kubeconfig you download from DigitalOcean invalidates every 7 days
# By appending this to your .bashrc file the kubeconfig gets refreshed every 6 days
# Pre
# - install 'doctl':
# - auth with DigitalOcean API token:
# When using custom contexts, put these in an other kubeconfig file,
# and add both to the KUBECONFIG environment variable
# export KUBECONFIG=/home/myuser/.kube/digitalocean-auth.yml:/home/myuser/.kube/digitalocean.yml
file_time=$(stat --format='%Y' "$filename")
current_time=$(date +%s)
let days=60*60*24*6
if (( file_time < ( current_time - ( days ) ) )); then
echo "DigitalOcean Kubeconfig is older as 6 days. Updating..."
doctl kubernetes cluster kubeconfig show $mycluster > $filename
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.