Local Development
Run the operator from your IDE against a development cluster: install the CRDs, start the operator, and make its webhooks reachable for the API server.
kubeops install, the CRD Installer or Aspire#if DEBUG, not the registrationRun the operator locally
dotnet run or the debugger starts the operator on your machine. It connects to the cluster of your current kubectl
context (KUBECONFIG or ~/.kube/config) with your credentials, so check it with
kubectl config current-context first.
The CRDs must be in the cluster before the operator starts watching:
| Option | Use it when |
|---|---|
kubeops install | You install the CRDs once per change from the command line |
| CRD Installer | The operator installs its CRDs on every start; development only |
| Aspire | An AppHost starts the operator; it creates missing CRDs |
An operator without webhooks needs nothing more.
Webhooks
The API server calls webhooks over HTTPS, so it must reach the operator on your machine:
| Your cluster | Use |
|---|---|
| kind, Docker Desktop, minikube or in your network | Certificate provider |
| Cloud, or behind NAT or VPN | Tunnel |
| Started by an Aspire AppHost | Aspire |
With each of them, the operator registers its webhooks at startup: the validation and mutation webhooks as the
configurations dev-validators and dev-mutators, and each conversion webhook in its CRD, if the CRD exists.
Certificate provider
CertificateGenerator creates a self-signed certificate for an IP address or host name of your machine.
var operatorBuilder = builder.Services
.AddKubernetesOperator()
.RegisterComponents();
#if DEBUG
const string ip = "192.168.1.100";
const ushort port = 443;
using var generator = new CertificateGenerator(ip);
var cert = generator.Server.CopyServerCertWithPrivateKey();
builder.WebHost.ConfigureKestrel(
o => o.Listen(IPAddress.Any, port, l => l.UseHttps(cert)));
operatorBuilder.UseCertificateProvider(port, ip, generator);
#endif
With kind, Docker Desktop or minikube, the API server runs in a container or VM, so localhost is not your machine.
Use an address that is reachable from there, e.g. your LAN IP or the gateway of the container network.
Tunnel
UseExternalWebhookEndpoint registers the webhooks with the public HTTPS URL of a tunnel. The tunnel terminates TLS,
so the operator listens on plain HTTP.
var operatorBuilder = builder.Services
.AddKubernetesOperator()
.RegisterComponents();
#if DEBUG
operatorBuilder.UseExternalWebhookEndpoint(
new Uri("https://my-tunnel-5000.euw.devtunnels.ms"));
#endif
- URL from configuration. Without arguments,
UseExternalWebhookEndpoint()readsKubeOps:Webhooks:ExternalUrl(environment variableKubeOps__Webhooks__ExternalUrl) and fails the start if it is missing. - Own certificate. For an endpoint without a publicly trusted certificate, pass its CA:
UseExternalWebhookEndpoint(uri, caBundle). - Path prefix.
https://proxy.example.com/my-operatorregistershttps://proxy.example.com/my-operator/validate/v1demoentity. The operator serves the routes at the root, so the proxy must strip the prefix.
The examples forward to an operator on http://localhost:5000. A persistent URL saves you from updating the
configuration on every run.
- Dev Tunnels
- Cloudflare
- ngrok
# login once, create once, host every session
devtunnel user login
devtunnel create kubeops-dev --allow-anonymous
devtunnel port create kubeops-dev -p 5000 --protocol http
devtunnel host kubeops-dev
# → https://<tunnel-id>-5000.<region>.devtunnels.ms
# quick tunnel: no account, new URL on every start
cloudflared tunnel --url http://localhost:5000
# → https://<random>.trycloudflare.com
# account required, free static domain
ngrok config add-authtoken <token>
ngrok http 5000 --url=<name>.ngrok-free.app
Aspire
WithWebhookDevTunnel from KubeOps.Aspire.Hosting starts a Microsoft Dev Tunnel for the operator's http
endpoint, passes its URL as KubeOps__Webhooks__ExternalUrl and starts the operator once the tunnel runs.
- AppHost
- Operator
builder.AddKubeOps("operator", "../WebhookOperator")
.RunWithKubernetes(dev)
.WithWebhookDevTunnel();
var operatorBuilder = builder.Services
.AddKubernetesOperator()
.RegisterComponents();
#if DEBUG
operatorBuilder.UseExternalWebhookEndpoint();
#endif
Install the devtunnel CLI; Aspire asks you to sign in when needed. The URL stays the same across runs. Pass another
endpoint name or tunnel options, e.g. WithWebhookDevTunnel("webhooks", tunnel => tunnel.WithExpiration(24)). In
publish mode, WithWebhookDevTunnel adds nothing. For the rest of the AppHost setup, see
.NET Aspire.
Security and shared clusters
The API server cannot authenticate against a tunnel, so the tunnel allows anonymous access. Anyone who knows the URL can call your webhooks while it runs. Your organization's policy may forbid this.
- Cluster-wide. The webhooks intercept everyone's requests for the resource type, not only yours. On a shared
cluster, use a dedicated CRD group or a
NamespaceSelectorvia a custom webhook configuration factory. - Cloud clusters. The API server calls the tunnel from the control plane. If its outbound traffic goes through your network (e.g. API server VNet integration on AKS), allow the tunnel domain there.
Common pitfalls
- The operator works on the wrong cluster. It uses your current kubectl context; switch it before you start.
- Writes are blocked after the operator stopped.
dev-validatorsanddev-mutatorsstay registered after a crash and withUseCertificateProvider, and the API server rejects writes it cannot validate.UseExternalWebhookEndpointandWithWebhookDevTunnelremove them when the operator stops. Delete them withkubectl delete validatingwebhookconfiguration dev-validatorsandkubectl delete mutatingwebhookconfiguration dev-mutators. - Other versions fail after the operator stopped. The conversion webhook stays in the CRD, so requests for a
non-stored version fail. Start the operator again, or set
spec.conversion.strategytoNonein the CRD.