Renewing cluster kubeconfig from the command line

  • 29 April 2020
  • 7 replies
  • 951 views

Userlevel 1

Just wanted to share how we are renewing the kubeconfig from the command line.

Background:
In our organization it was considered a bit clumsy to download the kubeconfig from the Karbon UI. We love the command line and wanted a quick’n’easy way to renew the authentication token.

The solution:
We created a docker image that contains the “karbonctl” binary and a wrapper script. The Dockerfile was also included into our CI/CD pipeline to automate the image creation.

The wrapper script does two things:

  • karbonctl login --pc-ip prism.nightingale.nu --pc-username “$1”
  • karbonctl cluster kubeconfig --cluster-name “$2” >”$3”

The commands that the end user run:

  • docker run --rm -it -v “$(pwd)”:/tmp docker.registry.local/karbonctl:latest <login> mycluster /tmp/karbon.cfg
  • export KUBECONFIG=”$(pwd)/karbon.cfg”

 


7 replies

Userlevel 3
Badge +1

Hey,

Thanks for sharing. Any chance you have the Dockerfile or Docker image available to share with the community?

 

Userlevel 7
Badge +35

Thanks for sharing @clindevall - good stuff!

BTW - love the avatar!

Userlevel 1

Hello,

Here’s the current Dockerfile:

FROM centos:7

COPY karbonctl /usr/local/bin

COPY kubeconfig /usr/local/bin

ENTRYPOINT ["/usr/local/bin/kubeconfig"]

The “kubeconfig” shell script looks like this:

#!/bin/sh

if [ $# -lt 2 ]

then

echo "Usage: kubeconfig <Office 365 login> <Karbon cluster name>"

exit 1

fi

karbonctl login --pc-ip prism-central.host.local --pc-username "$1"

if [ ! -z "$3" ]

then

karbonctl cluster kubeconfig --cluster-name "$2" >"$3"

else

karbonctl cluster kubeconfig --cluster-name "$2"

fi
 

Userlevel 1

There’s room for improvement, but for now we use the docker image like this:

docker run --rm -it -v "$(pwd)":/tmp docker.registry.local/karbon:latest john.doe@office365.com mycluster /tmp/mycluster.cfg

Where does one get the karbonctl binary from?

Userlevel 3
Badge +1

It is in Prism Central. Login via SSH with nutanix user and look in /home/nutanix/karbon

It is in Prism Central. Login via SSH with nutanix user and look in /home/nutanix/karbon

Is it possible to download this somewhere else? I’m trying to setup another VM or find a scalable way to renew contexts as sharing the admin credentials isn’t ideal

Reply