Unable to use HTTP with php image on Kubernetes

10/31/2019

I'm currently in the process of dockerizing a Laravel app and integrating it with Kubernetes. I'm not well-versed in php, so I could be missing something obvious. I managed to access the app with http through the browser running it via docker.

But for some reason whenever I access it through my Kubernetes cluster, regardless of if I type the URL manually, it redirects me to the https version of the URL. And this throws several Mixed Content: The page at '<URL>' was loaded over HTTPS, but requested an insecure script '<URL>' errors.

I've tried configuring Apache to use self-signed SSL, but I was unable to get it to work, and the cluster does seem to work on http with Angular apps anyway.

My Dockerfile, Kubernetes config files and apache.conf files look like this:

(Note that I removed env values for security and brevity)

Dockerfile

FROM php:7.2-apache
ENV APP_ENV=prod
ENV APACHE_DOCUMENT_ROOT /var/www/html

RUN docker-php-ext-install pdo pdo_mysql
RUN a2enmod rewrite
COPY ./apache.conf /etc/apache2/sites-available/000-default.conf
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"

WORKDIR /var/www/html/my-app
COPY . .
RUN apt-get update && apt-get install -y git zip unzip
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/bin --filename=composer
RUN /bin/composer install

apache.conf

<VirtualHost *:80>
    RewriteEngine On
    DocumentRoot ${APACHE_DOCUMENT_ROOT}

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    Alias /my-app "/var/www/html/my-app/public"
    <Directory "/var/www/html/my-app">
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>

</VirtualHost>

k8s config files

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-app-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: my-app
  template:
    metadata:
      labels:
        app: my-app
    spec:
      containers:
      - name: in-check
        image: registry-url:5000/my-app
        ports:
          - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: my-app-cluster-ip
spec:
  type: ClusterIP
  selector:
    app: my-app
  ports:
  - port: 8082
    targetPort: 80
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: my-app-ingress-service
  annotations:
    kubernetes.io/ingress.class: nginx
spec:
  rules:
    - http:
        paths:
          - path: /my-app/?(.*)
            backend:
              serviceName: my-app-cluster-ip
              servicePort: 8082

Any idea what might be causing this issue?

Any and all help is appreciated.

Update: it seems to load properly using http on my EKS cluster, but still results in the above errors on my copy of minikube.

Edit: here's the link to the Ingress controller config I'm using.

-- Xelron
apache
docker
kubernetes
php

1 Answer

11/1/2019

So I was unable to get the app to run on HTTP on my local copy of minikube, but after @Eduardo Baitello's advice, I changed all the resources' relative paths to full URLs with the HTTPS protocol included.

This isn't ideal since if the domain name or IP changes I have to manually update all resource URLs, but this is the only workaround I can find right now.

-- Xelron
Source: StackOverflow