Hello team,
Please see screenshots. Able to connect successfully but task marked as failed
KodeKloud_Deploy_Lemp_Stack_Level3.pdf (112.2 KB)
Hi @Raghav-Viswanathan
Just tested and it’s work fine
Please try again and let us know if the issue persists. Please provide us the yaml file of each resource
Regard
bro the thing i can figure out in your screenshots is that you are using the wrong deployment name “lemp-wp” instead of “lamp-wp”.
for me too brother it is working fine… @Raghav-Viswanathan
Hello Team,
I am able to get the task done. All resources are up and running. however I am getting below error in the nginx container logs due to which website is not getting launch.
Please see below manifests,
# LEMP Task
---
# secrets defination file
kubectl create secret generic mysql-root-pass --from-literal=password=R00t
kubectl create secret generic mysql-user-pass --from-literal=username=kodekloud_gem --from-literal=password=Rc5C9EyvbU
kubectl create secret generic mysql-db-url --from-literal=database=kodekloud_db10
kubectl create secret generic mysql-host --from-literal=host=mysql-service
---
# configmap and deployment defination file.
----
apiVersion: v1
kind: ConfigMap
metadata:
name: php-config
data:
php.ini: "variables_order = \"EGPCS\" \n"
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: lemp-wp
name: lemp-wp
spec:
replicas: 1
selector:
matchLabels:
app: lemp-wp
template:
metadata:
labels:
app: lemp-wp
spec:
containers:
- image: webdevops/php-nginx:alpine-3-php7
name: nginx-php-container
ports:
- containerPort: 80
volumeMounts:
- name: php-ini
mountPath: /opt/docker/etc/php/
subPath: php
env:
- name: MYSQL_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: mysql-root-pass
key: password
- name: MYSQL_DATABASE
valueFrom:
secretKeyRef:
name: mysql-db-url
key: database
- name: MYSQL_USER
valueFrom:
secretKeyRef:
name: mysql-user-pass
key: username
- name: MYSQL_PASSWORD
valueFrom:
secretKeyRef:
name: mysql-user-pass
key: password
- name: MYSQL_HOST
valueFrom:
secretKeyRef:
name: mysql-host
key: host
- image: mysql:5.6
name: mysql-container
ports:
- containerPort: 3306
env:
- name: MYSQL_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: mysql-root-pass
key: password
- name: MYSQL_DATABASE
valueFrom:
secretKeyRef:
name: mysql-db-url
key: database
- name: MYSQL_USER
valueFrom:
secretKeyRef:
name: mysql-user-pass
key: username
- name: MYSQL_PASSWORD
valueFrom:
secretKeyRef:
name: mysql-user-pass
key: password
- name: MYSQL_HOST
valueFrom:
secretKeyRef:
name: mysql-host
key: host
volumes:
- name: php-ini
configMap:
name: php-config
---
# Service defination file
---
apiVersion: v1
kind: Service
metadata:
name: mysql-service
spec:
selector:
app: lemp-wp
ports:
- port: 3306
targetPort: 3306
protocol: TCP
---
apiVersion: v1
kind: Service
metadata:
name: lemp-service
spec:
type: NodePort
selector:
app: lemp-wp
ports:
- port: 80
targetPort: 80
nodePort: 30008
---
# 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";