Search code examples
authenticationkuberneteskubectlkubeconfig

kubectl use config for authentication


I'm creating a pipeline to deploy some application in kubernetes.

I've been given the authentication credentials as a yaml file similar to the following:

apiVersion: v1
clusters:
- cluster:
    certificate-authority-data: LS0tL******0tLS0t
    server: https://api.whatever.com
  name: gs-name-clientcert
contexts:
- context:
    cluster: gs-name-clientcert
    user: gs-name-clientcert-user
  name: gs-name-clientcert
current-context: gs-name-clientcert
kind: Config
preferences: {}
users:
- name: gs-name-clientcert-user
  user:
    client-certificate-data: LS************RS0tLS0t
    client-key-data: LS0tL***********tLQ==

How can I tell kubectl to use that config file when I use the apply command? Thanks.


Solution

  • kubeconfig file path:

    The config modifies kubeconfig files using subcommands like “kubectl config set current-context my-context” The loading order follows these rules:

    1. If the –kubeconfig flag is set, then only that file is loaded. The flag may only be set once and no merging takes place.

    2. If the $KUBECONFIG environment variable is set, then it uses a list of paths (normal path delimiting rules for your system). These paths are merged together. 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, it creates the last file in the list.

    3. Otherwise, ${HOME}/.kube/config is used and no merging takes place.

      kubectl config SUBCOMMAND

      Options

      --kubeconfig="": use a particular kubeconfig file

    For more information refer to the command kubectl config and also follow the path config file.

    Also check the indentation of your config file:

    • If you are using TAB for indentation or any other purpose. Only use SPACE characters.

    • To find indentation errors use monospaced fonts to view and edit YAML.

    For more information about indentation refer to Indentation to YAML