Skip to content

Instantly share code, notes, and snippets.

@lpsm-dev
Last active April 25, 2020 03:08
Show Gist options
  • Save lpsm-dev/6d8d59b63d7443b19c7ff866f578d544 to your computer and use it in GitHub Desktop.
Save lpsm-dev/6d8d59b63d7443b19c7ff866f578d544 to your computer and use it in GitHub Desktop.
🔧 Multiple Kubeconfigs Manager
@lpsm-dev
Copy link
Author

Manager Kubeconfigs

This is a setup used to configure access to Multiple Clusters in your system. In this process we have a simple script that configure some alias commands

Setup

# ALIAS - KUBECTL COMMANDS
alias info="kubectl cluster-info"
alias view="kubectl config view"
alias contexts="kubectl config get-contexts"
alias context="kubectl config current-context"
alias ns="kubectl get ns"
alias services="kubectl get services"
alias nodes="kubectl get nodes"
alias pods="kubectl get pods --all-namespaces"

# ALIAS - KUBECTL CONTEXTS
alias aws-prod="kubectl config use-context aws-eks-cluster-prd"
alias aws-stage="kubectl config use-context eks-devops-stage-001"
alias aws-sandbox="kubectl config use-context eks-devops-sandbox-001"
alias aws-develop="kubectl config use-context eks-devops-develop-001"
alias aws-labs="kubectl config use-context eks-devops-labs-001"
alias do-prod="kubectl config use-context do-k8s-cluster-prod-001"
alias do-stage="kubectl config use-context do-k8s-cluster-staging-001"
alias cnb-prod="kubectl config use-context eks-cnb-production-001"
alias gc-develop="kubectl config use-context gke-devpos-develop-001"

# KUBECONFIG AWS
export CONFIG_AWS_PROD=$HOME/.kube/config-aws-prod
export CONFIG_AWS_STAGE=$HOME/.kube/config-aws-stage
export CONFIG_AWS_SANDBOX=$HOME/.kube/config-aws-sandbox
export CONFIG_AWS_DEVELOP=$HOME/.kube/config-aws-develop
export CONFIG_AWS_LABS=$HOME/.kube/config-aws-labs

# KUBECONFIG DO
export CONFIG_DO_PROD=$HOME/.kube/config-do-prod
export CONFIG_DO_STAGE=$HOME/.kube/config-do-stage

# KUBECONFIG CNB
export CONFIG_CNB_PROD=$HOME/.kube/config-cnb-prod

# KUBECONFIG GC
export CONFIG_GC_DEVELOP=$HOME/.kube/config-gc-develop

# EXPORT KUBECONFIG VARIABLE
export KUBECONFIG=$CONFIG_AWS_PROD:$CONFIG_AWS_STAGE:$CONFIG_AWS_SANDBOX:$CONFIG_AWS_DEVELOP:$CONFIG_AWS_LABS:$CONFIG_DO_PROD:$CONFIG_DO_STAGE:$CONFIG_CNB_PROD:$CONFIG_GC_DEVELOP

You need put this into .bashrc and run the source command.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment