Post-Deployment Operations
Checking application logs
To check the logs of a particular service, we can use the built-in mechanisms and using the kubectl tool we can check the logs in the following ways:
Basic log retrieval
Retrieve logs from a specific pod:
kubectl logs $pod-name -n $namespaceFollow mode (real-time logs)
Monitor logs in real-time as they are generated:
kubectl logs -f $pod-name -n $namespaceUsing labels:
kubectl logs -l $label-selector -n $namespace
kubectl logs -l app.kubernetes.io/name=som-dev-service-validation -n $namespace
kubectl logs -f -l app.kubernetes.io/name=som-dev-service-validation -n $namespaceLogs within a time interval:
Retrieve logs from the last specified time interval:
kubectl logs $pod-name --since=10m -n $namespaceRestart application
kubectl rollout restart is the preferred method for restarting an application, as it initiates a controlled restart of all pods in a given deployment without interrupting the application. This method makes it easy to update the application, allowing it to remain available by gradually replacing old pods with new ones.
kubectl delete pod command removes the selected pods manually, allowing you to restart the pod immediately without running a full rollout process. When a pod is deleted, the ReplicaSet controller will automatically create a new pod to reach the defined number of replicas.
Comparison of Methods: kubectl rollout restart vs kubectl delete pod
| Method | Description | When to Use | Advantages | Disadvantages |
|---|---|---|---|---|
| kubectl rollout restart deployment | Sequentially restarts all pods in a deployment. | For application updates and controlled restarts. | Maintains application continuity and allows monitoring rollout progress. | May be slower for large deployments. |
| kubectl delete pod | Deletes a specific pod and triggers automatic recreation by the ReplicaSet.. | For localized errors or fast restarts of individual pods. | Fast restart without needing a full rollout. | May cause brief application downtime if replicas are limited. |