Use local docker image having mysql with minikube

10/17/2018

On my laptop, I have Linux Mint OS. Details as below:

Mint version 19, 
Code name : Tara,
PackageBase : Ubuntu Bionic
Cinnamon (64-bit)
  1. I have webservice written using spring boot and mysql.

  2. It works fine locally.- verified and tested... Using dockerfile I have created docker image. From the directory of Dockerfile ran command- docker build . -t users-mysql-docker

Run the Docker image (users-mysql-docker) created. docker run -p 8086:8086 --name users-mysql-app --link mysql-standalone:mysql -d users-mysql-docker (In this command we sort of link our own image with standalone mysql.)

I already have mysql image in docker and container mysql-standalone.

  1. I started minikube and checked pods and deployments
xxxxxxxxx:~$ pwd
/home/sj
xxxxxxxxxx:~$ minikube start
xxxxxxxxxx:~$ kubectl get pods
xxxxxxxxxx:~$ kubectl get deployments
xxxxxxxxxx:~$ eval $(minikube docker-env)

Now when I check docker images, looks like as the README describes, it reuses the Docker daemon from Minikube with eval $(minikube docker-env).

  1. As per this link I did setup mysql on minikube. with that what I see in pods, deployments and services
xxxxxxxxxx:~$ kubectl get pods
NAME                         READY   STATUS    RESTARTS   AGE
mysql-6c57cd4d76-gxb7g       1/1     Running   1          9d

xxxxxxxxxx:~$ kubectl get deployments
NAME        DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
mysql       1         1         1            1           8d

xxxxxxxxxx:~$ kubectl get services
NAME         TYPE           CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
kubernetes   ClusterIP      10.96.0.1        <none>        443/TCP          9d
mysql        ClusterIP      None             <none>        3306/TCP         8d
  1. Now I want to deploy the same webservice from step# 1 to kubernetes(minikube). I went to directory where I have dockerfile and ran build command as below:

xxxxxxxxx:/directory$ docker build . -t users-mysql-kube:V1

Verified if I can see image in deamon docker within minikube.

xxxxxxxxxx:~$ docker images
REPOSITORY                                 TAG                 IMAGE ID            CREATED             SIZE
users-mysql-kube                           V1                  53152583b2b8        2 seconds ago       652MB
openjdk                                    8                   81f83aac57d6        5 weeks ago         624MB
mysql                                      5.7                 563a026a1511        5 weeks ago         372MB
k8s.gcr.io/coredns                         1.2.2               367cdc8433a4        6 weeks ago         39.2MB
k8s.gcr.io/kubernetes-dashboard-amd64      v1.10.0             0dab2435c100        7 weeks ago         122MB
k8s.gcr.io/kube-proxy-amd64                v1.10.0             bfc21aadc7d3        6 months ago        97MB
k8s.gcr.io/kube-apiserver-amd64            v1.10.0             af20925d51a3        6 months ago        225MB
k8s.gcr.io/kube-scheduler-amd64            v1.10.0             704ba848e69a        6 months ago        50.4MB
k8s.gcr.io/kube-controller-manager-amd64   v1.10.0             ad86dbed1555        6 months ago        148MB
k8s.gcr.io/etcd-amd64                      3.1.12              52920ad46f5b        7 months ago        193MB
k8s.gcr.io/kube-addon-manager              v8.6                9c16409588eb        7 months ago        78.4MB
k8s.gcr.io/k8s-dns-dnsmasq-nanny-amd64     1.14.8              c2ce1ffb51ed        9 months ago        41MB
k8s.gcr.io/k8s-dns-sidecar-amd64           1.14.8              6f7f2dc7fab5        9 months ago        42.2MB
k8s.gcr.io/k8s-dns-kube-dns-amd64          1.14.8              80cc5ea4b547        9 months ago        50.5MB
k8s.gcr.io/pause-amd64                     3.1                 da86e6ba6ca1        9 months ago        742kB
gcr.io/k8s-minikube/storage-provisioner    v1.8.1              4689081edb10        11 months ago       80.8MB

Below steps I tried just as TESTING PURPOSE. I may be wrong. Please provide your suggestions on that

  1. As mentioned in step# 2 the way I run docker image and link it to mysql, how do we run created image in step# 5 inside minikube and link it to deployed mysql? Is it something like:
xxxxxxxxxxx:~$ kubectl run umk-01 --image=users-mysql-kube:V1 --image-pull-policy=Never
  1. after image is deployed, how to expose it? should I do something like:
xxxxxxxxxxxxx:~$ kubectl expose deployment umk-01 --type=NodePort --port=8086

xxxxxxxxxxxxx:~$ kubectl get services
NAME         TYPE           CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
kubernetes   ClusterIP      10.96.0.1        <none>        443/TCP          9d
mysql        ClusterIP      None             <none>        3306/TCP         8d
umk-01       NodePort       10.100.105.58    <none>        8086:30004/TCP   6s
  1. I have tried step 6 and 7 and then tried below command but it didn't work.
xxxxxxxxxxxxx:~$ minikube service umk-01 --url
Waiting, endpoint for service is not ready yet...

It means something is wrong there in step#6 and 7 . Can someone help with that?

-- Shivraj
docker
kubernetes
linux-mint
minikube
mysql

1 Answer

10/17/2018

I am not sure if you get a service URL for nodeport service with Minikube. You can directly access the service on Minikube IP & port 30004. Just make sure you dont have firewall blocking the port.

-- coolsvap
Source: StackOverflow