Manage MikroTik RouterOS configuration from Kubernetes. The operator supports RouterOS v6 and v7 and is designed for local Kubernetes clusters, such as k3s, where a MikroTik router is the network gateway.
Read the public documentation for installation, usage, reference, architecture, and troubleshooting.
It creates DNS records, routes, NAT port forwards, and firewall rules while only managing configuration entries that it owns. Existing RouterOS rules are left untouched.
- Stand-alone Go operator using controller-runtime.
- RouterOS v6 and v7 support through the RouterOS API.
- One logical
MikroTikRoutercan manage multiple router endpoints. - Credentials loaded from Kubernetes Secrets.
- Automatic DNS records and routes for annotated Services.
- Ingress and Gateway API
HTTPRoutesupport. /32routes for ClusterIP Services through all node addresses, with an optional single-node mode.- Destination NAT and matching source masquerade rules for exposed Services.
- Managed forward firewall rules for port forwards.
- Custom resources for DNS records, routes, port forwards, and firewall rules.
- Idempotent reconciliation and periodic drift correction.
- Optional admin UI for listing, inspecting, and creating custom resources.
The operator watches Kubernetes resources and reconciles the desired state to RouterOS. Every generated RouterOS entry receives a managed comment, allowing the operator to update or remove only its own entries.
The core resources are namespaced:
| Resource | Purpose |
|---|---|
MikroTikRouter |
Router connection, credentials, and optional endpoints |
MikroTikDNSRecord |
/ip dns static record |
MikroTikRoute |
/ip route entry |
MikroTikPortForward |
dst-nat, src-nat, and forward firewall rules |
MikroTikFirewallRule |
Custom /ip firewall filter entry |
routerRef is optional when exactly one non-deleting MikroTikRouter exists
in the resource namespace, or when that namespace has none and exactly one
non-deleting router exists in the cluster. Set routerRef to name or
namespace/name when more than one router exists. Credentials stay in the
router namespace. TLS API connections verify certificates with the Go
defaults.
Create a credentials Secret and router resource. Do not commit real credentials to source control.
kubectl create secret generic mikrotik-credentials \
--from-literal=username=operator \
--from-literal=password='change-me'
kubectl apply -f examples/router.yamlInstall the operator and CRDs with Helm:
helm upgrade --install mikrotik-operator ./charts/mikrotik-operator \
--namespace mikrotik-operator-system \
--create-namespaceThe chart installs the operator, RBAC, CRDs, probes, and the mikrotik
IngressClass. Pin an image tag or digest for production deployments:
helm upgrade --install mikrotik-operator ./charts/mikrotik-operator \
--namespace mikrotik-operator-system \
--create-namespace \
--set image.tag=v0.4.0The raw Kubernetes resources are also available under config/.
The chart can deploy an optional browser panel for routers, DNS records, routes, port forwards, and firewall rules. It is disabled by default and has no authentication. Enable it only on a trusted network or behind an authenticating proxy.
helm upgrade --install mikrotik-operator ./charts/mikrotik-operator \
--namespace mikrotik-operator-system \
--create-namespace \
--set ui.enabled=truePort-forward the ClusterIP Service, then open http://127.0.0.1:8080:
kubectl -n mikrotik-operator-system port-forward \
svc/mikrotik-operator-mikrotik-operator-ui 8080:8080On a Linux host, just test-install-ui installs K3s and the chart with the
UI enabled. See docs/_guide/admin-ui.md for the
full guide.
The dashboard shows counts for routers, DNS records, routes, port forwards, and firewall rules, plus objects that are not Ready.
List pages include name/spec search, a searchable namespace filter, and
create/edit/delete for standalone resources. Ownership badges truncate with
an ellipsis; hover to read the full Managed · Service/namespace/name text.
Resources generated from a Service, Ingress, or HTTPRoute show a
Managed by banner. Edit and delete are disabled; change the owning
Kubernetes object instead.
Annotate a Service to create an owned DNS record:
metadata:
annotations:
mikrotik.operator.io/dns-name: web.home.arpa
mikrotik.operator.io/public-ip: 203.0.113.10The public-ip annotation creates one port forward per TCP or UDP Service
port. For ClusterIP Services, the destination is the Service ClusterIP. For
NodePort Services, DNS points to a node InternalIP and uses the NodePort.
For ClusterIP routing, the operator creates owned MikroTikRoute objects
(/32 through every node InternalIP by default). Use the following annotation
when only one node should be used:
metadata:
annotations:
mikrotik.operator.io/route-mode: single-nodeUse mikrotik.operator.io/router-ref when more than one router exists.
The value may be a router name or namespace/name.
Ingress resources use the mikrotik IngressClass and need no special DNS
annotation. Each hostname is mapped to its backend Service address.
Gateway API support is disabled by default. Enable it and create the GatewayClass through Helm:
helm upgrade --install mikrotik-operator ./charts/mikrotik-operator \
--namespace mikrotik-operator-system \
--create-namespace \
--set gatewayAPI.enabled=true \
--set gatewayAPI.gatewayClass.create=trueGateway API CRDs must be installed separately. See
examples/gateway-api.yaml for a minimal
Gateway and HTTPRoute.
Install a single-node K3s server and the operator chart on a Linux host (requires just, Helm, and kubectl):
just test-installTo include the optional admin UI (no authentication; trusted networks only):
just test-install-uijust test-install true does the same. After install, port-forward
the UI Service as described in docs/_guide/admin-ui.md.
Override IMAGE_TAG to pin operator and UI images together.
On WSL2, Docker Desktop adds a /Docker/host mount whose options contain an
unescaped space. Kubelet treats that as a fatal /proc/mounts parse error and
K3s crash-loops. just k3s-install applies a systemd workaround that hides
the mount from K3s only. k3d (used by just e2e-test) is unaffected because
it does not run kubelet on the WSL host.
The full RouterOS-backed E2E test uses k3d, which runs K3s inside Docker, and
the docker-routeros
RouterOS QEMU image as a Docker container with its API published onto the k3d
network. It requires Docker, k3d, kubectl, Helm, Go, and a Linux shell such as
WSL:
just e2e-testThe test builds and imports the operator image, starts a disposable RouterOS
container, installs Gateway API and the Helm chart, applies resources covering
Services, NodePorts, Ingress, HTTPRoute, DNS, routes, NAT, and firewall rules,
then verifies the resulting entries through the RouterOS native API. The
RouterOS test image uses its default admin account with an empty password by
default. Override E2E_ROUTER_IMAGE, E2E_CLUSTER_NAME, or
E2E_OPERATOR_IMAGE when needed.
just fmt-check
just test
just vet
just build
just helm-lint
just ui-test
helm template validation charts/mikrotik-operator --include-crds
cd web/ui && npm ci && npm run buildjust e2e-ui-test installs the chart with the UI enabled on k3d and CRUDs
each CR over HTTP; it does not start RouterOS. Keep CRD YAML identical in
config/crd/bases and charts/mikrotik-operator/crds.
GitHub Actions validates formatting, tests, race tests, vet, vulnerability
scanning, Go linting, Docker builds, Helm resources, Kubernetes manifests,
workflow syntax, and the GoReleaser configuration. Trusted vMAJOR.MINOR.PATCH
tags publish multi-arch operator and admin UI images with GoReleaser. Helm
chart packages are published from main when charts/mikrotik-operator/Chart.yaml
gets a new version, independent of image tags. Re-publishing an existing
chart version is skipped. GitHub Releases contain changelog notes only; the
operator is consumed as a container, not as a standalone binary. Dependabot
opens grouped weekly updates for Go modules, GitHub Actions, and pinned
container images.
Read AGENTS.md and .github/copilot-instructions.md
before making changes. Keep changes focused, add tests for behavior changes,
and validate the affected Go, Kubernetes, Helm, and RouterOS paths before
opening a pull request. Use the repository issue forms for bug reports and
feature requests.
The operator architecture is documented in
docs/_reference/how-it-works.md. Operational failures and
common pitfalls are in docs/_guide/troubleshooting.md.
Use a dedicated RouterOS account with only the API policies required by the deployment, and keep RouterOS reachable from the operator Pod over TCP 8728 or 8729.
api/— Kubernetes API types.cmd/manager/— operator binary.cmd/ui-backend/— optional admin UI server.internal/controller/— reconcilers.internal/routeros/— RouterOS client and desired state operations.internal/uiapi/— admin UI REST API.web/ui/— React admin panel.charts/mikrotik-operator/— Helm chart.config/— raw manifests and Kustomize resources.examples/— sample resources and smoke-test manifests.



