Running a drupal site using Minikube

1/12/2021

I'm learning how to use Kubernetes by using Minikube and creating a Drupal site.

I was able to minikube service my drupal site and reach up to the "Set up Database" page and that's about it. It keeps telling me I need to insert the correct info. I checked my MYSQL pod and was able to exec and MySQL into my database.

I'm not sure what I'm missing? Is MYSQL pod not connected to my Drupal pod?

Here's my drupal-mysql.yaml file:

<!-- begin snippet: js hide: false console: true babel: false --><!-- language: lang-html -->
---
apiVersion: v1
kind: Service
metadata:
  name: drupal-mysql-service
spec:
  ports:
    - name: mysql
      port: 3306
      targetPort: 3306
      protocol: TCP
  selector:
    app: drupal
  type: ClusterIP
---
apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
  name: drupal-mysql
spec:
  selector:
    matchLabels:
      app: mysql
  template:
    metadata:
      labels:
        app: mysql
    spec:
      containers:
        - image: mysql:5.7
          name: mysql
          env:
            # Use secret in real usage
            - name: MYSQL_ROOT_PASSWORD
              value: seto_password
            - name: MYSQL_DATABASE
              value: drupal_databases
          ports:
            - containerPort: 3306
              name: mysql
              protocol: TCP
          volumeMounts:
            - name: vol-drupal
              mountPath: /var/lib/mysql
              subPath: 'mysql'
      volumes:
        - name: vol-drupal
          persistentVolumeClaim:
            claimName: drupal-seto-mysql
<!-- end snippet -->

Here's my drupal.yaml file:

<!-- begin snippet: js hide: false console: true babel: false --><!-- language: lang-html -->
apiVersion: apps/v1
kind: Deployment
metadata:
  name: drupal
  labels:
    app: drupal
spec:
  selector:
    matchLabels:
      app: drupal
      tier: frontend
  strategy:
    type: Recreate
  replicas: 1
  template:
    metadata:
      labels:
        app: drupal
        tier: frontend
    spec:
      selector:
      initContainers:
        - name: init-sites-volume
          image: drupal:8.9.11
          command: ['/bin/bash', '-c']
          args:
            [
              'cp -r /var/www/html/sites/ /data/; chown www-data:www-data /data/ -R',
            ]
          volumeMounts:
            - mountPath: /data
              name: vol-drupal
      containers:
        - image: drupal:8.9.11
          name: drupal
          ports:
            - containerPort: 80
          volumeMounts:
            - mountPath: /var/www/html/modules
              name: vol-drupal
              subPath: modules
            - mountPath: /var/www/html/profiles
              name: vol-drupal
              subPath: profiles
            - mountPath: /var/www/html/sites
              name: vol-drupal
              subPath: sites
            - mountPath: /var/www/html/themes
              name: vol-drupal
              subPath: themes
      volumes:
        - name: vol-drupal
          persistentVolumeClaim:
            claimName: drupal-seto
<!-- end snippet -->

And Here's my drupal-service.yaml:

<!-- begin snippet: js hide: false console: true babel: false --><!-- language: lang-html -->
apiVersion: v1
kind: Service
metadata:
  name: drupal-service
  labels:
    app: drupal
spec:
  type: NodePort
  ports:
    - name: web
      protocol: TCP
      port: 80
      targetPort: 80
  selector:
    app: drupal
<!-- end snippet -->
-- MetalBearSolid
drupal
drupal-8
kubernetes
minikube

1 Answer

7/7/2021

You need to connect between containers using IP address of containers or may be pods, but what is point of getting database in container, instead install mysql in host machine I have done it, checkout the guide

https://www.youtube.com/watch?v=7Y4RJrk-cFw

-- Karthikeyan Manivasagam
Source: StackOverflow