You are looking at the documentation of a prior release. To read the documentation of the latest release, please visit here.

New to KubeDB? Please start here.

Deploy MariaDB from private Docker registry

KubeDB operator supports using private Docker registry. This tutorial will show you how to use KubeDB to run MariaDB database using private Docker images.

Before You Begin

  • Read concept of MariaDB Version Catalog to learn detail concepts of MariaDBVersion object.

  • You need to have a Kubernetes cluster, and the kubectl command-line tool must be configured to communicate with your cluster. If you do not already have a cluster, you can create one by using kind.

  • You will also need a docker private registry or private repository. In this tutorial we will use private repository of docker hub.

  • You have to push the required images from KubeDB’s Docker hub account into your private registry. For mysql, push DB_IMAGE, EXPORTER_IMAGE, INITCONTAINER_IMAGE of following MariaDBVersions, where deprecated is not true, to your private registry.

$ kubectl get mariadbversions -n kube-system,VERSION:.spec.version,DB_IMAGE:.spec.db.image,EXPORTER_IMAGE:.spec.exporter.image,INITCONTAINER_IMAGE:.spec.initContainer.image,DEPRECATED:.spec.deprecated
10.4.17   10.4.17   kubedb/mariadb:10.4.17   kubedb/mysqld-exporter:v0.11.0   kubedb/busybox        <none>
10.5.8    10.5.8    kubedb/mariadb:10.5.8    kubedb/mysqld-exporter:v0.11.0   kubedb/busybox        <none>

Docker hub repositories:

  • kubedb/operator

  • kubedb/mariadb

  • kubedb/mysqld-exporter

  • Update KubeDB catalog for private Docker registry. Ex:

    kind: MariaDBVersion
      name: 10.5.8
        image: PRIVATE_REGISTRY/mysql:10.5.8
        image: PRIVATE_REGISTRY/mysqld-exporter:v0.11.0
        image: PRIVATE_REGISTRY/busybox
        databasePolicyName: maria-db
      version: 10.5.8
  • To keep things isolated, this tutorial uses a separate namespace called demo throughout this tutorial. Run the following command to prepare your cluster for this tutorial:

    $ kubectl create ns demo
    namespace/demo created

Create ImagePullSecret

ImagePullSecrets is a type of a Kubernete Secret whose sole purpose is to pull private images from a Docker registry. It allows you to specify the url of the docker registry, credentials for logging in and the image name of your private docker image.

Run the following command, substituting the appropriate uppercase values to create an image pull secret for your private Docker registry:

$ kubectl create secret docker-registry -n demo myregistrykey \
  --docker-server=DOCKER_REGISTRY_SERVER \
  --docker-username=DOCKER_USER \
  --docker-email=DOCKER_EMAIL \
secret/myregistrykey created

If you wish to follow other ways to pull private images see official docs of kubernetes.

NB: If you are using kubectl 1.9.0, update to 1.9.1 or later to avoid this issue.

Install KubeDB operator

When installing KubeDB operator, set the flags --docker-registry and --image-pull-secret to appropriate value. Follow the steps to install KubeDB operator properly in cluster so that to points to the DOCKER_REGISTRY you wish to pull images from.

Deploy MariaDB database from Private Registry

While deploying MariaDB from private repository, you have to add myregistrykey secret in MariaDB spec.imagePullSecrets. Below is the MariaDB CRD object we will create.

kind: MariaDB
  name: md-pvt-reg
  namespace: demo
  version: "10.5.8"
    storageClassName: "standard"
    - ReadWriteOnce
        storage: 1Gi
      - name: myregistrykey
  terminationPolicy: WipeOut

Now run the command to deploy this MariaDB object:

$ kubectl apply -f created

To check if the images pulled successfully from the repository, see if the MariaDB is in running state:

$ kubectl get pods -n demo
NAME              READY     STATUS    RESTARTS   AGE
md-pvt-reg-0   1/1       Running   0          56s

Cleaning up

To cleanup the Kubernetes resources created by this tutorial, run:

$ kubectl delete mariadb -n demo md-pvt-reg "md-pvt-reg" deleted
$ kubectl delete ns demo
namespace "demo" deleted