Kubernetes HTTP liveness probe fails with "connection refused" even though URL works without it
For anyone interested I've managed to solve this issue.
I was getting a 301 redirect response from Wordpress due to Wordpress forcing my domain name example.com. Solved this issue by disabling Wordpress canonical redirection feature for the specific request http://POD_IP:8080/index.php.
Here's how:
Added the Pod IP address as an environment variable:
- name: K8S_POD_IP valueFrom: fieldRef: fieldPath: status.podIP
Created a Wordpress plugin with a custom redirect_canonical filter that prevents Wordpress from redirecting http://POD_IP:8080/index.php:
<?php/** * Plugin Name: Kubernetes Liveness Probe Exception */add_filter('redirect_canonical', function($redirect_url, $requested_url) { $K8S_POD_IP = getenv('K8S_POD_IP'); $LIVENESS_URL = "http://" . $K8S_POD_IP . ":8080/index.php"; if ($requested_url == $LIVENESS_URL) { return $requested_url; } return $redirect_url;}, 10, 2);
10.244.3.1 - - [11/Dec/2019:06:39:18 +0000] "GET /index.php HTTP/1.1" 301 264 "-" "kube-probe/1.16"
You're getting a 301 redirect response from Apache. You need to be getting a 2xx to be considered a success.
To check what path it's redirecting you to try curl --location --verbose http://url/index.php
If you can't figure out a way around Apache or Wordpress's redirection, you could consider a tcpSocket probe rather than httpGet
I'd think WP redirects you to a “clean” url of /
. Remove the index.php part