<p>My goal to override the default Kubelet configuration in the running cluster</p>

<pre><code>"imageGCHighThresholdPercent": 85,
"imageGCLowThresholdPercent": 80,
</code></pre>

<p>to</p>

<pre><code> "imageGCHighThresholdPercent": 60,
 "imageGCLowThresholdPercent": 40,
</code></pre>

<p>The possible option is to apply the node patch for each node. </p>

<p>I'm using the following command to get the kubelet config via kubeclt proxy </p>

<pre><code>curl -sSL "http://localhost:8001/api/v1/nodes/ip-172-31-20-135.eu-west-1.compute.internal/proxy/configz" | python3 -m json.tool
</code></pre>

<p>The output is </p>

<pre><code>{
  "kubeletconfig": {

     ....

    "imageGCHighThresholdPercent": 85,
    "imageGCLowThresholdPercent": 80,

     .....
    }
}
</code></pre>

<p>here is the command I'm using to update these two values</p>

<pre><code>kubectl patch node ip-172-31-20-135.eu-west-1.compute.internal -p '{"kubeletconfig":{"imageGCHighThresholdPercent":60,"imageGCLowThresholdPercent":40}}'
</code></pre>

<p>Unfortunately the kubeclt returns me </p>

<p><strong>node/ip-172-31-20-135.eu-west-1.compute.internal patched (no change)</strong> </p>

<p>As a result the change has no effect.</p>

<p>Any thought what I'm doing wrong. </p>

<p>Thanks</p>

Denis Voloshin
<p>While you are using EKS you have to configure <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AMIs.html" rel="nofollow noreferrer">An Amazon Machine Image (AMI)</a> provides the information required to launch an instance. You must specify an AMI when you launch an instance. You can launch multiple instances from a single AMI when you need multiple instances with the same configuration. You can use different AMIs to launch instances when you need instances with different configurations.</p>

<p>First create folder <code>/var/lib/kubelet</code>, and put <strong>kubeconfig</strong> template file into it, the content as below:</p>

<pre><code>apiVersion: v1  
kind: Config  
clusters:  
- cluster:  
    certificate-authority: CERTIFICATE_AUTHORITY_FILE  
    server: MASTER_ENDPOINT  
  name: kubernetes  
contexts:  
- context:  
    cluster: kubernetes  
    user: kubelet  
  name: kubelet  
current-context: kubelet  
users:  
- name: kubelet  
  user:  
    exec:  
      apiVersion: client.authentication.k8s.io/v1alpha1  
      command: /usr/bin/heptio-authenticator-aws  
      args:  
        - "token"  
        - "-i"  
        - "CLUSTER_NAME"
</code></pre>

<p>Then create template file <code>/etc/systemd/system/kubelet.service</code>, the content as below:</p>

<pre><code>[Unit]  
Description=Kubernetes Kubelet  
Documentation=[https://github.com/kubernetes/kubernetes](https://github.com/kubernetes/kubernetes)  
After=docker.service  
Requires=docker.service

[Service]  
ExecStart=/usr/bin/kubelet \  
   --address=0.0.0.0 \  
   --authentication-token-webhook \  
   --authorization-mode=Webhook \  
   --allow-privileged=true \  
   --cloud-provider=aws \  
   --cluster-dns=DNS_CLUSTER_IP \  
   --cluster-domain=cluster.local \  
   --cni-bin-dir=/opt/cni/bin \  
   --cni-conf-dir=/etc/cni/net.d \  
   --container-runtime=docker \  
   --max-pods=MAX_PODS \  
   --node-ip=INTERNAL_IP \  
  --network-plugin=cni \  
   --pod-infra-container-image=602401143452.dkr.ecr.REGION.amazonaws.com/eks/pause-amd64:3.1 \  
   --cgroup-driver=cgroupfs \  
   --register-node=true \  
   --kubeconfig=/var/lib/kubelet/kubeconfig \  
   --feature-gates=RotateKubeletServerCertificate=true \  
   --anonymous-auth=false \  
   --client-ca-file=CLIENT_CA_FILE  \
   --image-gc-high-threshold=60  \
   --image-gc-low-threshold=40

Restart=on-failure  
RestartSec=5

[Install]  
WantedBy=multi-user.target
</code></pre>

<p>You have to add flags <code>image-gc-high-threshold</code> and <code>image-gc-low-threshold</code> and specify proper values.</p>

<pre><code>--image-gc-high-threshold int32    The percent of disk usage after which image garbage collection is always run. (default 85)
--image-gc-low-threshold int32     The percent of disk usage before which image garbage collection is never run. Lowest disk usage to garbage collect to. (default 80)
</code></pre>

<p>Please take a look: <a href="https://medium.com/getamis/customize-aws-eks-worker-node-ami-d7b3d203051" rel="nofollow noreferrer">eks-worker-node-ami</a>.</p>
