Configure Client commands from command line Configure Client commands from command line kubernetes kubernetes

Configure Client commands from command line


You should use Vagrant to automate those steps.

For instance, IBM/deploy-ibm-cloud-private/Vagrantfile has this section:

install_kubectl = <<SCRIPTecho "Pulling #{image_repo}/kubernetes:v#{k8s_version}..."sudo docker run -e LICENSE=#{license} --net=host -v /usr/local/bin:/data #{image_repo}/kubernetes:v#{k8s_version} cp /kubectl /data &> /dev/nullkubectl config set-credentials icpadmin --username=admin --password=admin &> /dev/nullkubectl config set-cluster icp --server=http://127.0.0.1:8888 --insecure-skip-tls-verify=true &> /dev/nullkubectl config set-context icp --cluster=icp --user=admin  --namespace=default &> /dev/nullkubectl config use-context icp &> /dev/nullSCRIPT

See more at "Kubernetes, IBM Cloud Private, and Vagrant, oh my!", from Tim Pouyer.


@VonC provided useful tips. This is how the service account token can be obtained.

Get the token from a running container - Tip from this link.

RUNNIGCONTAINER=$(docker ps | grep k8s_cloudiam-apikeys_auth | awk '{print $1}')TOKEN=$(docker exec -t $RUNNIGCONTAINER cat /var/run/secrets/kubernetes.io/serviceaccount/token)

I already know the name of the IBM Cloud Private cluster name, master node and the default user name. The only missing link was the token. Please note that the script used by Tim is using password and the only difference was - I wanted to use token instead of the password.

So use the scripts.

kubectl config set-cluster ${CLUSTERNAME}.icp --server=https://$MASTERNODE:8001 --insecure-skip-tls-verify=truekubectl config set-context ${CLUSTERNAME}.icp-context --cluster=${CLUSTERNAME}.icpkubectl config set-credentials admin --token=$TOKENkubectl config set-context ${CLUSTERNAME}.icp-context --user=$DEFAULTUSERNAME --namespace=defaultkubectl config use-context ${CLUSTERNAME}.icp-context


# get tokenicp_auth_token=`curl -s -k -H "Content-Type: application/x-www-form-urlencoded;charset=UTF-8" \    -d "grant_type=password&username=${myuser}&password=${mypass}&scope=openid" \    https://${icp_server}:8443/idprovider/v1/auth/identitytoken --insecure | \    sed 's/{//g;s/}//g;s/\"//g' | \    awk -F ':' '{print $7}'`# setup contextkubectl config set-cluster ${icp_server} --server=https://${icp_server}:8001 --insecure-skip-tls-verify=true kubectl config set-credentials ${icp_server}-user --token=${icp_auth_token}kubectl config set-context ${icp_server}-context --cluster=${icp_server} --user=${icp_server}-user kubectl config use-context ${icp_server}-context