<p>I'm trying to scale a deployment with <a href="https://godoc.org/k8s.io/client-go/kubernetes/typed/apps/v1" rel="nofollow noreferrer">golang client</a>. The problem I've found is that the <a href="https://godoc.org/k8s.io/client-go/kubernetes/typed/apps/v1#DeploymentInterface" rel="nofollow noreferrer">golang client does not have a scale method for deployments</a>. I don't know how I should do it. 
The idea that I have is get a deployment, modify the replicas, and then do an update. </p>

<pre><code>package main

import (
    "context"
    metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    appsv1 "k8s.io/api/apps/v1"
    "flag"
    "fmt"
    "os"
    "path/filepath"

)

func main() {
    var kubeconfig *string
    if home := homedir.HomeDir(); home != "" {
        kubeconfig = flag.String("kubeconfig", filepath.Join(home, ".kube", "config"), "(optional) absolute path to the kubeconfig file")
    } else {
        kubeconfig = flag.String("kubeconfig", "", "absolute path to the kubeconfig file")
    }
    flag.Parse()

    config, err := clientcmd.BuildConfigFromFlags("", *kubeconfig)
    if err != nil {
        panic(err)
    }
    clientset, err := kubernetes.NewForConfig(config)
    if err != nil {
        panic(err)
    }
    //get and update replicas
    deploymentsClient := clientset.AppsV1().Deployments(apiv1.NamespaceDefault)
    deployment, _ := deploymentsClient.Get(context.TODO(), "demo-deployment", metav1.GetOptions{})
    deploymentsClient.Update(context.TODO(), deployment, metav1.UpdateOptions{})
}
</code></pre>

<p>(Example taken from <a href="https://github.com/kubernetes/client-go/blob/master/examples/create-update-delete-deployment/" rel="nofollow noreferrer">kubernetes client go</a> github repository)</p>

<p>But I don't know if it is the best aproach. </p>

pcampana
<pre><code>package main

import (
    &quot;context&quot;
    &quot;log&quot;
    &quot;path/filepath&quot;

    metav1 &quot;k8s.io/apimachinery/pkg/apis/meta/v1&quot;
    &quot;k8s.io/client-go/kubernetes&quot;
    &quot;k8s.io/client-go/rest&quot;
    &quot;k8s.io/client-go/tools/clientcmd&quot;
    &quot;k8s.io/client-go/util/homedir&quot;
)

func main() {
    kubeconfig := filepath.Join(homedir.HomeDir(), &quot;.kube&quot;, &quot;config&quot;)
    config, err := clientcmd.BuildConfigFromFlags(&quot;&quot;, kubeconfig)
    if err != nil {
        config, err = rest.InClusterConfig()
        if err != nil {
            log.Fatal(err)
        }
    }

    client, err := kubernetes.NewForConfig(config)
    if err != nil {
        log.Fatal(err)
    }

    s, err := client.AppsV1().
        Deployments(&quot;default&quot;).
        GetScale(context.TODO(), &quot;nginx&quot;, metav1.GetOptions{})
    if err != nil {
        log.Fatal(err)
    }

    sc := *s
    sc.Spec.Replicas = 10

    us, err := client.AppsV1().
        Deployments(&quot;default&quot;).
        UpdateScale(context.TODO(),
            &quot;nginx&quot;, &amp;sc, metav1.UpdateOptions{})
    if err != nil {
        log.Fatal(err)
    }

    log.Println(*us)
}
</code></pre>
