MySQL Operator for Kubernetes Manual  /  MySQL InnoDB Cluster  /  MySQL InnoDB Cluster Service Explanation

3.4 MySQL InnoDB Cluster Service Explanation

For connecting to the InnoDB Cluster, a Service is created inside the Kubernetes cluster. The exported ports represent read-write and read-only ports for both the MySQL Protocol and X Protocol.

$> kubectl describe service mycluster

Output looks similar to this:

Name:              mycluster
Namespace:         default
Annotations:       <none>
Selector:          component=mysqlrouter,,tier=mysql
Type:              ClusterIP
IP Family Policy:  SingleStack
IP Families:       IPv4
Port:              mysql  3306/TCP
TargetPort:        6446/TCP
Port:              mysqlx  33060/TCP
TargetPort:        6448/TCP
Port:              mysql-alternate  6446/TCP
TargetPort:        6446/TCP
Port:              mysqlx-alternate  6448/TCP
TargetPort:        6448/TCP
Port:              mysql-ro  6447/TCP
TargetPort:        6447/TCP
Port:              mysqlx-ro  6449/TCP
TargetPort:        6449/TCP
Port:              router-rest  8443/TCP
TargetPort:        8443/TCP
Session Affinity:  None
Events:            <none>

An alternative view showing services named mycluster and mycluster-instances:

$> kubectl get service

Output looks similar to this:

NAMESPACE     NAME                  TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                                                  AGE
default       kubernetes            ClusterIP        <none>        443/TCP                                                  2d1h
default       mycluster             ClusterIP   <none>        3306/TCP,33060/TCP,6446/TCP,6448/TCP,6447/TCP,6449/TCP   2d
default       mycluster-instances   ClusterIP   None             <none>        3306/TCP,33060/TCP,33061/TCP                             2d

The long host name used to connect to an InnoDB Cluster from within a Kubernetes cluster is {innodbclustername}.{namespace}.svc.cluster.local, which routes to the current primary/replica using MySQL Router, depending on the port. Acceptable host name forms:


Using these names goes to the Kubernetes LoadBalancer (part of Kubernetes Service), which redirects to MySQL Router. MySQL Router then talks to the individual server based on the role, such as PRIMARY or SECONDARY.

For example, assuming 'mycluster' as the InnoDB Cluster name in the 'default' namespace:


Using only {innodbclustername} as the host name assumes the session's context is either the default namespace or set accordingly. Alternatively you may use the clusterIP instead of a host name; here's an example that retrieves it:

$> kubectl get service/mycluster -o jsonpath='{.spec.clusterIP}'

See also Chapter 5, Connecting to MySQL InnoDB Cluster.