This is in continuation to the previous post

The front end deployments have 3 Pod replicas


networkandcode@k8s-master:~ kubectl get deployment deploy4-frontend -n staging
NAME               READY   UP-TO-DATE   AVAILABLE   AGE
deploy4-frontend   3/3     3            3           34h
networkandcode@k8s-master:~ kubectl get deployment deploy4-frontend -n production
NAME               READY   UP-TO-DATE   AVAILABLE   AGE
deploy4-frontend   3/3     3            3           34h

Let's define an hpa manifest with minimum replicas 4, maximum replicas 4, and target CPU utilization as 75%


networkandcode@k8s-master:~ cat hpa7-frontend.yaml
---
apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
  name: hpa7-frontend
  namespace: NameSpaceName
spec:
  minReplicas: 2
  maxReplicas: 5
  targetCPUUtilizationPercentage: 75
  scaleTargetRef:
    apiVersion: extensions/v1beta1
    kind: Deployment
    name: deploy4-frontend
...

To create the hpa in both namespaces


networkandcode@k8s-master:~ sed -i 's/NameSpaceName/staging/g' hpa7-frontend.yaml
networkandcode@k8s-master:~ kubectl create -f hpa7-frontend.yaml
horizontalpodautoscaler.autoscaling/hpa7-frontend created
networkandcode@k8s-master:~ sed -i 's/staging/production/g' hpa7-frontend.yaml
networkandcode@k8s-master:~ kubectl create -f hpa7-frontend.yaml
horizontalpodautoscaler.autoscaling/hpa7-frontend created
networkandcode@k8s-master:~ sed -i 's/production/NamespaceName/g' hpa7-frontend.yaml

Verify


networkandcode@k8s-master:~ kubectl get hpa --all-namespaces
NAMESPACE    NAME            REFERENCE                     TARGETS         MINPODS   MAXPODS   REPLICAS   AGE
production   hpa7-frontend   Deployment/deploy4-frontend   /75%   2         5         3          2m8s
staging      hpa7-frontend   Deployment/deploy4-frontend   /75%   2         5         3          2m25s

--end-of-post--