![]() |
Codeigniter 4 and DB hosted in Kubernetes - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: Installation & Setup (https://forum.codeigniter.com/forumdisplay.php?fid=9) +--- Thread: Codeigniter 4 and DB hosted in Kubernetes (/showthread.php?tid=92694) |
Codeigniter 4 and DB hosted in Kubernetes - ryan_w_frank - 03-31-2025 Hello, I am beating my head against the wall trying to figure out what I am doing wrong... I setup a PostgreSQL database in my Kubernetes cluster, have it exposed through LoadBalancer. I can connect from Python and PGAdmin just fine. Configured CI to connect with the same config used in Python and PGAdmin: Code: public array $default = [ RE: Codeigniter 4 and DB hosted in Kubernetes - InsiteFX - 03-31-2025 You may need a full DSN Name for it. CodeIgniter 4 Users Guide - Working with Databases - Database Configuration - DSN RE: Codeigniter 4 and DB hosted in Kubernetes - haudevbe - 04-01-2025 1. Check Kubernetes LoadBalancer IP/Port Configuration Ensure that the LoadBalancer IP and port (192.168.1.240) is correctly configured and accessible from the CI environment. Verify that the LoadBalancer is exposing the PostgreSQL port (default is 5432). You can check with the following command in Kubernetes: kubectl get svc Verify if the LoadBalancer IP is properly assigned to the service. 2. Verify Network Connectivity From your CI environment, ensure that the server can actually reach 192.168.1.240. You can use tools like ping or telnet to test connectivity: ping 192.168.1.240 telnet 192.168.1.240 5432 If there's a network issue, you might need to update firewall rules or security groups, depending on your Kubernetes environment. 3. Check Database Authentication Double-check the username, password, and database name in your CI configuration. Make sure that the same credentials work on Python and PGAdmin. Ensure that the PostgreSQL user has the necessary permissions to access the specified database. 4. DB Configuration (pg_hba.conf) If you're using a self-hosted PostgreSQL instance, check the pg_hba.conf file on the PostgreSQL server to ensure it allows connections from your CI environment. Look for lines similar to: host all all 192.168.1.240/32 md5 You may need to allow connections from your CI's IP address or subnet. 5. Test Connection String In the provided configuration, try replacing the hostname with the fully qualified domain name or the Kubernetes service name if you're using Kubernetes DNS. Additionally, try adding the port explicitly if it’s not using the default PostgreSQL port (5432): 'hostname' => '192.168.1.240:5432' 6. Error Logs If the connection fails, check the logs from your CI environment to see if there’s any detailed error message. Look for authentication failures, connection timeouts, or network issues. You can also check PostgreSQL logs to see if it is rejecting connections. 7. Database Driver Ensure that the PostgreSQL driver is correctly installed and supported by your CI environment. The DBDriver should be set to 'Postgre', which you have already done, but you should also confirm that all necessary dependencies for PostgreSQL support are installed in your CI environment. 8. CI Configuration Issues Sometimes CI environments have network restrictions or proxy issues that could affect database connections. Try testing locally or using a different network configuration to rule out such issues. 9. Timeout Configuration Check if the CI connection has a timeout setting that is too short for establishing the connection. You might want to increase the timeout setting in your configuration if it's a connection timeout issue. If you've gone through these steps and the issue persists, sharing the specific error message you're getting from the CI logs would be helpful in pinpointing the problem further. RE: Codeigniter 4 and DB hosted in Kubernetes - ryan_w_frank - 04-01-2025 (03-31-2025, 11:47 PM)InsiteFX Wrote: You may need a full DSN Name for it. I have tried DSN. From what my simple mind can understand, looks like the PG driver is doing a pg_ping to validate server is alive. As you can't ping the kube service through the ingress, the ICMP responds weird and it fails the connection... I could be 100% wrong, but it seems to be logical tracing the connection process through CI code. RE: Codeigniter 4 and DB hosted in Kubernetes - trello - 04-11-2025 Thanks It was of great help for me |