I am currently building a CI/CD pipeline where I am trying to test a simple nginx deployment, the problem is when I run kubectl apply -f ./nginx-demplyment.yaml
I only get the output that resources got created/updated.
In my use case I the first thing i get is:
deployment.apps/nginx1.14.2 created
service/my-service created
And this is the output of kubectl get all
where pods STATUS
says ContainerCreating:
The problem is in my pipeline I want to run curl
command to check if my nginx server is working properly once the image gets pulled and the pod STATUS is Running, but obviously if the image didn’t get pulled yet curl will say connection refused because the container is not up yet.
How can I do that and is there a way to get the output of pulling images at least?
the task runs the commands with && so the curl gets executed right after kubectl.
Am working on a kind cluster with 3 control-plane nodes and 2 worker nodes.
2
Answers
I think there is a possible way to do that which is by downloading the images first then deploying Nginx.
once the image gets pulled next command
curl
will work as wanted.You can use
kubectl wait
to wait for the deployment to be in a certain condition. Another option (or possibly used in combination) is to retry curl until the request returns a 200. An example of kubectl wait for your nginx deployment to become ready: