# coredns

CoreDNS as the cluster DNS: a Corefile built from typed server blocks, a Service at the kubelet's clusterDNS address, and the dns role

This page is generated from [`kix/packages/experimental/coredns`](https://github.com/kix-run/kix/tree/main/kix/packages/experimental/coredns).

| | |
| --- | --- |
| Stability | Experimental |
| `package` value | `packages.experimental.coredns` |
| Default software version | `1.15.0` |
| Roles | `dns` |

## Dependencies

Kix matches each dependency below to another package instance by instance name, alias, or role. To bind a specific instance, set [`deps.<name>`](/docs/reference/instances-and-composition/#deps) in your cluster definition. See [Declaring dependencies](/docs/reference/package-anatomy/#declaring-dependencies) for how required and optional dependencies work.

| Dependency | Requirement |
| --- | --- |
| `prometheus` | Optional |

## Options

### `clusterIP`

Address of the Service. It must equal the kubelet's `clusterDNS`,
which every pod's resolv.conf names: `clusterDNS` in the kubelet
config (`kubectl -n kube-system get cm kubelet-config -o yaml` on
kubeadm), `--cluster-dns` on k3s and RKE2. Typically 10.96.0.10 on
kubeadm and 10.43.0.10 on k3s and RKE2.

- **Type:** `IPv4 or IPv6 address literal`
- **Example:** `"10.96.0.10"`

### `env`

Extra environment variables. A value is a string, a `fieldRef` source such as `{ valueFrom.fieldRef.fieldPath = "metadata.name"; }`, or a `secretKeyRef` source naming a Secret managed outside Kix with `kix.untrackedRef`. A credential that comes from a dependency is wired by the package. Null removes a variable the package sets by default.

- **Type:** ``attribute set of (null or string or env var source with `valueFrom`)``
- **Default:** `{ }`

### `image`

Container image for this instance. Set it from a pin file (`kix.pins`) so the deployed reference is committed and resolved.

- **Type:** `submodule`
- **Default:**

  ```nix
  {
    digest = "sha256:0a9d8c8ddf34347eb59aad9a8784f0710de88d6d112726d11d271f9bc6daca26";
    pullPolicy = "IfNotPresent";
    repository = "docker.io/coredns/coredns";
    tag = "1.15.0";
  }
  ```

### `image.digest`

Resolved manifest digest, `sha256:` followed by 64 hex characters. What will actually run. Null means not resolved.

- **Type:** `null or string`
- **Default:** the package's digest while `tag` is the package's tag, otherwise null

### `image.note`

Whatever a person wanted to say about this pin. Kix never reads it and a promotion never discards it. Declared here for the same reason as the three fields above: a pin carries its own record-keeping, and the option accepts the whole pin rather than a subset of it.

- **Type:** `null or string`
- **Default:** `null`

### `image.promotedBy`

Who resolved this pin, for the record. Null when unknown.

- **Type:** `null or string`
- **Default:** `null`

### `image.pullPolicy`

imagePullPolicy for containers using this image. Null leaves it to Kubernetes.

- **Type:** `null or string`
- **Default:** `"IfNotPresent"`

### `image.repository`

Image repository, registry host included.

- **Type:** `string`
- **Default:** `"docker.io/coredns/coredns"`

### `image.resolvedAt`

When this pin was resolved, RFC 3339. Null when unknown.

- **Type:** `null or string`
- **Default:** `null`

### `image.sourceRev`

Revision of the source the image was built from, when Kix built it. Null for upstream images.

- **Type:** `null or string`
- **Default:** `null`

### `image.tag`

Image tag. What was asked for.

- **Type:** `string`
- **Default:** `"1.15.0"`

### `metrics.enabled`

Enable metrics endpoint and monitoring resources (ServiceMonitor, PrometheusRules) when prometheus is available.

- **Type:** `boolean`
- **Default:** `true`

### `metrics.interval`

Scrape interval (e.g. "30s"). Null = use Prometheus default.

- **Type:** `null or string`
- **Default:** `null`

### `replicas`

CoreDNS replicas.

- **Type:** `positive integer, meaning >0`
- **Default:** from the availability level: 1 at none, 2 above

### `resources`

Container resource requests and limits. Each field keeps its default until set, and null removes a default.

- **Type:** `submodule`
- **Default:**

  ```nix
  {
    limits = {
      memory = "170Mi";
    };
    requests = {
      cpu = "100m";
      memory = "70Mi";
    };
  }
  ```

### `resources.claims`

Dynamic resource claims the container uses. Null leaves it unset.

- **Type:** `null or (list of (submodule))`
- **Default:** `null`

### `resources.claims.*.name`

Name of an entry in the pod's `resourceClaims`.

- **Type:** `string`

### `resources.claims.*.request`

Request within the claim to use. Null uses the whole claim.

- **Type:** `null or string`
- **Default:** `null`

### `resources.limits`

Resource quantities by name.

- **Type:** `open submodule of attribute set of Kubernetes quantity, such as "500m" or "1Gi" (a non-negative decimal or integer with an optional suffix m, k, M, G, T, P, E, Ki, Mi, Gi, Ti, Pi or Ei)`
- **Default:** `{ }`

### `resources.limits.cpu`

The cpu quantity. Null leaves it unset.

- **Type:** `null or Kubernetes quantity, such as "500m" or "1Gi" (a non-negative decimal or integer with an optional suffix m, k, M, G, T, P, E, Ki, Mi, Gi, Ti, Pi or Ei)`
- **Default:** `null`

### `resources.limits.ephemeral-storage`

The ephemeral-storage quantity. Null leaves it unset.

- **Type:** `null or Kubernetes quantity, such as "500m" or "1Gi" (a non-negative decimal or integer with an optional suffix m, k, M, G, T, P, E, Ki, Mi, Gi, Ti, Pi or Ei)`
- **Default:** `null`

### `resources.limits.memory`

The memory quantity. Null leaves it unset.

- **Type:** `null or Kubernetes quantity, such as "500m" or "1Gi" (a non-negative decimal or integer with an optional suffix m, k, M, G, T, P, E, Ki, Mi, Gi, Ti, Pi or Ei)`
- **Default:** `"170Mi"`

### `resources.requests`

Resource quantities by name.

- **Type:** `open submodule of attribute set of Kubernetes quantity, such as "500m" or "1Gi" (a non-negative decimal or integer with an optional suffix m, k, M, G, T, P, E, Ki, Mi, Gi, Ti, Pi or Ei)`
- **Default:** `{ }`

### `resources.requests.cpu`

The cpu quantity. Null leaves it unset.

- **Type:** `null or Kubernetes quantity, such as "500m" or "1Gi" (a non-negative decimal or integer with an optional suffix m, k, M, G, T, P, E, Ki, Mi, Gi, Ti, Pi or Ei)`
- **Default:** `"100m"`

### `resources.requests.ephemeral-storage`

The ephemeral-storage quantity. Null leaves it unset.

- **Type:** `null or Kubernetes quantity, such as "500m" or "1Gi" (a non-negative decimal or integer with an optional suffix m, k, M, G, T, P, E, Ki, Mi, Gi, Ti, Pi or Ei)`
- **Default:** `null`

### `resources.requests.memory`

The memory quantity. Null leaves it unset.

- **Type:** `null or Kubernetes quantity, such as "500m" or "1Gi" (a non-negative decimal or integer with an optional suffix m, k, M, G, T, P, E, Ki, Mi, Gi, Ti, Pi or Ei)`
- **Default:** `"70Mi"`

### `servers`

Corefile server blocks by name. Adding a block keeps `default`;
`servers.default.plugins.<p>.enabled = false` removes one plugin
from it, and `servers.default.enabled = false` removes the block.
Each default directive is set field by field, so overriding
`kubernetes.args` keeps its `block`.

Blocks render with those that enable `view` first, then by name.
CoreDNS answers from the first block sharing a zone and port whose
view matches, so name blocks with a prefix such as `10-office` to
order them.

A plugin that reads a file (`file`, `hosts`) reads it from a key
added to the ConfigMap with partsOverlays on `configmap`, at
`/etc/coredns/<key>`.

The package allows DNS (53) in from every pod and out to resolvers
outside the cluster. Under network policy, a block on another port,
an upstream that is a pod, or a DoT or DoH upstream needs a policy
of its own: an entry in the cluster's `networkPolicy.platformIntents`
that selects these pods (`k8s-app: kube-dns`), or a policy resource
added with partsOverlays.

- **Type:** `attribute set of (submodule)`
- **Default:**

  One block, `servers.default`, as kubeadm writes it:

  ```
  .:53 {
      cache 30 {
          disable success <clusterDomain>
          disable denial <clusterDomain>
      }
      errors
      forward . <cluster.network.dnsUpstream, or /etc/resolv.conf> {
          max_concurrent 1000
      }
      health {
          lameduck 5s
      }
      kubernetes <clusterDomain> in-addr.arpa ip6.arpa {
          pods insecure
          fallthrough in-addr.arpa ip6.arpa
          ttl 30
      }
      loadbalance
      loop
      prometheus :9153
      ready
      reload
  }
  ```
- **Example:**

  ```nix
  {
    default.plugins.forward.args = [ "." "192.0.2.53" ];
    "10-office" = {
      plugins.view.args = [ "office" ];
      plugins.view.block = [ "expr incidr(client_ip(), '192.0.2.0/24')" ];
      plugins.forward.args = [ "." "192.0.2.1" ];
    };
  }
  ```

### `servers.<name>.enabled`

Whether the server block is rendered.

- **Type:** `boolean`
- **Default:** `true`

### `servers.<name>.plugins`

Directives of the block, keyed by a name of your choice, which is
also the default plugin name. CoreDNS runs plugins in its
compiled-in order whatever the Corefile says; repeats of one
plugin run in attribute-name order.

- **Type:** `attribute set of (submodule)`
- **Default:** `{ }`

### `servers.<name>.plugins.<name>.args`

Arguments after the plugin name, one word each.

- **Type:** `list of string`
- **Default:** `[ ]`

### `servers.<name>.plugins.<name>.block`

Lines inside the directive's `{ }` block. Empty renders no block.

- **Type:** `list of string`
- **Default:** `[ ]`

### `servers.<name>.plugins.<name>.enabled`

Whether the directive is rendered.

- **Type:** `boolean`
- **Default:** `true`

### `servers.<name>.plugins.<name>.name`

The plugin the directive runs. Set it to repeat a plugin under another attribute, for example `rewrite-a = { name = "rewrite"; args = [ ... ]; }`.

- **Type:** `string`
- **Default:** the attribute name

### `servers.<name>.port`

Port the block listens on, for every zone in its header.

- **Type:** `16 bit unsigned integer; between 0 and 65535 (both inclusive)`
- **Default:** `53`

### `servers.<name>.zones`

Zones the block serves, such as `.` or `example.org`. The port goes
in `port`, not in the zone. A zone with a scheme (`dns://`,
`tls://`, `https://`, `grpc://`, or `quic://`) is refused: write a
plain DNS zone without one. A TLS server needs a certificate in the
pod and a Corefile block that `servers` does not build; add both
with partsOverlays on `configmap` and `deployment`.

- **Type:** `non-empty (list of DNS zone name without a scheme or a :port suffix)`
- **Default:**

  ```nix
  [
    "."
  ]
  ```