Skip to content

Instantly share code, notes, and snippets.

@mose
Last active January 19, 2018 14:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mose/dc0b24c95e46b219e963494e66f9609d to your computer and use it in GitHub Desktop.
Save mose/dc0b24c95e46b219e963494e66f9609d to your computer and use it in GitHub Desktop.
kubesandbox remote access

As I was testing around with https://bitnami.com/stack/kubernetes-sandbox I wanted to remotely access it

First find the token, by getting on the server, which is configured to trust any local user to be cluster admin with kubectl

TOKEN=$(kubectl get secrets -n kube-system | grep default-token | awk '{print $2}')
kubectl describe secret $TOKEN -n kube-system | grep token:

Now give that default user the cluster admin role

kubectl create clusterrolebinding admin-role --clusterrole=cluster-admin --serviceaccount=kube-system:default

Then create a local ~/.kube/config-sandbox

apiVersion: v1
clusters:
- cluster:
    insecure-skip-tls-verify: true
    server: https://<ip>:6443
  name: default
contexts:
- context:
    cluster: default
    namespace: default
    user: default
  name: default
current-context: default
kind: Config
preferences: {}
users:
- name: default
  user:
    token: <xxx>

where

  • <ip> is the ip of the server
  • <xxx> is the default-token-xxxx in the secrets

Now I can, locally

export KUBECONFIG=$KUBECONFIG:$HOME/.kube/config-sandbox
kubectl get pods --all-namespaces
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment