0

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.

DeejonZ
  • 2,451
  • 2
  • 17
  • 19
  • 1
    There are multiple ways, **1st** `export KUBECONFIG=/path/to/yaml`, **2nd**, place the yaml in the default directory, Eg, `~/.kube/config`, **3rd**, use `--kubeconfig /path/to/yaml` flag while using `kubectl` commands – P.... Feb 15 '23 at 14:12
  • I tried --kubeconfig it says : `error: error loading config file "/var/cred-deployer.yaml": yaml: line 5: mapping values are not allowed in this context` – DeejonZ Feb 15 '23 at 14:15
  • the content of `/var/cred-deployer.yaml` is same as the one provided in the question? – P.... Feb 15 '23 at 14:24
  • ok I solved, the indentation was wrong. Thanks a lot for your help. – DeejonZ Feb 16 '23 at 08:55
  • @DeejonZ Since your issue is resolved can you post the procedure you've followed as Solution and accept it for better community reach – Mayur Kamble Feb 16 '23 at 11:45
  • Please add your answer as a solution and I will accept it – DeejonZ Feb 16 '23 at 12:53

1 Answers1

2

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

Mayur Kamble
  • 180
  • 4