Skip to content

Instantly share code, notes, and snippets.

@bakavets
Last active January 17, 2021 09:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bakavets/f2c508d7b7561c2ae80b2c17a59e0574 to your computer and use it in GitHub Desktop.
Save bakavets/f2c508d7b7561c2ae80b2c17a59e0574 to your computer and use it in GitHub Desktop.

Kubernetes-lesson-4 content:

Create minikube cluster k8s-cluster-1

minikube start --profile k8s-cluster-1

Create minikube cluster k8s-cluster-2

minikube start --profile k8s-cluster-2

Use the AWS CLI update-kubeconfig command to create or update your kubeconfig for your cluster

aws eks --region <region-code> update-kubeconfig --name <cluster_name>

By default, kubectl looks for a file named config in the $HOME/.kube directory. You can specify other kubeconfig files by setting the KUBECONFIG environment variable or by setting the --kubeconfig flag.

export KUBECONFIG=/home/anton/.kube/config_1:/home/anton/.kube/config_2
Modify kubeconfig files using subcommands like "kubectl config set current-context my-context"

The loading order follows these rules:

  • If the --kubeconfig flag is set, then only that file is loaded. The flag may only be set once and no merging takes place.
  • If $KUBECONFIG environment variable is set, then it is used as a list of paths (normal path delimiting rules for your system). These paths are merged. When a value is modified, it is modified in the file that defines the stanza. When a value is created, it is created in the first file that exists. If no files in the chain exist, then it creates the last file in the list.
  • Otherwise, ${HOME}/.kube/config is used and no merging takes place.

Usage kubectl config SUBCOMMAND

kubectl config current-context - Display the current-context

kubectl config delete-cluster minikube - Delete the minikube cluster

kubectl config delete-context minikube - Delete the context for the minikube cluster

kubectl config delete-user minikube - Delete the minikube user

kubectl config get-clusters - List the clusters kubectl knows about

kubectl config get-contexts - List all the contexts in your kubeconfig file

kubectl config get-contexts my-context - Describe one context in your kubeconfig file.

kubectl config get-users - List the users kubectl knows about

kubectl config rename-context old-name new-name - Rename the context 'old-name' to 'new-name' in your kubeconfig file

kubectl config set clusters.my-cluster.server https://1.2.3.4 - Set server field on the my-cluster cluster to "https://1.2.3.4"

kubectl config set clusters.my-cluster.certificate-authority-data $(echo "cert_data_here" | base64 -i -) - Set certificate-authority-data field on the my-cluster cluster.

kubectl config set contexts.my-context.cluster my-cluster - Set cluster field in the my-context context to my-cluster.

kubectl config set users.cluster-admin.client-key-data cert_data_here --set-raw-bytes=true - Set client-key-data field in the cluster-admin user using --set-raw-bytes option.

kubectl config set-cluster e2e --server=https://1.2.3.4 - Set only the server field on the e2e cluster entry without touching other values.

kubectl config set-cluster e2e --embed-certs --certificate-authority=~/.kube/e2e/kubernetes.ca.crt - Embed certificate authority data for the e2e cluster entry

kubectl config set-cluster e2e --insecure-skip-tls-verify=true - Disable cert checking for the dev cluster entry

kubectl config set-cluster e2e --tls-server-name=my-cluster-name - Set custom TLS server name to use for validation for the e2e cluster entry

kubectl config set-context gce --user=cluster-admin - Set the user field on the gce context entry without touching other values

kubectl config set-credentials cluster-admin --client-key=~/.kube/admin.key - Set only the "client-key" field on the "cluster-admin" # entry, without touching other values

kubectl config set-credentials cluster-admin --username=admin --password=uXFGweU9l35qcif - Set basic auth for the "cluster-admin" entry

kubectl config set-credentials cluster-admin --client-certificate=~/.kube/admin.crt --embed-certs=true - Embed client certificate data in the "cluster-admin" entry

kubectl config set-credentials cluster-admin --auth-provider=gcp - Enable the Google Compute Platform auth provider for the "cluster-admin" entry

kubectl config set-credentials cluster-admin --auth-provider=oidc --auth-provider-arg=client-id=foo --auth-provider-arg=client-secret=bar - Enable the OpenID Connect auth provider for the "cluster-admin" entry with additional args

kubectl config set-credentials cluster-admin --auth-provider=oidc --auth-provider-arg=client-secret- - Remove the "client-secret" config value for the OpenID Connect auth provider for the "cluster-admin" entry

kubectl config set-credentials cluster-admin --exec-command=/path/to/the/executable --exec-api-version=client.authentication.k8s.io/v1beta1 - Enable new exec auth plugin for the "cluster-admin" entry

kubectl config set-credentials cluster-admin --exec-arg=arg1 --exec-arg=arg2 - Define new exec auth plugin args for the "cluster-admin" entry

kubectl config set-credentials cluster-admin --exec-env=key1=val1 --exec-env=key2=val2 - Create or update exec auth plugin environment variables for the "cluster-admin" entry

kubectl config set-credentials cluster-admin --exec-env=var-to-remove- - Remove exec auth plugin environment variables for the "cluster-admin" entry

kubectl config unset current-context - Unset the current-context.

kubectl config unset contexts.foo.namespace - Unset namespace in foo context.

kubectl config use-context minikube - Use the context for the minikube cluster

kubectl config view - Show merged kubeconfig settings.

kubectl config view --raw - Show merged kubeconfig settings and raw certificate data.

kubectl config view -o jsonpath='{.users[?(@.name == "e2e")].user.password}' - Get the password for the e2e user

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment