Laravel and Kubernetes 8 on Minikube

Working locally in Minikube on https://github.com/Larastudio/laravel-k8 for testing purposes before I move it to Digital Ocean. It is based on a repo by Eamon and what it does is get Laravel up and running with two Docker images and several Helm packages (mysql, cert manager, redis). Been really hard getting into this all so I am getting stuck often.

Cluster information:

Kubernetes version: 1.15.5
Installation method: Mac Installer and current version 2.2.0.0
Host OS: MacOs Catalina
CNI and version: no idea
CRI and version: no idea

Pods in use

Pods I have up and running so far:

kubectl get pod --all-namespaces                                   
NAMESPACE     NAME                                             READY   STATUS    RESTARTS   AGE
kube-system   coredns-6955765f44-9k4nn                         1/1     Running   3          23h
kube-system   coredns-6955765f44-zp2qr                         1/1     Running   3          23h
kube-system   etcd-minikube                                    1/1     Running   3          23h
kube-system   kube-addon-manager-minikube                      1/1     Running   3          23h
kube-system   kube-apiserver-minikube                          1/1     Running   3          23h
kube-system   kube-controller-manager-minikube                 1/1     Running   3          23h
kube-system   kube-proxy-qrzc5                                 1/1     Running   3          23h
kube-system   kube-scheduler-minikube                          1/1     Running   3          23h
kube-system   storage-provisioner                              1/1     Running   4          23h
laravel6      cert-manager-7974f4ddf4-gkz58                    1/1     Running   1          20h
laravel6      cert-manager-cainjector-76f7596c4-v8n6c          1/1     Running   2          20h
laravel6      cert-manager-webhook-8575f88c85-j2sdm            1/1     Running   1          20h
laravel6      nginx-ingress-controller-69d5dc598f-zfpwd        1/1     Running   2          21h
laravel6      nginx-ingress-default-backend-659bd647bd-568kb   1/1     Running   1          21h

Connect to Cluster admin

When I check the cluster I see the ip address I am supposed to use. And I was looking this up because I want to make my Nginx Ingress work and then later on hopefully test Cert Manager as well.

kubernetes master is running at https://192.168.64.3:8443
KubeDNS is running at https://192.168.64.3:8443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.

When I go there I only see 403 data:

{
  "kind": "Status",
  "apiVersion": "v1",
  "metadata": {
    
  },
  "status": "Failure",
  "message": "forbidden: User \"system:anonymous\" cannot get path \"/\"",
  "reason": "Forbidden",
  "details": {
    
  },
  "code": 403
}

Why is that?

Nginx Ingress local domain

Two, how can one attach a local domain to a Nginx Ingress locally using Minikube? In Laravel Valet this is all done out of the box and using dnsmasq, but in this case I have to do it myself of course. But some pointers how would be nice.

Probably you have already solved this by now. But if not, here are some thoughts.

In order to deploy a pre-built application like Laravel on K8S with Ingress + Cert Manager you need following:

  • Connect the IP of the Service with Ingress
  • Apply the annotation that is needed by CertManager on Ingress
  • Create appropriate CertManager resources to get a SSL cert
  • For Minikube, use Service type of NodePort and then update your /etc/hosts file on your host to include the path that you define in Ingress with a pointer to the minikube IP + port from NodePort.

Here are some references that might be helpful. These are from our work on setting up multi-tenant Moodle environments on Kubernetes.

Thanks @devkulkarni . Went through the Medium article and checked out the repository with Moodle / K8 code. The latter may help us with the Cert Manager setup though a more complete example with the actual app and other needed containers would have been welcome. Perhaps an idea for a future article including repo?

We have made progress since this post. We are running things locally with multiple images. We do now have a setup working on Minikube using a local domain hitting:

  • Ingress Nginx connected via a
  • Nginx service to our web pod with
  • Nginx container working with our
  • Laravel PHP FPM container with database containers:
  • MySQL Redis containers *
  • On DigitalOcean we will most likely go for managed database setups

The code for Larakube can be located here.
We do not have Cert Manager configured yet and we may need a NodePort for that after all. At least for the Minikube setup. Not sure yet. Other issue is that we are trying to have Laravel send request for new SSL certificates to the Cert Manager, but we have found a possible PHP package for that.

It is a whole New Brave World out there and lots to learn. I appreciate your feedback a lot. Thank you!