You are looking at the documentation of a prior release. To read the documentation of the latest release, please
visit here.
We use cookies and other similar technology to collect data to improve your experience on our site, as described in our Privacy Policy.
Run Production-Grade Databases on Kubernetes
Backup and Recovery Solution for Kubernetes
Run Production-Grade Vault on Kubernetes
Secure HAProxy Ingress Controller for Kubernetes
Kubernetes Configuration Syncer
Kubernetes Authentication WebHook Server
KubeDB simplifies Provision, Upgrade, Scaling, Volume Expansion, Monitor, Backup, Restore for various Databases in Kubernetes on any Public & Private Cloud
A complete Kubernetes native disaster recovery solution for backup and restore your volumes and databases in Kubernetes on any public and private clouds.
KubeVault is a Git-Ops ready, production-grade solution for deploying and configuring Hashicorp's Vault on Kubernetes.
Secure HAProxy Ingress Controller for Kubernetes
Kubernetes Configuration Syncer
Kubernetes Authentication WebHook Server
New to KubeDB? Please start here.
KubeDB operator supports using private Docker registry. This tutorial will show you how to use KubeDB to run MySQL database using private Docker images.
At first, 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 Minikube.
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 the following images to your private registry.
$ export DOCKER_REGISTRY=<your-registry>
$ docker pull kubedb/operator:0.8.0 ; docker tag kubedb/operator:0.8.0 $DOCKER_REGISTRY/operator:0.8.0 ; docker push $DOCKER_REGISTRY/operator:0.8.0
$ docker pull kubedb/mysql:8.0 ; docker tag kubedb/mysql:8.0 $DOCKER_REGISTRY/mysql:8.0 ; docker push $DOCKER_REGISTRY/mysql:8.0
$ docker pull kubedb/mysql-tools:8.0 ; docker tag kubedb/mysql-tools:8.0 $DOCKER_REGISTRY/mysql-tools:8.0 ; docker push $DOCKER_REGISTRY/mysql-tools:8.0
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 myregistrykey \
--docker-server=DOCKER_REGISTRY_SERVER \
--docker-username=DOCKER_USER \
--docker-email=DOCKER_EMAIL \
--docker-password=DOCKER_PASSWORD
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.
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.
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
$ kubectl get ns
NAME STATUS AGE
default Active 45m
demo Active 10s
kube-public Active 45m
kube-system Active 45m
While deploying MySQL
from private repository, you have to add myregistrykey
secret in MySQL
spec.imagePullSecrets
.
Below is the MySQL CRD object we will create.
apiVersion: kubedb.com/v1alpha1
kind: MySQL
metadata:
name: mysql-pvt-reg
namespace: demo
spec:
version: "8.0"
doNotPause: true
storage:
storageClassName: "standard"
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 50Mi
imagePullSecrets:
- name: myregistrykey
Now run the command to deploy this MySQL
object:
$ kubedb create -f https://raw.githubusercontent.com/kubedb/cli/0.8.0/docs/examples/mysql/private-registry/demo-2.yaml
mysql "mysql-pvt-reg" created
To check if the images pulled successfully from the repository, see if the MySQL
is in running state:
$ kubectl get pods -n demo -w
NAME READY STATUS RESTARTS AGE
mysql-pvt-reg-0 0/1 Pending 0 0s
mysql-pvt-reg-0 0/1 Pending 0 0s
mysql-pvt-reg-0 0/1 ContainerCreating 0 1s
mysql-pvt-reg-0 1/1 Running 0 8s
$ kubedb get my -n demo
NAME STATUS AGE
mysql-pvt-reg Running 26s
We don’t need to add imagePullSecret
for snapshot
objects.
Just create snapshot object and KubeDB operator will reuse the ImagePullSecret
from MySQL
object.
To cleanup the Kubernetes resources created by this tutorial, run:
$ kubectl patch -n demo mysql/mysql-pvt-reg -p '{"spec":{"doNotPause":false}}' --type="merge"
$ kubectl delete -n demo mysql/mysql-pvt-reg
$ kubectl patch -n demo drmn/mysql-pvt-reg -p '{"spec":{"wipeOut":true}}' --type="merge"
$ kubectl delete -n demo drmn/mysql-pvt-reg
$ kubectl delete ns demo
namespace "demo" deleted