kubernetes integration testing

7/28/2020

I have 3 microservices, where service A talks to service B and C, and C can talk to A.

I have set up a Jenkins pipeline, where unit tests get run as part of the CI build, however, I'm not sure how to test the container once deployed on the pod. Integration tests on our staging server? I have looked into creating a test container, and using that as a test runner, which can populate the database with data, and verify the results, and produce a report. Is this how it's done?

-- user1555190
devops
jenkins-pipeline
kubernetes

1 Answer

7/28/2020

Answer

Yes, the approach described in your question is an effective way of testing distributed services on Kubernetes.

We maintain a staging cluster that CI pipelines push microservices to and perform tests on.

Each pipeline will run unit tests and then build a Docker image, tag it, and push it to our registry. After this, the pipeline will run something like kubectl set image ... to initiate a rollout of a new ReplicaSet for the respective microservice. Note that we use a unique tag for the image (not latest, for example).

We wait for the rollout via kubectl rollout status ... and once the rollout is complete, the pipeline begins running tests.

We usually run feature and integration tests directly from the pipeline VM. We run load tests (e.g. using locust.io) in a Pod deployed on the staging cluster.

If the tests fail, we run kubectl rollout undo ... to revert the microservice to the previous image.

More Info

Its good practice to maintain Deployment and Service YAML spec in each microservice project (e.g. in deploy/ dir) so that the CI pipeline can be idempotent. In this case you would run kubectl apply -f deploy/*.yaml to update your microservices on the staging cluster.

Pods running test fixtures can rely on ClusterIP services when running against your on-cluster microservices. Tests running from pipeline VMs will need to hit your microservices through Services that have an external IP.

-- Serge
Source: StackOverflow