Kubernetes deploy LAMP-Stack with secrets yaml

Hello,
i get issues connecting to mysql database if i deploy the LAMP-Stack if i try to deploy my secrets via yaml file. Is there something else i have to look out for if i try this approach?

My yaml file:

apiVersion: v1
kind: Secret
metadata:
  name: mysecret
type: Opaque
data:
  MYSQL_ROOT_PASSWORD: bmJ0ZWNo
  MYSQL_DATABASE: a29kZWtsb3Vk
  MYSQL_USER: bXl1c2Vy
  MYSQL_PASSWORD: bXlwYXNzd29yZA==
  MYSQL_HOST: bXlob3N0

It works if i create the secrets via CLI, but i wanted to try a different approach:
kubectl create secret generic mysecret --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

Hi @marco.braeumer

Normally, he should be ok nothing special to add to the yaml file. Which kind of error did you face on?
However, you can use the command line to generate the yaml file and adapt it after before create your secret.

kubectl create secret generic mysecret --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 --dry-run=client -o yaml > myawesome_secret.yaml
  • edit the file and adapt if needed

  • create the secret from file

kubectl create -f myawesome_secret.yaml

Regard

Hi,
i might have made a mistake setting the secrets manually. I used echo -n "blabla" | base64 for every value.

After using your approach it worked now, thank you :slight_smile:

logs from the httpd-php container where i got connection issues:

thor@jump_host ~$ kubectl logs lamp-wp-6cd857bf75-svpp4
Defaulted container "httpd-php-container" out of: httpd-php-container, mysql-container
-> Executing /opt/docker/provision/entrypoint.d/05-permissions.sh
-> Executing /opt/docker/provision/entrypoint.d/20-php-fpm.sh
-> Executing /opt/docker/provision/entrypoint.d/20-php.sh
-> Executing /opt/docker/bin/service.d/supervisor.d//10-init.sh
2023-08-08 21:28:32,332 CRIT Set uid to user 0
2023-08-08 21:28:32,332 WARN Included extra file "/opt/docker/etc/supervisor.d/apache.conf" during parsing
2023-08-08 21:28:32,332 WARN Included extra file "/opt/docker/etc/supervisor.d/cron.conf" during parsing
2023-08-08 21:28:32,332 WARN Included extra file "/opt/docker/etc/supervisor.d/dnsmasq.conf" during parsing
2023-08-08 21:28:32,332 WARN Included extra file "/opt/docker/etc/supervisor.d/php-fpm.conf" during parsing
2023-08-08 21:28:32,332 WARN Included extra file "/opt/docker/etc/supervisor.d/postfix.conf" during parsing
2023-08-08 21:28:32,332 WARN Included extra file "/opt/docker/etc/supervisor.d/ssh.conf" during parsing
2023-08-08 21:28:32,332 WARN Included extra file "/opt/docker/etc/supervisor.d/syslog.conf" during parsing
2023-08-08 21:28:32,339 INFO RPC interface 'supervisor' initialized
2023-08-08 21:28:32,339 INFO supervisord started with pid 1
2023-08-08 21:28:33,342 INFO spawned: 'syslogd' with pid 89
2023-08-08 21:28:33,344 INFO spawned: 'php-fpmd' with pid 90
2023-08-08 21:28:33,346 INFO spawned: 'apached' with pid 91
2023-08-08 21:28:33,348 INFO spawned: 'crond' with pid 92
-> Executing /opt/docker/bin/service.d/syslog-ng.d//10-init.sh
2023-08-08 21:28:33,348 INFO success: php-fpmd entered RUNNING state, process has stayed up for > than 0 seconds (startsecs)
2023-08-08 21:28:33,348 INFO success: apached entered RUNNING state, process has stayed up for > than 0 seconds (startsecs)
2023-08-08 21:28:33,348 INFO success: crond entered RUNNING state, process has stayed up for > than 0 seconds (startsecs)
-> Executing /opt/docker/bin/service.d/php-fpm.d//10-init.sh
Setting php-fpm user to application
-> Executing /opt/docker/bin/service.d/httpd.d//10-init.sh
-> Executing /opt/docker/bin/service.d/cron.d//10-init.sh
[SYSLOG] syslog-ng[89]: syslog-ng starting up; version='3.7.2'
[Tue Aug 08 21:28:33.423930 2023] [so:warn] [pid 115:tid 140612842564424] AH01574: module socache_shmcb_module is already loaded, skipping
[Tue Aug 08 21:28:33.428707 2023] [so:warn] [pid 115:tid 140612842564424] AH01574: module socache_shmcb_module is already loaded, skipping
[Tue Aug 08 21:28:33.500026 2023] [lbmethod_heartbeat:notice] [pid 115:tid 140612842564424] AH02282: No slotmem from mod_heartmonitor
[Tue Aug 08 21:28:33.502478 2023] [mpm_event:notice] [pid 115:tid 140612842564424] AH00489: Apache/2.4.25 (Unix) LibreSSL/2.4.4 configured -- resuming normal operations
[Tue Aug 08 21:28:33.502513 2023] [core:notice] [pid 115:tid 140612842564424] AH00094: Command line: '/usr/sbin/httpd -D FOREGROUND'
[08-Aug-2023 21:28:33] NOTICE: fpm is running, pid 90
[08-Aug-2023 21:28:33] NOTICE: ready to handle connections
2023-08-08 21:28:34,604 INFO success: syslogd entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
[08-Aug-2023 21:28:53] WARNING: [pool www] child 220 said into stderr: "NOTICE: PHP message: PHP Warning:  mysqli_connect(): (HY000/2005): Unknown MySQL server host 'myhost' (-2) in /app/index.php on line 7"
[php-fpm:access] 127.0.0.1 -  08/Aug/2023:21:28:53 +0000 "GET /index.php" 200 /app/index.php 4.973 2048 0.00%
[Tue Aug 08 21:28:53.498128 2023] [proxy_fcgi:error] [pid 120:tid 140612841556656] [client 10.244.0.1:23569] AH01071: Got error 'PHP message: PHP Warning:  mysqli_connect(): (HY000/2005): Unknown MySQL server host 'myhost' (-2) in /app/index.php on line 7\n', referer: https://c0a50ee3335e497c.labs.kodekloud.com/
10.244.0.1 - - [08/Aug/2023:21:28:53 +0000] "GET / HTTP/1.1" 200 29 "https://c0a50ee3335e497c.labs.kodekloud.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/116.0"
[httpd:access] 30008-port-c0a50ee3335e497c.labs.kodekloud.com:80 10.244.0.1 - - [08/Aug/2023:21:28:53 +0000] "GET / HTTP/1.1" 200 bytesIn:2119 bytesOut:213 reqTime:0

@marco.braeumer

You need to adapt the host ‘myhost’ on index.php with the hostname and port of your mysql container