TerraTest: Test a Kubernetes deployment and service
Published in
7 min readApr 7, 2022
In this story, we will see how to test a Kubernetes deployment and service. For that, we will use TerraTest.
Create the deployment and service manifests
Now, we will create the deployment and the service that we want to test. In first, let’s create a deployment manifest deploy.yaml
:
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deploy
spec:
selector:
matchLabels:
app: nginx
replicas: 1
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: devopstestlab/nginx-helloworld
ports:
- containerPort: 80
Then let’s create a service manifest svc.yaml
:
---
kind: Service
apiVersion: v1
metadata:
name: nginx-svc
spec:
selector:
app: nginx
ports:
- protocol: TCP
targetPort: 80
port: 80
type: NodePort
Let’s create the deployment:
kubectl apply -f deploy.yaml
The output is:
deployment.apps/nginx-deploy created
Let’s create the service:
kubectl apply -f svc.yaml
The output is:
service/nginx-svc created
Let’s check that the pod is running:
kubectl get pods