|
| 1 | +# Kubeconfig |
| 2 | + |
| 3 | +Kubernetes uses a configuration file, typically referred to as **kubeconfig**, |
| 4 | +to manage cluster access details and user credentials. It is created when you create a new cluster or |
| 5 | +when you create a new user for an existing cluster. |
| 6 | + |
| 7 | +## Purpose of the Kubeconfig |
| 8 | + |
| 9 | +This file enables the `kubectl` command-line tool to interact with the |
| 10 | +Kubernetes cluster, allowing users to perform various operations such as deploying applications, inspecting cluster |
| 11 | +resources, and managing cluster configurations. |
| 12 | + |
| 13 | +Like `kubectl`, Icinga for Kubernetes requires a kubeconfig file to access the Kubernetes API. |
| 14 | + |
| 15 | +## Managing Kubeconfig |
| 16 | + |
| 17 | +### Location of Kubeconfig File |
| 18 | + |
| 19 | +By default, the kubeconfig file is located at `~/.kube/config` on most systems. |
| 20 | + |
| 21 | + |
| 22 | +#### Changing the Location |
| 23 | +You can specify a different location for the kubeconfig file by setting the KUBECONFIG environment variable. |
| 24 | +This allows you to use a configuration file stored in another location. |
| 25 | + |
| 26 | + |
| 27 | +```shell |
| 28 | +export KUBECONFIG=/path/to/your/kubeconfig |
| 29 | +```` |
| 30 | + |
| 31 | +### Structure of the Kubeconfig File |
| 32 | + |
| 33 | +A typical kubeconfig file is a YAML file with the following main sections: |
| 34 | + |
| 35 | +- **apiVersion:** Specifies the version of the Kubernetes API. |
| 36 | +- **kind:** Defines the type of Kubernetes resource being described. |
| 37 | +- **clusters:** Defines the clusters that kubectl can connect to. |
| 38 | +- **users:** Contains the authentication information for different users. |
| 39 | +- **contexts:** Represents a combination of a cluster, a user, and a namespace. |
| 40 | +- **current-context:** Indicates the default context that kubectl uses for commands. |
| 41 | + |
| 42 | + |
| 43 | +#### Example kubeconfig file |
| 44 | + |
| 45 | +The following example of a kubeconfig file illustrates the values that must be replaced by user-specific values. |
| 46 | + |
| 47 | +```yml |
| 48 | +apiVersion: v1 |
| 49 | +kind: Config |
| 50 | +clusters: |
| 51 | + - cluster: |
| 52 | + server: https://your-cluster-api-server:8443 |
| 53 | + certificate-authority: /path/to/ca.crt |
| 54 | + name: your-cluster |
| 55 | +users: |
| 56 | + - name: your-user |
| 57 | + user: |
| 58 | + client-certificate: /path/to/client.crt |
| 59 | + client-key: /path/to/client.key |
| 60 | +contexts: |
| 61 | + - context: |
| 62 | + cluster: your-cluster |
| 63 | + user: your-user |
| 64 | + namespace: default |
| 65 | + name: your-context |
| 66 | +current-context: your-context |
| 67 | +``` |
| 68 | + |
| 69 | +For a more detailed explanation of the kubeconfig file, see the [official Kubernetes documentation](https://kubernetes.io/docs/concepts/configuration/organize-cluster-access-kubeconfig/). |
0 commit comments