Common Errors
Solutions to frequently encountered errors when using PHP K8s.
Connection Errors
"Connection refused"
Error:
cURL error 7: Failed to connect to 127.0.0.1 port 8080: Connection refusedSolution: Ensure kubectl proxy is running:
kubectl proxy --port=8080 &
curl http://127.0.0.1:8080/version # Test connectivitySSL Certificate Errors
Error:
cURL error 60: SSL certificate problemSolution (Development Only):
$cluster->withoutSslChecks();Solution (Production):
$cluster->withCaCertificate('/path/to/ca.crt');Authentication Errors
"Unauthorized"
Error:
401 Unauthorized: User "system:anonymous" cannot list resource "pods"Solution: Provide valid authentication:
// Bearer token
$cluster->withToken('your-token');
// Or kubeconfig
$cluster = KubernetesCluster::fromKubeConfigYamlFile();"Forbidden"
Error:
403 Forbidden: User lacks permission to perform actionSolution: Check RBAC permissions:
kubectl auth can-i list pods --as=system:serviceaccount:default:my-saResource Errors
"Resource not found"
Error:
404 Not Found: pods "nonexistent-pod" not foundSolution: Verify resource exists:
kubectl get pods -n <namespace>try {
$pod = $cluster->getPodByName('my-pod');
} catch (KubernetesAPIException $e) {
if ($e->getCode() === 404) {
echo "Pod not found";
}
}"Already exists"
Error:
409 Conflict: pods "my-pod" already existsSolution: Use createOrUpdate() instead of create():
$pod->createOrUpdate();YAML Errors
"YAML extension not installed"
Error:
Call to undefined function yaml_parse()Solution: Install ext-yaml:
# Ubuntu/Debian
sudo apt-get install php-yaml
# macOS
pecl install yaml
# Verify
php -m | grep yaml"YAML parse error"
Error:
YAML parse error: mapping values are not allowed in this contextSolution: Validate your YAML:
yamllint your-file.yamlType Errors
"Enum comparison fails"
Error (Migrating from upstream):
if ($pod->getPodPhase() === 'Running') { // Always false!Solution: Use enum:
use RenokiCo\PhpK8s\Enums\PodPhase;
if ($pod->getPodPhase() === PodPhase::RUNNING) {
// Correct
}"Type error: string expected, enum given"
Error:
TypeError: Return value must be of type string, enum returnedSolution: Get enum value:
$phaseString = $pod->getPodPhase()->value; // "Running"Watch Errors
"Watch connection timeout"
Error:
Watch operation timed outSolution: Set timeout option:
$cluster->pod()->watchAll(function ($type, $pod) {
// ...
return false;
}, [
'timeoutSeconds' => 600, // 10 minutes
]);Exec/Logs Errors
"Container not running"
Error:
Error executing command: container not runningSolution: Check pod phase:
$pod->refresh();
if ($pod->getPodPhase() !== PodPhase::RUNNING) {
echo "Pod not running yet: {$pod->getPodPhase()->value}";
}"No shell in container"
Error:
exec /bin/sh: no such file or directorySolution: Use available shell or command:
// Try different shells
$output = $pod->exec(['/bin/bash', '-c', 'ls']);
// Or
$output = $pod->exec(['ls']); // Direct commandPatch Errors
"Test operation failed"
Error:
422 Unprocessable Entity: test operation failedSolution: Test operation found mismatch:
$patch = new JsonPatch();
$patch
->test('/spec/replicas', 3) // Expected 3
->replace('/spec/replicas', 5);
try {
$deployment->jsonPatch($patch);
} catch (KubernetesAPIException $e) {
echo "Replica count has changed, refresh and retry";
$deployment->refresh();
}Memory Errors
"Allowed memory size exhausted"
Error:
Fatal error: Allowed memory size of X bytes exhaustedSolution: Increase PHP memory limit:
ini_set('memory_limit', '512M');Or in php.ini:
memory_limit = 512MNamespace Errors
"Namespace not found"
Error:
404: namespaces "production" not foundSolution: Create namespace first:
K8s::namespace($cluster)
->setName('production')
->create();Quick Debugging Checklist
✅ Is kubectl proxy running?
bashcurl http://127.0.0.1:8080/version✅ Can you access the cluster with kubectl?
bashkubectl get pods✅ Is authentication configured?
php$cluster->withToken('...')✅ Is the namespace correct?
php$cluster->getAllPods('correct-namespace')✅ Is ext-yaml installed (for YAML imports)?
bashphp -m | grep yaml✅ Are you using enums correctly?
phpuse RenokiCo\PhpK8s\Enums\PodPhase; $pod->getPodPhase() === PodPhase::RUNNING
Getting Help
If you're still stuck:
- Check the full documentation
- Search GitHub Issues
- Open a new issue with:
- PHP version (
php -v) - Package version (
composer show renoki-co/php-k8s) - Minimal code example
- Full error message
- PHP version (
Troubleshooting guide for common errors in cuppett/php-k8s fork