# Configuration

import { Aside, Tabs, TabItem } from '@astrojs/starlight/components';

The `kubetail` CLI tool can be configured using a local config file. If a config file is not found, Kubetail will use the defaults shown below. The file supports YAML, JSON, and TOML formats and values can reference environment variables using `${VARIABLE_NAME}` syntax.

---

## Initialization

The default config file path is `~/.kubetail/config.yaml`. You can initialize the config by placing a file in the default location or by using the CLI `config init` command to do it for you:

```sh
kubetail config init
```

<Aside type="tip">
The `config init` command accepts a `--format` flag to choose a different initialization format. See [CLI reference](/reference/cli#kubetail-config-init) for more details.
</Aside>

---

## Usage

Everytime you run a `kubetail` command, it will automatically look for a config file in the default location. You can specify a different path with the global `--config` flag:

```sh
kubetail serve --config /path/to/config.yaml
```

<Aside type="tip">
The order of precedence for settings is:

1. Defaults
2. Config file
3. CLI flags
</Aside>

---

## Defaults

<Tabs>
  <TabItem label="YAML">
```yaml
## Kubetail CLI Configuration File
# 
# This file defines the behavior for the kubetail CLI tool,  
# including logs command defaults and dashboard server settings.
#

## version ##
#
# Schema version for the configuration file
#
version: 1

## general ##
#
general:

  ## kubeconfig ##
  #
  # Path to the kubeconfig file to use for CLI requests.
  # If empty, the default path (~/.kube/config) or KUBECONFIG env var is used.
  #
  # Default value: ""
  #
  kubeconfig: ""

## commands ##
#
commands:

  ## logs ##
  #
  # Settings specific to the 'logs' subcommand
  #
  logs:

    ## kube-context ##
    #
    # The specific Kubernetes context to use. 
    # If empty, the current active context is used.
    #
    # Default value: ""
    #
    kube-context: ""

    ## head ##
    #
    # The number of lines to show from the beginning of the log buffer
    #
    # Default value: 10
    #
    head: 10

    ## tail ##
    #
    # The number of lines to show from the end of the log buffer
    #
    # Default value: 10
    #
    tail: 10

    ## columns ##
    #
    # Full set of output columns for 'logs' records.
    # Allowed values: timestamp,dot,node,region,zone,os,arch,namespace,pod,container
    #
    # Default value: ["timestamp", "dot"]
    #
    columns:
      - timestamp
      - dot

  ## serve ##
  #
  # Settings for the dashboard server
  #
  serve:

    ## host ##
    #
    # The network interface the server should bind to.
    #
    # Default value: localhost
    #
    host: localhost

    ## port ##
    #
    # The TCP port the server will listen on.
    #
    # Default value: 7500
    #
    port: 7500

    ## skip-open ##
    #
    # If true, the CLI will not automatically open the browser 
    # when the server starts.
    #
    # Default value: false
    #
    skip-open: false

## dashboard ##
#
# Settings for the web dashboard UI
#
dashboard:

  ## columns ##
  #
  # The default columns to show when displaying log records.
  #
  # Default value: ["timestamp", "dot"]
  #
  columns:
    - timestamp
    - dot
```
  </TabItem>
  <TabItem label="TOML">
```toml
# Kubetail CLI Configuration File
#
# Defines behavior for the kubetail CLI tool, including
# logs command defaults and dashboard server settings.

# Schema version for the configuration file
version = 1

[general]
# Path to kubeconfig. If empty, uses ~/.kube/config or KUBECONFIG env var.
kubeconfig = ""

[commands.logs]
# Specific Kubernetes context to use. If empty, uses active context.
kube-context = ""

# Number of lines to show from the beginning of the log buffer
head = 10

# Number of lines to show from the end of the log buffer
tail = 10

# Full set of output columns for 'logs' records.
# Allowed values: timestamp,dot,node,region,zone,os,arch,namespace,pod,container
columns = ["timestamp", "dot"]

[commands.serve]
# Network interface the server binds to
host = "localhost"

# TCP port the server listens on
port = 7500

# If true, don't automatically open browser when server starts
skip-open = false

[dashboard]
# The default columns to show when displaying log records.
columns = ["timestamp", "dot"]
```
  </TabItem>
  <TabItem label="JSON">
```json
{
  "version": 1,
  "general": {
    "kubeconfig": ""
  },
  "commands": {
    "logs": {
      "kube-context": "",
      "head": 10,
      "tail": 10,
      "columns": ["timestamp", "dot"]
    },
    "serve": {
      "host": "localhost",
      "port": 7500,
      "skip-open": false
    },
    "dashboard": {
      "columns": ["timestamp", "dot"]
    }
  }
}
```
  </TabItem>
</Tabs>

<Aside type="tip">
Environment variable expansion is supported. For example:

```yaml
commands:
  serve:
    port: ${MY_KUBETAIL_PORT}
```
</Aside>