Scaling up and down the application or service based on predefined criteria is a common way to utilize the most compute resources in most efficient way. In Kubernetes, you can scale up and down manually or use a Horizontal Pod Autoscaler (HPA) to do autoscaling. In this section, we'll describe how to perform both operations.
Prepare the following YAML file, which is a simple Deployment that launches two nginx
containers. Also, a NodePort service with TCP—30080
exposed:
# cat 3-1-1_deployment.yaml apiVersion: apps/v1 kind: Deployment metadata: name: my-nginx spec: replicas: 2 selector: matchLabels: service : nginx template: metadata: labels: service : nginx spec: containers: - name: my-container image: nginx --- apiVersion: v1 kind: Service metadata: name: my-nginx spec: ports: - protocol: TCP port: 80 nodePort: 30080 type: NodePort selector: service: nginx