Kubectl config
You’ve come to the right place to start using kubectl! This tool will help you interact with your apps running in Kubernetes.
Kubernetes provides a command line tool for communicating with a Kubernetes cluster’s control plane, using the Kubernetes API. This tool is named kubectl.
Kubectl Setup
There are some differences depending on the cloud provider, but both of them follow these steps initially:
- Copy the config from this link: config to
~/.kube/config. - Install
kubectlitself. To do this with brew, usebrew install kubectl, or you can visit the kubectl download page.
Azure
‘kubectl’ access requires membership in the Azure security group for Azure Banno Development
Once you have that, follow these directions to get kubectl working:
- Install kubelogin. To install kubelogin with brew, use
brew install Azure/kubelogin/kubelogin. - Use the
kubelogin convert-kubeconfigcommand to seed your auth. After that, you can runkubectlcommands.- When using a new configuration for k8s, a prompt will appear upon
kubectlcommands showing a code to enter and a login page where@jhacorp.comcredentials (and passcode) will need to be provided. This populates an entry for the declared environment into theaccess-token:line item entry inside~/.kube/config. - You can then use any
kubectlcommand to create access tokens for each environment:- Production:
production-centralus-aks - UAT:
uat-centralus-aks - Staging:
staging-centralus-aks - tools:
tools-centralus-aks - example command: ‘
kubectl --context $ENVIRONMENT-centralus-aks get namespaces’
- Production:
- When using a new configuration for k8s, a prompt will appear upon
(See the k8s auth docs for further details.)
GCP
‘kubectl’ access uses the gcloud cli tool and a plugin to authenticate to GCP.
- Install the gcloud cli tool. Follow the steps to initialize the configuration.
- Install the plugin that
kubectluses viagcloud components install gke-gcloud-auth-plugin.
Contexts
Contexts are available for each region in each environment:
- Development:
gke_dev-digital-banno_us-central1_gkeandgke_dev-digital-banno_us-east4_gke
Example commands
- Edit an service’s config (environment variables, app version, number of replicas, etc)
- tl;dr: use
kubectl --context ENVIRONMENT_CONTEXT -n TEAM_NAMESPACE edit app APP_NAME. Example:kubectl --context gke_dev-digital-banno_us-central1_gke -n mirai edit app go-ach-for-cus. - Developers have access to make modifications on both Development/Staging, but not Production. This is useful when testing changes to your app and you don’t want to wait on the environments pipeline.
- These changes are not persisted. To make any changes permanent they need to be added to the service’s config in the Environments repository.
- tl;dr: use
- Here are some useful functions to put in your terminal’s
.bashrcor.zshrcfile. You can change the defaults to your favorite namespace (e.g.discoverybelow) and environment (e.g.uatbelow).
# call with service name and optionally namespace and env to forward localhost:8080 to your service
# e.g. kforward my-service my-namespace uat
# $1 = service name
# $2 = namespace; discovery is the default on "" or null
# $3 = env; uat is the default on ""
function kforward() { kubectl --context ${3:uat}-centralus-aks -n ${2:-discovery} port-forward service/$1 8080:http }
# call with env and service name; this is permanent until the next deployment, while scale is only temporary
# $1 = service name
# $2 = namespace; discovery is the default on "" or null
# $3 = env; uat is the default on ""
function kedit() { kubectl --context ${3:uat}-centralus-aks -n ${2:-discovery} edit app $1 }