Pulumi: how to correctly use HorizontalPodAutoscaler

156 Views Asked by At

I'm trying to setup HPA v1 for my pods using Pulumi

  new HorizontalPodAutoscaler(
    `${prefixedHPAName}`,
    {
        apiVersion: 'autoscaling/v1',
        kind: 'HorizontalPodAutoscaler',
        metadata: {
            name: 'worker',
            clusterName: 'redacted',
            namespace: namespaceName
       },
        spec: {
            maxReplicas: 3,
            minReplicas: 1,
            scaleTargetRef: {
                apiVersion: 'apps/v1',
                kind: 'Deployment',
                name: 'worker'
            },
            targetCPUUtilizationPercentage: 50,
        }
    }
  );

but I keep getting the following error

kubernetes:autoscaling/v1:HorizontalPodAutoscaler (tushar-routex-routex-hpa):
    error: configured Kubernetes cluster is unreachable: unable to load Kubernetes client configuration from kubeconfig file: invalid configuration: no configuration has been provided, try setting KUBERNETES_MASTER environment variable

Are there any examples on how to set HPA for my pods via pulumi?

1

There are 1 best solutions below

0
On

The problem is not related to HPA nor pulumi, its a common problem with kubectl/kubernetes clients, where the client cannot find the kube config file to connect to the K8S API. Check if you have a config file in the path ~/.kube/config, then try to export the path before using pulumi

export KUBECONFIG=~/.kube/config

If you don't have a file, you can check the documentation of your cloud provider to create it.