Incorrect validation "Deploy Lamp Stack on Kubernetes Cluster"

I have followed the following steps:

  1. Create secret
kubectl create secret generic db-secret --from-literal=MYSQL_ROOT_PASSWORD=nbtech --from-literal=MYSQL_DATABASE=kodekloud --from-literal=MYSQL_USER=nbtechsupport --from-literal=MYSQL_PASSWORD=nbtech --from-literal=MYSQL_HOST=mysql-service
  1. Write ConfigMap’s manifests and apply
apiVersion: v1
kind: ConfigMap
metadata:
  name: php-config
data:
  php.ini: |
    variables_order = "EGPCS"

---

apiVersion: v1
kind: ConfigMap
metadata:
  name: php-index
data:
  index.php: |
    <?php
    $dbname = $_ENV["MYSQL_DATABASE"];
    $dbuser = $_ENV["MYSQL_USER"];
    $dbpass = $_ENV["MYSQL_PASSWORD"];
    $dbhost = $_ENV["MYSQL_HOST"];

    $connect = mysqli_connect($dbhost, $dbuser, $dbpass) or die("Unable to Connect to '$dbhost'");

    $test_query = "SHOW TABLES FROM $dbname";
    $result = mysqli_query($test_query);

    if ($result->connect_error) {
       die("Connection failed: " . $conn->connect_error);
    }
      echo "Connected successfully";
  1. Write deployment with services and apply
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: lamp-wp
  name: lamp-wp
spec:
  replicas: 1
  selector:
    matchLabels:
      app: lamp-wp
  template:
    metadata:
      labels:
        app: lamp-wp
    spec:
      containers:
      - name: mysql-container
        image: mysql:5.6
        env:
          - name: MYSQL_ROOT_PASSWORD
            valueFrom:
              secretKeyRef:
                name: db-secret
                key: MYSQL_ROOT_PASSWORD
          - name: MYSQL_DATABASE
            valueFrom:
              secretKeyRef:
                name: db-secret
                key: MYSQL_DATABASE
          - name: MYSQL_USER
            valueFrom:
              secretKeyRef:
                name: db-secret
                key: MYSQL_USER
          - name: MYSQL_PASSWORD
            valueFrom:
              secretKeyRef:
                name: db-secret
                key: MYSQL_PASSWORD
          - name: MYSQL_HOST
            valueFrom:
              secretKeyRef:
                name: db-secret
                key: MYSQL_HOST
      - name: httpd-php-container
        image: webdevops/php-apache:alpine-3-php7
        env:
          - name: MYSQL_ROOT_PASSWORD
            valueFrom:
              secretKeyRef:
                name: db-secret
                key: MYSQL_ROOT_PASSWORD
          - name: MYSQL_DATABASE
            valueFrom:
              secretKeyRef:
                name: db-secret
                key: MYSQL_DATABASE
          - name: MYSQL_USER
            valueFrom:
              secretKeyRef:
                name: db-secret
                key: MYSQL_USER
          - name: MYSQL_PASSWORD
            valueFrom:
              secretKeyRef:
                name: db-secret
                key: MYSQL_PASSWORD
          - name: MYSQL_HOST
            valueFrom:
              secretKeyRef:
                name: db-secret
                key: MYSQL_HOST
        volumeMounts:
          - mountPath: /opt/docker/etc/php/php.ini
            name: php-config
            subPath: php.ini
          - mountPath: /app/index.php
            name: php-index
            subPath: index.php
      volumes:
        - name: php-config
          configMap:
            name: php-config
            items:
              - key: php.ini
                path: php.ini
        - name: php-index
          configMap:
            name: php-index
            items:
              - key: index.php
                path: index.php

---

apiVersion: v1
kind: Service
metadata:
  name: lamp-service
spec:
  type: NodePort
  ports:
    - port: 80
      targetPort: 80
      nodePort: 30008
  selector:
    app: lamp-wp

---

apiVersion: v1
kind: Service
metadata:
  name: mysql-service
spec:
  ports:
    - port: 3306
      targetPort: 3306
  selector:
    app: lamp-wp

Website provided information that the connection successful, but the check failed.
Returned error messages:

Mysql database is hardcoded in ‘index.php’
Mysql user is hard coded in ‘index.php’
Mysql password is hard coded in ‘index.php’
Mysql HOST is hard coded in ‘index.php’

website is not up and accessible

Please help me.

Hi @blossomdude

That could be because you need to fetch the env variables in the php-index configMap using getenv('DB_HOST) etc.

If you still can’t get it working. You can refer to the solution posted here