7

I've got a setup described bellow - so a simple replication controller, service and an https ingress deployed with kubernetes on google cloud.

I need to kill my app for a bit so that I can test how the rest of my stack reacts - what's a good way to do it?

I've tried deleting the service, but when I've recreated it, it wouldn't pick up the backend service (replication controller and pod got created and I could access them internally, but not via the ingress - the service didn't see it.

echo "
apiVersion: v1
kind: Service
metadata:
  name: nodeapp-https
  labels:
    app: nodeapp-https
spec:
  type: NodePort
  ports:
  - port: 80
    targetPort: 8080
    protocol: TCP
    name: http
  selector:
    app: nodeapp-https
---
apiVersion: v1
kind: ReplicationController
metadata:
  name: nodeapp-https
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: nodeapp-https
    spec:
      containers:
      - name: nodeapp-https
        image: gcr.io/my-project/node-app:v84
        ports:
        - containerPort: 8080
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: nodeapp-httpss
spec:
  tls:
  - secretName: node-app-secret
  backend:
    serviceName: nodeapp-https
    servicePort: 80
" | kubectl create -f -
Zlatko
  • 18,936
  • 14
  • 70
  • 123

2 Answers2

24

You could set the replica count to 0 for the duration of the test. When you're finished testing, you would reset the replica count to the desired number to bring your app back up.

The command to do this would be

$ kubectl scale rc nodeapp-https --replicas=0
... do your test
$ kubectl scale rc nodeapp-https --replicas=1
Tigraine
  • 23,358
  • 11
  • 65
  • 110
Pixel Elephant
  • 20,649
  • 9
  • 66
  • 83
4

If you are using Deployment(new concept in k8s), you can scale down replicas(number of pods) using following command,

kubectl scale deployment/<<my-service-name>> --replicas=0 --namespace <<my_namespace>>
deployment.apps/my-service-name scaled

You can verify replica changes by describing the deployment,

kubectl describe deployment my-service-name --namespace my-namespace
Name:                   my-service-name
Namespace:              my-namespace
CreationTimestamp:      Tue, 03 Mar 2020 17:19:41 -0800
Labels:                 app=<<my-service-name>>
Annotations:            deployment.kubernetes.io/revision=91
                        kubectl.kubernetes.io/last-applied-configuration={"apiVersion":"apps/v1","kind":"Deployment","metadata":{"annotations":{},"labels":{"app":"my-service-name"},"name":"my-service-name","namespace":"my_namespace"},"sp...
Selector:               app=my-service-name
Replicas:               0 desired | 0 updated | 0 total | 0 available | 0 unavailable


...

To get the replicas running you can scale up using same command how you scaled down,

kubectl scale deployment/<<my-service-name>> --replicas=1 --namespace <<my-namespace-name>>

For the question, my-service-name is nodeapp-https but its using ReplicationController(not recommended anymore in k8s) not Deployment.

Read:

prayagupa
  • 30,204
  • 14
  • 155
  • 192