> ## Documentation Index
> Fetch the complete documentation index at: https://ngrok.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Private Connectivity with the ngrok Kubernetes Operator

> Let pods in your cluster reach ngrok private endpoints (`*.ngrok.direct`) by URL with the ngrok Kubernetes Operator.

Private connectivity lets pods in your cluster reach ngrok private endpoints by their real URL, such as `https://demo.ngrok.direct`.
Private endpoints are ngrok endpoints on `*.ngrok.direct` with no public address.
Use it when a service your workloads need runs in another network, and you don't want to expose it to the public internet.

In the Helm chart, the feature is `ngrok.features.privateEndpoints`, and the Operator tracks each endpoint as a `PrivateEndpoint` resource.

> [!NOTE]
>
> Private connectivity is in preview and off by default.
> Request access in your [ngrok dashboard](https://dashboard.ngrok.com/early-access#private-connectivity)
> It requires Helm chart `0.25.0` or later.

## How it works

When you enable the feature, the Operator:

1. Polls your account every 10 seconds for `*.ngrok.direct` endpoints and mirrors each one as a `PrivateEndpoint` resource in the Operator namespace.
2. Creates a `ClusterIP` Service for each hostname in the Operator namespace.
   `demo.ngrok.direct` becomes the Service `demo-ngrok-direct`, with one port for each endpoint port.
3. Runs a `private-endpoint-forwarder` Deployment behind those Services.
   It accepts connections and opens a private dial connection to the matching endpoint through ngrok.

You configure cluster DNS to resolve `demo.ngrok.direct` to the `demo-ngrok-direct` Service.

```mermaid theme={"theme":{"light":"css-variables","dark":"css-variables"}}
flowchart TB
  Pod -- "resolve demo.ngrok.direct" --> CoreDNS
  Pod -- "connect" --> Service["Service demo-ngrok-direct"]
  Service --> Forwarder["private-endpoint-forwarder"]
  Forwarder -- "private dial" --> ngrok["ngrok cloud"]
  ngrok --> Endpoint["demo.ngrok.direct"]
```

The forwarder copies bytes in both directions.
It doesn't terminate TLS or read headers, so what your client sees depends on the endpoint's scheme:

| Scheme | What the client sees |
| - | - |
| `http` | Plain HTTP. |
| `https` | ngrok's publicly trusted `*.ngrok.direct` certificate. Standard certificate verification works. |
| `tls` | The upstream service's own certificate, end to end. |
| `tcp` | Raw TCP. |

The Operator doesn't mirror `*.internal` endpoints, or endpoints with the `kubernetes` binding, which [bindings](https://ngrok.com/docs/gateway/k8s/guides/bindings.md) handle.

## Private connectivity vs. bindings

Kubernetes bindings also let pods reach ngrok endpoints without public exposure.
Private connectivity is intended to replace them, so use it for new setups.
Both can run in the same install without overlapping.

| | Kubernetes bindings | Private connectivity |
| - | - | - |
| Which endpoints | Endpoints with the `kubernetes` binding that match your selectors | Every `*.ngrok.direct` endpoint in the account |
| Name clients use | `<service>.<namespace>` | The endpoint's real URL, with valid TLS |
| DNS changes | None | One rewrite rule |
| Credentials | Certificate issued to the Operator | Access token with `gateway:endpoints:connect` |

## Prerequisites

* Helm chart `0.25.0` or later.
* An [access token](https://ngrok.com/docs/iam/access-tokens.md#create-an-access-token) that includes `gateway:endpoints:connect`.
  The **Quick select → Kubernetes Operator** preset includes it.
* Permission to change your cluster's DNS configuration.
* Outbound access from the forwarder pods to `h2.connect-endpoint.ngrok.com` on TCP/443.
  QUIC also uses `quic.connect-endpoint.ngrok.com` on UDP/443 when it's allowed.
  See [Network egress](https://ngrok.com/docs/gateway/k8s/installation/network-egress.md#private-endpoints-preview).

## Enable private connectivity

Add this to your Operator's Helm values, then install or upgrade as usual (see [Update the Operator](https://ngrok.com/docs/gateway/k8s/installation/update.md)):

```yaml theme={"theme":{"light":"css-variables","dark":"css-variables"}}
ngrok:
  features:
    privateEndpoints:
      enabled: true
```

The forwarder uses the same access token as the rest of the Operator.
If your credentials come from an existing `Secret`, add a `PRIVATE_ENDPOINTS_ACCESS_TOKEN` key to it before upgrading, or the forwarder won't start.

Confirm the forwarder is running:

```bash theme={"theme":{"light":"css-variables","dark":"css-variables"}}
kubectl -n ngrok-operator get pods -l app.kubernetes.io/component=private-endpoint-forwarder
```

## Configure cluster DNS

Your cluster DNS must resolve each `<label>.ngrok.direct` name to the ClusterIP of the `<label>-ngrok-direct` Service in the Operator namespace.
The Operator doesn't change cluster DNS, so you add this yourself.

On CoreDNS, one rewrite rule covers every endpoint:

```text wrap theme={"theme":{"light":"css-variables","dark":"css-variables"}}
rewrite stop name regex ^([a-z][a-z0-9-]*)\.ngrok\.direct\.$ {1}-ngrok-direct.ngrok-operator.svc.cluster.local. answer auto
```

Replace `ngrok-operator` if you installed into a different namespace, and `cluster.local` if your cluster uses a different domain.
Names that don't match an existing Service return `NXDOMAIN`.

The rule is the same on every CoreDNS cluster.
Where you put it depends on who manages CoreDNS.
If Helm, GitOps, or Terraform owns your CoreDNS config, make the change there so it isn't reverted.

> [tab] kind / self-managed
>
> Edit the `coredns` ConfigMap and add the rule inside the existing `.:53 { }` block.
> Don't add a second server block.
>
> ```bash theme={"theme":{"light":"css-variables","dark":"css-variables"}}
> kubectl -n kube-system edit configmap coredns
> kubectl -n kube-system rollout restart deployment/coredns
> ```
>
> For kind, the Operator repo includes a [script](https://github.com/ngrok/ngrok-operator/blob/main/scripts/kind-private-endpoints-dns.sh) that applies the rule for you.

> [tab] EKS
>
> CoreDNS runs as an EKS add-on, and add-on updates can overwrite direct ConfigMap edits.
> Put the full Corefile in the add-on's `corefile` configuration value instead.
>
> ```bash theme={"theme":{"light":"css-variables","dark":"css-variables"}}
> CLUSTER=my-cluster
>
> # Start from the current Corefile, then add the rule inside the .:53 { } block
> kubectl -n kube-system get configmap coredns -o jsonpath='{.data.Corefile}' > Corefile
>
> # Merge it into the add-on's existing configuration values
> aws eks describe-addon --cluster-name "$CLUSTER" --addon-name coredns \
>   | jq -r '.addon.configurationValues // "{}"' > values.json
> jq --rawfile corefile Corefile '. + {corefile: $corefile}' values.json > values.ngrok.json
>
> aws eks update-addon --cluster-name "$CLUSTER" --addon-name coredns \
>   --configuration-values file://values.ngrok.json \
>   --resolve-conflicts PRESERVE
> ```
>
> See [Manage CoreDNS on EKS](https://docs.aws.amazon.com/eks/latest/userguide/managing-coredns.html).

> [tab] AKS
>
> AKS reverts changes to the `coredns` ConfigMap.
> Add the rule to the `coredns-custom` ConfigMap under a key ending in `.override`, keeping any existing keys:
>
> ```yaml wrap theme={"theme":{"light":"css-variables","dark":"css-variables"}}
> apiVersion: v1
> kind: ConfigMap
> metadata:
>   name: coredns-custom
>   namespace: kube-system
> data:
>   ngrok.override: |
>     rewrite stop name regex ^([a-z][a-z0-9-]*)\.ngrok\.direct\.$ {1}-ngrok-direct.ngrok-operator.svc.cluster.local. answer auto
> ```
>
> ```bash theme={"theme":{"light":"css-variables","dark":"css-variables"}}
> kubectl -n kube-system rollout restart deployment/coredns
> ```
>
> See [Customize CoreDNS with AKS](https://learn.microsoft.com/en-us/azure/aks/coredns-custom).

> [tab] K3s
>
> K3s rewrites its packaged `coredns` ConfigMap.
> Add the rule to the `coredns-custom` ConfigMap under an `ngrok.override` key, the same as the AKS tab, then restart CoreDNS.

> [tab] GKE
>
> GKE's default DNS, kube-dns, can't rewrite names, but it can forward a domain to another DNS server.
> Run a small CoreDNS Deployment that applies the rule, and forward `ngrok.direct` to it.
>
> 1. Deploy CoreDNS in any namespace with this Corefile, and expose it with a Service on port 53 over both UDP and TCP:
>
>    ```text wrap theme={"theme":{"light":"css-variables","dark":"css-variables"}}
>    ngrok.direct:53 {
>        rewrite stop name regex ^([a-z][a-z0-9-]*)\.ngrok\.direct\.$ {1}-ngrok-direct.ngrok-operator.svc.cluster.local. answer auto
>        forward . <KUBE_DNS_IP>
>    }
>    ```
>
>    Get `<KUBE_DNS_IP>` with `kubectl -n kube-system get svc kube-dns -o jsonpath='{.spec.clusterIP}'`.
>
> 2. Add a stub domain to the `kube-dns` ConfigMap that points at your CoreDNS Service's ClusterIP, keeping any existing entries:
>
>    ```yaml theme={"theme":{"light":"css-variables","dark":"css-variables"}}
>    apiVersion: v1
>    kind: ConfigMap
>    metadata:
>      name: kube-dns
>      namespace: kube-system
>    data:
>      stubDomains: |
>        {"ngrok.direct": ["<COREDNS_SERVICE_IP>"]}
>    ```
>
> With Cloud DNS for GKE, stub domains become Cloud DNS forwarding zones, which query from outside the cluster.
> Point them at an address your VPC can reach, such as an internal load balancer.
> Autopilot clusters don't allow changes to kube-dns.
>
> See [About kube-dns for GKE](https://docs.cloud.google.com/kubernetes-engine/docs/concepts/kube-dns) and [About Cloud DNS for GKE](https://docs.cloud.google.com/kubernetes-engine/docs/concepts/about-cloud-dns).

If your cluster DNS can't apply a rewrite rule or forward to a server that can, add a record for each private endpoint hostname that points at its Service's ClusterIP.

`tcp` and `tls` endpoints also work without any DNS change if clients call the Service name directly, such as `demo-ngrok-direct.ngrok-operator:5432`.
`http` and `https` endpoints don't, because ngrok rejects requests whose `Host` header isn't the endpoint's hostname.

## Test the connection

Start a private endpoint in the same ngrok account as the Operator, pointing at a service you want to reach.
For example, with the agent:

```bash theme={"theme":{"light":"css-variables","dark":"css-variables"}}
ngrok http 8080 --url https://demo.ngrok.direct
```

Within about 10 seconds, the Operator mirrors it:

```bash theme={"theme":{"light":"css-variables","dark":"css-variables"}}
kubectl -n ngrok-operator get privateendpoints
```

```text theme={"theme":{"light":"css-variables","dark":"css-variables"}}
NAME                          URL                         SCHEME   CLUSTERIP      READY   AGE
demo.ngrok.direct-https-443   https://demo.ngrok.direct   https    10.96.47.186   True    9s
```

Then send a request from a pod:

```bash theme={"theme":{"light":"css-variables","dark":"css-variables"}}
kubectl run curl-test --rm -it --restart=Never --image=curlimages/curl -- curl -sS https://demo.ngrok.direct
```

## Configuration

| Value | Default | Description |
| - | - | - |
| `ngrok.features.privateEndpoints.enabled` | `false` | Turns on private connectivity. |
| `ngrok.features.privateEndpoints.privateDialProtocol` | `auto` | `auto` tries QUIC and HTTP/2 and keeps whichever connects first. Set `quic` or `h2` to use one. |
| `components.privateEndpointForwarder.replicaCount` | `1` | Forwarder replicas. Every replica serves every endpoint. |
| `components.privateEndpointForwarder.resources` | `{}` | Forwarder resource requests and limits. |

See [Helm values](https://ngrok.com/docs/gateway/k8s/installation/helm.md) for the rest.

## Limitations

* Every pod in the cluster can reach every mirrored endpoint.
  Sending the calling pod's identity, so Traffic Policy can restrict access by namespace, is coming soon.
* Only single-label hostnames work: `<label>.ngrok.direct`, where the label starts with a letter, uses lowercase letters, digits, and `-`, and is at most 50 characters.
* A cluster supports up to 1,000 endpoint ports.
* IPv4 only.
* Only one Operator install per cluster can serve private endpoints, because the DNS rule points at a single namespace.

## Troubleshooting

**No `PrivateEndpoint` for an endpoint.**
Check the hostname ends in `.ngrok.direct`, the endpoint is in the same account as the Operator, and it doesn't use the `kubernetes` binding.

**`PrivateEndpoint` isn't ready.**
The `Ready` condition's reason tells you why:

| Reason | Meaning |
| - | - |
| `UnsupportedHostname` | The hostname can't become a Service name. See the hostname rules in [Limitations](#limitations). |
| `PortConflict` | Another `PrivateEndpoint` already serves this hostname and port. |
| `PortsExhausted` | The cluster has reached its 1,000 endpoint port limit. |
| `ServiceConflict` | A Service the Operator doesn't manage already uses the name `<label>-ngrok-direct`. |
| `ServiceNotReady` | The Service doesn't have a ClusterIP yet. |

`Ready` means the Service is configured.
It doesn't confirm the endpoint is reachable.

**Forwarder pod isn't ready.**
Check its logs.
Common causes are a missing `PRIVATE_ENDPOINTS_ACCESS_TOKEN` key, a token without `gateway:endpoints:connect`, or blocked egress.

```bash theme={"theme":{"light":"css-variables","dark":"css-variables"}}
kubectl -n ngrok-operator logs -l app.kubernetes.io/component=private-endpoint-forwarder
```

**`421 Misdirected Request`.** The request's `Host` header isn't the endpoint's hostname, usually because the client called the Service name instead of the `*.ngrok.direct` URL.

**DNS doesn't resolve.**
If every `*.ngrok.direct` name returns `NXDOMAIN`, the DNS rule is missing or wasn't loaded.
If only one does, check its Service exists and the namespace in the rule matches.

## Disable or uninstall

Disabling the feature or uninstalling the Operator leaves the per-hostname Services behind.
Delete them, then remove the DNS rule:

```bash theme={"theme":{"light":"css-variables","dark":"css-variables"}}
kubectl -n ngrok-operator delete svc -l ngrok.com/managed-by=private-endpoint-poller
```

If you only disabled the feature, also run `kubectl -n ngrok-operator delete privateendpoints --all`.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.