Start by checking how many pods exist on the system with the command:
Copy
Ask AI
kubectl get pods
Output:
Copy
Ask AI
No resources found in default namespace.
Next, verify the number of ReplicaSets:
Copy
Ask AI
kubectl get rs
Output:
Copy
Ask AI
No resources found in default namespace.
Finally, check the existing deployments:
Copy
Ask AI
kubectl get deployments
Output:
Copy
Ask AI
No resources found in default namespace.
At this point, the environment is clean—no pods, ReplicaSets, or deployments are present.Some changes are then applied. Rechecking the deployments now shows that one deployment has been created:
Copy
Ask AI
kubectl get deployments
Output:
Copy
Ask AI
NAME READY UP-TO-DATE AVAILABLE AGEfrontend-deployment 0/4 4 0 10s
Next, inspect the ReplicaSets:
Copy
Ask AI
kubectl get rs
Output:
Copy
Ask AI
NAME DESIRED CURRENT READY AGEfrontend-deployment-7f8dcd896 4 4 0 35s
None of the four pods are ready. To investigate further, inspect one of the pods in detail:
Copy
Ask AI
kubectl describe pod frontend-deployment-7f8dcd896-stmbx
Within the detailed output, you will notice that the image used is “busybox888” (visible under the “Pulling image” events). Key excerpts from the describe output include:
Copy
Ask AI
State: WaitingReason: ErrImagePull...Pulling image "busybox888"Warning Failed ... Failed to pull image "busybox888": rpc error: code = Unknown desc = failed to pull and unpack image "docker.io/library/busybox888:latest": pull access denied, repository does not exist or may require authorization: server response: authorization failedWarning Failed ... Error: ErrImagePullNormal BackOff ... Back-off pulling image "busybox888"
The image “busybox888” does not exist, which is why the pods are not becoming ready. Verify and update your image name as needed.
Then, attempt to create the deployment by executing:
Copy
Ask AI
kubectl create -f deployment-definition-1.yaml
You might encounter an error similar to this:
Copy
Ask AI
Error from server (BadRequest): error when creating "deployment-definition-1.yaml": deployment in version "v1" cannot be handled as a Deployment: no kind "deployment" is registered for version "apps/v1" in scheme "k8s.io/apimachinery/v1.23.3-k3s1/pkg/runtime/schema.go:100"
Upon inspecting the file, you could notice that although the API version is correctly set to apps/v1, the kind is mistakenly written in lowercase. The kind field is case sensitive and must start with an uppercase letter.Below is the corrected YAML definition:
An alternative method is to create a deployment directly from the command line by specifying the name, image, and number of replicas. For example, to create an HTTP frontend deployment with three replicas using a specific image, run:
Check the environment for existing pods, ReplicaSets, and deployments.
Troubleshoot a deployment issue caused by an incorrect image.
Correctly create a deployment using a YAML definition.
Create a deployment directly from the command line.
Ensuring correct syntax and case sensitivity in your Kubernetes YAML files is crucial to avoid deployment errors.
By following these steps, you will strengthen your understanding of Kubernetes deployments and develop the skills to quickly troubleshoot and resolve common issues.