Skip to content

Instantly share code, notes, and snippets.

@amalkh5
Last active January 17, 2020 10:06
Show Gist options
  • Select an option

  • Save amalkh5/370f6595a1cb96e5a46eb2d10733b713 to your computer and use it in GitHub Desktop.

Select an option

Save amalkh5/370f6595a1cb96e5a46eb2d10733b713 to your computer and use it in GitHub Desktop.
k8s cheat sheet

Cluster configuration

      $ kubectl config set-cluster "$CLUSTER_NAME" --server="$SERVER_IP" --certificate-authority="$KUBE_CA_PEM"  --embed-certs=true
      $ kubectl config set-credentials "$KUBE_USER" --client-certificate="$CLIENT_CERT"  --client-key="$CLIENT_KEY"  --embed-certs=true
      $ kubectl config set-context "$KUBE_CONTEXT" --cluster="$CLUSTER_NAME" --user="$KUBE_USER" --namespace="$KUBE_NAMESPACE"
      $ kubectl config use-context "$KUBE_CONTEXT"

Set the KUBECONFIG environment variable

$ export KUBECONFIG_SAVED=$KUBECONFIG

Create User With Limited Namespace Access

$ kubectl create namespace name
$ openssl genrsa -out key.key 2048
$ openssl req -new -key key.key -out key.csr -subj "/CN=key/O=centos"
$ openssl x509 -req -in key.csr -CA /etc/kubernetes/pki/ca.crt -CAkey /etc/kubernetes/pki/ca.key -CAcreateserial -out key.crt -days 500
$ kubectl config set-credentials key --client-certificate=/key.crt  --client-key=/key.key
$ kubectl config set-context key-context  --cluster=prd --namespace=nsme --user=key
$ kubectl --context=key-context get pods
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment