Kubernetes Connection Lifecycle
This guide explains what actually happens when Meshery manages a Kubernetes Connection: the components Meshery deploys, how it stays in sync with your cluster, the connectivity it depends on, and the knobs and diagnostics you use to operate it. For the generic connection state machine that applies to every kind of connection, see Connections; for how to register one in the first place, see Registering a Connection.
What happens when you connect a cluster
Meshery automatically discovers the clusters in your kubeconfig
($HOME/.kube/config) and, for each, tracks a Connection through its
lifecycle states
DiscoveredโRegisteredโConnected, and laterDisconnected/Deletedas appropriate.
When a Kubernetes connection transitions to Connected, Meshery (depending on the MeshSync deployment mode) brings up the pieces needed to observe the cluster and begins streaming live cluster state into the Meshery Database. From that point the Connections table and the cluster views reflect what is really running in the cluster.
The in-cluster components
In operator mode, three components run inside the managed cluster
(namespace meshery):
| Component | What it is | What it does |
|---|---|---|
| Meshery Operator | A Kubernetes operator | Deploys and reconciles the Broker and MeshSync; owns their lifecycle. |
| Meshery Broker | A NATS server (meshery-nats) | The message bus. MeshSync publishes cluster state to it; Meshery Server subscribes to it. |
| MeshSync | A custom controller | Watches the cluster (multi-tier discovery) and publishes changes to the Broker. |
Each reports a status that surfaces on the connection (for example the Broker and MeshSync move to CONNECTED once Meshery is actually receiving data). See Understanding the status.
One Operator per cluster, shared by every connection
The Operator is a cluster singleton: one Helm release, meshery-operator in
namespace meshery, serves every operator-mode connection to that cluster -
several kubeconfig contexts naming the same API server, several users of one
Meshery Server, and other Meshery Servers managing the same cluster. Meshery
recognizes a cluster by its Kubernetes server ID (the kube-system namespace
UID), so different API server addresses for one cluster count as one when
each context was imported while the cluster was reachable. A context imported
while its cluster was unreachable carries no server ID and is matched only by
its exact API server address.
Because of that, Meshery manages the Operator at cluster scope:
- Installing is serialized per cluster. When several connections to one
cluster connect at once, one installs the Operator and the others find it
installed, instead of racing each other into
helm install. The serialization only covers connections whose cluster keys match: connections reaching the same cluster through different addresses, with no server ID to tie them together, can still race to install the Operator. - Disconnecting, deleting, or switching a connection to embedded mode never
uninstalls the Operator. Each only ends that connection’s use of it. The
Operator stays installed even after the last connection on this Meshery
Server leaves, because Meshery cannot see every consumer - another Meshery
Server, or an Operator installed with Helm or
mesheryctl, may still depend on it. - Uninstalling is an explicit request, made through the GraphQL
changeOperatorStatusmutation (target statusDISABLED). It removes the Operator for every connection to the cluster. When other connections on the same Meshery Server were using it, Meshery raises a warning event, Meshery Operator removed from a cluster other connections use, that names the ones it can match inaffectedConnectionIDs. A connection reaching the same cluster through a different address, with no server ID to tie it to this cluster, is not listed. Those connections reinstall the Operator the next time they connect in operator mode; switch them to embedded mode to keep it off.
To remove the Operator from a cluster nothing uses any more, first check the
target cluster with kubectl config current-context, then run
helm uninstall meshery-operator -n meshery --kube-context <context> with
that cluster’s context, so the removal cannot land on whatever cluster the
active context happens to select.
Which Operator version gets installed
Meshery Server installs the Operator as a Helm chart from meshery.io/charts. The version it asks for tracks the Meshery Server release, but the Server checks that version against the repository’s published index before installing, so it never asks Helm for a chart that does not exist:
- Not published yet (chart publishing trails Server releases): the newest published chart is installed instead.
- Too old to run: a version below the oldest chart verified to deploy is raised to the oldest published chart at or above that boundary.
- Release candidates are never selected automatically.
Neither substitution is silent - each is reported in the events feed, naming
the version deployed and why. To choose the version yourself for one
connection, set operator.version; an explicit pin is honored exactly, and is
refused with a visible error if it names a version the repository does not
publish or a moving tag such as stable-latest. Details, including how to
confirm what is deployed, are in
Choosing the chart version yourself.
What the Operator then deploys is pinned by the Operator itself: MeshSync and the Broker run specific released versions with pull policies to match, so nothing drifts underneath a restart.
MeshSync deployment modes
Meshery can run MeshSync in one of two modes. You can set it per connection, and
the default can be set with the MESHSYNC_DEFAULT_DEPLOYMENT_MODE server
environment variable.
Operator mode
The Operator, Broker (NATS) and MeshSync run inside the cluster. MeshSync publishes to the in-cluster Broker and Meshery Server subscribes to it. This is the scalable model - it isolates discovery from Meshery Server and works well across many clusters - but it requires Meshery Server to have a network path to the in-cluster Broker (see Broker connectivity).
Embedded mode (default)
MeshSync runs in-process inside Meshery Server (using an internal, in-memory message channel instead of NATS), watching the cluster directly through the Kubernetes API that Meshery already has access to. No Operator, NATS, or port-forward is involved - so it “just works” out of the box for a single, directly-reachable cluster. The trade-off is that discovery consumes Meshery Server’s own resources and it separates less cleanly across many clusters.
Switch a connection’s MeshSync mode from the Kubernetes connection’s actions in
the UI. Under the hood this calls
POST /api/integrations/connections/{connectionId}/actions with
{"action":"setMeshsyncMode","mode":"operator"|"embedded"}; Meshery tears down
the old setup and redeploys MeshSync in the new mode. Switching to embedded mode
leaves the cluster’s Operator installed, because other connections may share it
(see One Operator per cluster).
Broker connectivity
This section applies to operator mode only (embedded mode has no in-cluster Broker). For Meshery Server to receive MeshSync data it must be able to both reach and authenticate to the Broker.
Authentication (token)
The Meshery Operator provisions NATS with token authentication and stores the
token in the meshery-nats-auth secret. Meshery Server reads that token and
presents it when connecting; without it the Broker rejects the connection with an
authorization violation. This is automatic - there is nothing to configure.
If the Broker is recreated - the Operator reinstalled, or the meshery
namespace rebuilt - it comes back with a new token and often a new endpoint,
and the connection Meshery holds keeps presenting the old ones. Meshery notices:
once a Broker connection has been down for about 45 seconds, it re-reads the
Broker’s endpoint and the meshery-nats-auth token, and if the token changed,
or the Broker answers at a different endpoint, it rebuilds the MeshSync data
connection with the new values and raises an informational Meshery Broker
changed; reconnecting MeshSync event. A Broker
that is only down, with the same endpoint and token, is left to reconnect on its
own. No server restart or reconnect is needed.
Reachability
What matters is whether Meshery Server runs in the connection’s own cluster, not whether it runs in a cluster at all:
- Meshery running in the connection’s cluster (Helm /
mesheryctl system start --platform kubernetes, managing the cluster it is installed in): the Broker’sClusterIPis directly reachable. Nothing to do. - Meshery running anywhere else - a Docker host, your laptop, or a Pod in a
different cluster: the Broker is typically exposed as
ClusterIPonly, which is not reachable from outside its cluster. Meshery needs a path to it.
Managed port-forward (automatic)
Unless Meshery Server runs in the connection’s own cluster, it automatically
establishes a self-healing port-forward to the Broker’s NATS pod through the
Kubernetes API server (the same mechanism as kubectl port-forward, using the
credentials Meshery already holds) and connects to NATS over it. It
re-establishes the tunnel if the pod restarts or the connection drops, and tears
it down when the connection is disconnected or deleted. No manual kubectl port-forward is required.
Meshery recognizes its own cluster by Kubernetes server ID (the kube-system
namespace UID), so a kubeconfig that names that cluster by an external address
still counts as the same cluster. If the server ID cannot be read - for example,
Meshery’s service account may not read namespaces - only a connection that names
the in-cluster API endpoint (kubernetes.default.svc or the
KUBERNETES_SERVICE_HOST address) is treated as Meshery’s own cluster; every
other connection gets the port-forward, which costs at most a hop through the
API server.
| Behavior | Detail |
|---|---|
| Default | On for every connection to a cluster other than the one Meshery runs in. |
| Meshery’s own cluster | Skipped automatically (the ClusterIP is directly reachable). |
| Disable | Set MESHERY_MANAGED_BROKER_PORTFORWARD=false on Meshery Server. |
Current releases treat a Meshery Server running inside any Kubernetes cluster as in-cluster, so a Server that manages a different cluster skips the port-forward too - see the known issue under Out-of-Cluster Deployment.
When disabled, Meshery falls back to the resolved Broker endpoint (and
127.0.0.1 / host.docker.internal on the Broker port), so you can provide your
own path, for example:
kubectl port-forward -n meshery svc/meshery-nats 4222:4222
Diagnostics
Click a Kubernetes connection’s row in the Connections table to open its detail view. Alongside the Operator / MeshSync / Broker status chips, a Diagnostics section reports actionable problems and remediation, computed from the live controller status and Meshery’s actual Broker connection. The codes it reports:
| Code | Meaning | What to do |
|---|---|---|
connection_inactive | No active session for the connection yet. | Connect the cluster. |
operator_deploy_failed | Meshery tried to deploy the Operator and could not; the underlying cause is carried in the diagnostic. | Read the cause. An unreadable kubeconfig or missing permissions in the meshery namespace need fixing first; an unresolvable chart version means the requested operator.version is not published, or the chart repository was unreachable. Redeploying the Operator re-resolves the version, so a transient repository outage clears on retry. |
operator_not_deployed | The Operator isn’t deployed (operator mode). | Reconnect the cluster, or switch MeshSync mode; ensure Meshery can create resources in the meshery namespace. |
broker_unreachable | The Broker is up but Meshery can’t reach/authenticate to it. | Make the Broker reachable (the managed port-forward normally handles this; otherwise port-forward it, expose it via NodePort/LoadBalancer, or run Meshery in that cluster). |
broker_networking | Informational: how Meshery reaches the Broker - managed port-forward, in-cluster ClusterIP, or a direct endpoint - and the address in use. | Nothing to fix; it reports the transport behind a Broker that Meshery can see. |
The same diagnostics are available programmatically at
GET /api/system/controllers/diagnostics?connectionId=<id>.
Operating a connection
From the connection in Meshery UI you can:
- Switch MeshSync mode (operator โ embedded) - see MeshSync deployment modes.
- (Re)deploy Operator / MeshSync / Broker. Uninstalling is cluster-wide and explicit - see One Operator per cluster.
- Reconnect Meshery Server to the Broker, or run an ad-hoc connectivity test.
- Rediscover / re-upload the kubeconfig, or disconnect / delete the connection (which also tears down the managed port-forward and MeshSync data handler, and leaves the cluster’s Operator installed).
- Reset the Meshery Database if the cached cluster state looks stale.
Known kinks
- NATS pod in
CrashLoopBackOffright after deploy. Some Meshery Operator versions inject the NATS token intonats.confunquoted (token: $NATS_TOKEN). When the randomly-generated token happens to look like a number (e.g. starts with digits and contains ane), the NATS config parser rejects it and the pod crash-loops, so the Broker never becomes ready. Check withkubectl logs -n meshery meshery-nats-0 -c nats; the fix belongs in the operator (quote it:token: "$NATS_TOKEN"). Redeploying often generates a token that parses. - “MeshSync running but not connected to Broker.” Almost always a Broker
reachability or authentication problem for a Meshery running outside the
connection’s cluster - see Broker connectivity. The
Diagnostics section will say
broker_unreachablewith remediation.