Bug #108205 MySQL Operator: MySQL Router Pod Does not executing
Submitted: 20 Aug 2022 16:38 Modified: 22 Aug 2022 16:48
Reporter: test item Email Updates:
Status: Can't repeat Impact on me:
None 
Category:MySQL Operator Severity:S1 (Critical)
Version:8.0.30-2.05 OS:Any
Assigned to: MySQL Verification Team CPU Architecture:Any
Tags: MySQL Operator

[20 Aug 2022 16:38] test item
Description:
Hello,

I tried to install 3 InnoDB Pods and 1 MySQL Router from this link: https://dev.mysql.com/doc/mysql-operator/en/mysql-operator-installation-kubectl.html but it seems that MySQL Router does not execute.

How to repeat:
NAMESPACE        NAME                                      READY   STATUS             RESTARTS        AGE
default          mycluster-0                               2/2     Running            0               10m
default          mycluster-1                               2/2     Running            0               10m
default          mycluster-2                               2/2     Running            0               1
[22 Aug 2022 16:24] MySQL Verification Team
Hi,

I cannot reproduce this. Following the manual works ok with me. 

For help on how to setup please contact MySQL Support team or you can try for free to get help on https://forums.mysql.com/ but bugs system is no place for support.

Thank you for your interest in MySQL
[22 Aug 2022 16:48] test item
I follow all the steps on the manual but it seems that MySQL Router is not showing up. I set the number of instances for MySQL Router into 1 but when I check the number of pods deployed by the deployment it seems that the result is 0/0.

apiVersion: mysql.oracle.com/v2
kind: InnoDBCluster
metadata:
  name: mycluster
spec:
  secretName: mypwds
  tlsUseSelfSigned: true
  instances: 3
  router:
    instances: 1

NAMESPACE        NAME                                      READY   UP-TO-DATE   AVAILABLE   AGE
default          deployment.apps/mycluster-router          0/0     1            0           2d

NAMESPACE        NAME                                                DESIRED   CURRENT   READY   AGE
default          replicaset.apps/mycluster-router-dsb5ddfjy9         0         0         0       11h

NAMESPACE   NAME                         READY   AGE
default     statefulset.apps/mycluster   0/3     2d
[20 Oct 2022 1:26] Nate Kush
Hello there, any updates so far? 
I came across the same issue recently, ie. mysql router not running so that mysql cluster cannot be accessed.
[29 Dec 2022 2:23] jigao zuo
i found the 8.0.31 bug reason, you should look at the operator log. 

i my cluster,it shows:

[2022-12-27 13:48:33,520] kopf.objects         [INFO    ]   Server.TLS.useSelfSigned:   True
1. Initial Configuration ConfigMap and Container Probes
2. Cluster Accounts
3. Router Accounts
4. Cluster Service
5. Cluster ServiceAccount
6. Cluster RoleBinding
7. Cluster StatefulSet
8. Cluster PodDisruptionBudget
    Preparing...
    Creating...
[2022-12-27 13:48:33,546] kopf.objects         [ERROR   ] Handler 'on_innodbcluster_create' failed with an exception. Will retry.
Traceback (most recent call last):
  File "/usr/lib/mysqlsh/python-packages/kopf/_core/actions/execution.py", line 279, in execute_handler_once
    result = await invoke_handler(
  File "/usr/lib/mysqlsh/python-packages/kopf/_core/actions/execution.py", line 374, in invoke_handler
    result = await invocation.invoke(
  File "/usr/lib/mysqlsh/python-packages/kopf/_core/actions/invocation.py", line 139, in invoke
    await asyncio.shield(future)  # slightly expensive: creates tasks
  File "/usr/lib64/python3.9/concurrent/futures/thread.py", line 52, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/lib/mysqlsh/python-packages/mysqloperator/controller/innodbcluster/operator_cluster.py", line 163, in on_innodbcluster_create
    api_policy.create_namespaced_pod_disruption_budget(namespace=namespace, body=disruption_budget)
  File "/usr/lib/mysqlsh/python-packages/kubernetes/client/api/policy_v1_api.py", line 67, in create_namespaced_pod_disruption_budget
    return self.create_namespaced_pod_disruption_budget_with_http_info(namespace, body, **kwargs)  # noqa: E501
  File "/usr/lib/mysqlsh/python-packages/kubernetes/client/api/policy_v1_api.py", line 166, in create_namespaced_pod_disruption_budget_with_http_info
    return self.api_client.call_api(
  File "/usr/lib/mysqlsh/python-packages/kubernetes/client/api_client.py", line 348, in call_api
    return self.__call_api(resource_path, method,
  File "/usr/lib/mysqlsh/python-packages/kubernetes/client/api_client.py", line 180, in __call_api

so we can see the "PodDisruptionBudget" createing is failed, so we can see the operator source code:
def prepare_cluster_pod_disruption_budget(spec: InnoDBClusterSpec) -> dict:
    tmpl = f"""
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
  name: {spec.name}-pdb
spec:
  maxUnavailable: 1
  selector:
    matchLabels:
      component: mysqld
      tier: mysql
      mysql.oracle.com/cluster: {spec.name}
"""
the apiVersion is "policy/v1", my k8s cluster version is v1.18,it does not support "policy/v1", then i found in operator 8.0.30, the source code is : 
apiVersion: policy/v1beta1
kind: PodDisruptionBudget
metadata:
  name: {spec.name}-pdb
spec:
  maxUnavailable: 1
  selector:
    matchLabels:
      component: mysqld
      tier: mysql
      mysql.oracle.com/cluster: {spec.name}
"""

apiVersion is "policy/v1beta1", this is supported by k8s v1.18, then i tried operator version 8.0.30, the PodDisruptionBudget is created successfull, then the router also successfully created.

so if you use k8s version < v1.21, you should use operator version 8.0.30, and if you want to check the deploy errors, you should see the operator log:

kubectl logs pod/mysql-operator-c78fddd58-sgsq9 -n mysql-operator