Federated horizontal pod autoscalers

Let's look at another example of a newer resource that you can use with the federated model: horizontal pod autoscalers (HPAs).  

Here's what the architecture of these looks like in a single cluster:

These HPAs will act in a similar fashion to normal HPAs, with the same functionality and same API-based compatibility—only, with federation, the management will traverse your clusters. This is an alpha feature, so it is not enabled by default on your cluster. In order to enable it, you'll need to run federation-apiserver with the --runtime-config=api/all=true option. Currently, the only metrics that work to manage HPAs are CPU utilization metrics.

First, let's create a file that contains the HPA configuration, called node-hpa-fed.yaml:

apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
name: nodejs
namespace: default
spec:
scaleTargetRef:
apiVersion: apps/v1beta1 kind: Deployment
name: nodejs
minReplicas: 5
maxReplicas: 20
targetCPUUtilizationPercentage: 70

We can add this to our cluster with the following command:

kubectl --context=federation-cluster create -f node-hpa-fed.yaml

In this case, --context=federation-cluster is telling kubectl to send the request to federation-apiserver instead of kube-apiserver.

If, for example, you wanted to restrict this HPA to a subset of your Kubernetes clusters, you can use cluster selectors to restrict the federated object by using the federation.alpha.kubernetes.io/cluster-selector annotation. It's similar in function to nodeSelector, but acts upon full Kubernetes clusters. Cool! You'll need to create an annotation in JSON format. Here's a specific example of a ClusterSelector annotation:

metadata:
annotations:
federation.alpha.kubernetes.io/cluster-selector: '[{"key": "hipaa", "operator":
"In", "values": ["true"]}, {"key": "environment", "operator": "NotIn", "values": ["nonprod"]}]'

This example is going to keep workloads with the hipaa label out of environments with the nonprod label.

For a full list of Top Level Federation API objects, see the following: https://kubernetes.io/docs/reference/federation/

You can check your clusters to see whether the HPA was created in an individual location by specifying the context:

kubectl --context=gce-cluster-01 get HPA nodejs

Once you're finished with the HPA, it can be deleted with the following kubectl command:

kubectl --context=federation-cluster delete HPA nodejs
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.150.143