Hello, I'm Arthur.
Deploying an application to Kubernetes can make it easier to manage containers, scale workloads, and maintain reliable services. However, a deployment does not always work as expected.
An application may remain in a pending state, containers may repeatedly restart, or a service may fail to connect to its pods.
Understanding how to investigate these problems is an important skill for developers and system administrators.
In this guide, we'll explore common Kubernetes deployment issues, useful troubleshooting commands, and practical ways to identify the root cause of application failures.
1. Understand the Kubernetes Deployment Process
Kubernetes uses several components to manage applications.
A typical application deployment includes:
- Deployment: Manages the desired number of application replicas.
- Pod: Runs one or more containers.
- Service: Provides a stable network endpoint for accessing pods.
- ConfigMap: Stores non-sensitive application configuration.
- Secret: Stores sensitive configuration data.
When you deploy an application, Kubernetes attempts to maintain the desired state defined in your configuration.
For example, if a Deployment specifies three replicas, Kubernetes attempts to keep three application pods running.
If a pod fails, Kubernetes may create a replacement.
Understanding these components helps narrow down where a problem might be occurring.
2. Check the Deployment Status
Start by checking the status of your application.
kubectl get deployments
This command displays the desired and available replicas for each Deployment.
For example:
NAME READY UP-TO-DATE AVAILABLE
web-app 2/3 3 2
In this example, the Deployment expects three replicas, but only two are available.
This indicates that at least one pod is not becoming available.
Check the pods in the current namespace:
kubectl get pods
For a more detailed view:
kubectl get pods -o wide
The output includes the pod status, restart count, and node assignment.
Common statuses include:
-
Pending: The pod has not yet been scheduled or fully started. -
Running: The pod has been assigned to a node and its containers are running or starting. -
CrashLoopBackOff: A container repeatedly fails and Kubernetes is delaying another restart. -
ImagePullBackOff: Kubernetes is having trouble pulling the container image.
These statuses help identify which troubleshooting steps to follow next.
3. Investigate Pods That Are Not Starting
If a pod remains in the Pending state, inspect its details:
kubectl describe pod pod-name
Replace pod-name with the actual pod name.
The output includes information about scheduling, container configuration, and recent events.
Look for messages such as:
FailedScheduling
This may indicate that Kubernetes cannot find a suitable node for the pod.
Possible causes include insufficient CPU or memory, node restrictions, or storage requirements that cannot be satisfied.
For example, if a pod requests more CPU than any available node can provide, it may remain pending until resources become available or the workload configuration changes.
Check the cluster nodes:
kubectl get nodes
Then inspect their resource information:
kubectl describe node node-name
Review the available resources and any scheduling restrictions before making changes.
4. Troubleshoot ImagePullBackOff Errors
A pod may fail to start because Kubernetes cannot download its container image.
Common causes include:
- An incorrect image name
- A missing image tag
- A private registry requiring authentication
- Network connectivity problems
- Registry rate limits
Inspect the pod events:
kubectl describe pod pod-name
Look for image-related error messages.
You can also check the image configured in a Deployment:
kubectl get deployment web-app \
-o jsonpath='{.spec.template.spec.containers[*].image}'
If the image is stored in a private registry, make sure the appropriate image pull secret is configured.
For example, a Deployment can reference a secret using:
spec:
template:
spec:
imagePullSecrets:
- name: registry-secret
The secret must exist in the same namespace as the pod.
Avoid placing registry passwords directly in application manifests or public repositories.
5. Check Container Logs
If a container starts and then crashes, its logs may reveal the cause.
Retrieve the current container logs:
kubectl logs pod-name
If the pod contains multiple containers, specify the container name:
kubectl logs pod-name -c container-name
For a container that has restarted, check its previous logs:
kubectl logs pod-name --previous
This can help identify errors that occurred before the last restart.
Common problems include:
- Missing environment variables
- Invalid application configuration
- Database connection failures
- Incorrect file permissions
- Application startup errors
For example, an application may fail because it expects a database hostname that is not available in its Kubernetes configuration.
Review the logs before changing the Deployment or restarting the application.
6. Troubleshoot Kubernetes Services
A pod can be running correctly while the application remains inaccessible.
This may happen when a Service is configured incorrectly or does not select the intended pods.
List the Services:
kubectl get services
Inspect a particular Service:
kubectl describe service web-service
Check the Service's endpoints:
kubectl get endpoints web-service
On newer Kubernetes versions, you can also inspect EndpointSlices:
kubectl get endpointslices
If the Service has no endpoints, check whether its selector matches the labels on the application pods.
For example, a Service may select pods with:
selector:
app: web
But the actual pods may use:
labels:
app: web-app
Because the labels do not match, the Service will not select those pods.
Correcting the selector can restore connectivity without changing the application itself.
7. Check Application Resource Limits
Kubernetes allows you to define CPU and memory requests and limits for containers.
Requests help Kubernetes schedule workloads, while limits can restrict how much CPU or memory a container can use.
For example:
resources:
requests:
cpu: "250m"
memory: "256Mi"
limits:
cpu: "500m"
memory: "512Mi"
If a container exceeds its memory limit, it may be terminated.
You may see an OOMKilled reason when inspecting the pod.
Check the pod status:
kubectl describe pod pod-name
If the container is being terminated because of insufficient memory, investigate its actual memory usage before increasing the limit.
For CPU-related performance problems, inspect resource usage:
kubectl top pods
This command requires the Kubernetes Metrics Server or another compatible metrics provider.
If the cluster has insufficient capacity, review whether the workload can be optimized or whether additional resources are needed.
For applications running on dedicated infrastructure, SeiMaxim's dedicated server hosting can be evaluated when planning the compute resources required for a Kubernetes environment.
8. Review Kubernetes Events
Kubernetes events provide useful information about scheduling, container startup, and other cluster activities.
List recent events:
kubectl get events --sort-by=.metadata.creationTimestamp
To inspect events in a particular namespace:
kubectl get events -n production
Look for warnings and repeated failures.
For example, an event may report that a container cannot mount a volume or that a pod cannot be scheduled.
Events can help identify when the problem started and which Kubernetes component reported it.
They are especially useful when an application fails before producing its own logs.
9. Validate Deployment Changes
When troubleshooting, avoid changing several configuration settings at the same time.
Instead, make one targeted change and observe its effect.
You can review the current Deployment configuration:
kubectl get deployment web-app -o yaml
If the Deployment was created using a configuration file, validate the proposed changes before applying them:
kubectl diff -f deployment.yaml
Apply the configuration:
kubectl apply -f deployment.yaml
Then monitor the rollout:
kubectl rollout status deployment/web-app
If the updated application fails and the previous revision is available, you can roll back:
kubectl rollout undo deployment/web-app
A rollback should be part of a controlled recovery process. Confirm that the previous application version is compatible with the current database and configuration.
10. Plan Infrastructure for Kubernetes Workloads
Kubernetes can distribute applications across multiple nodes, but the cluster still depends on the underlying infrastructure.
Before deploying a workload, consider:
- CPU and memory requirements
- Storage capacity and performance
- Network connectivity between nodes
- Container registry access
- Resource requests and limits
- Monitoring and recovery procedures
For production workloads, the infrastructure must support both normal application activity and the resource requirements of scheduled workloads.
SeiMaxim's server hosting solutions can be reviewed when planning the infrastructure for containerized applications.
The best configuration depends on the number of workloads, expected traffic, resource requirements, and the reliability goals of the application.
Final Thoughts
Kubernetes deployment problems can come from many different sources, including container images, scheduling, application configuration, networking, and resource limits.
Start by checking the Deployment and pod status. Then inspect events, logs, Services, and resource usage to identify the underlying cause.
Make targeted changes and monitor the result before moving on to another adjustment.
A systematic troubleshooting process helps developers resolve deployment issues more efficiently and build applications that are easier to maintain.
Top comments (0)