<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Sysdig</title>
    <description>The latest articles on DEV Community by Sysdig (@sysdig).</description>
    <link>https://dev.to/sysdig</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Forganization%2Fprofile_image%2F6084%2Fd2633afb-5834-4976-913e-e4df77f6cd5c.png</url>
      <title>DEV Community: Sysdig</title>
      <link>https://dev.to/sysdig</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sysdig"/>
    <language>en</language>
    <item>
      <title>Top metrics for Elasticsearch monitoring with Prometheus</title>
      <dc:creator>Javier Martínez</dc:creator>
      <pubDate>Tue, 09 May 2023 08:18:13 +0000</pubDate>
      <link>https://dev.to/sysdig/top-metrics-for-elasticsearch-monitoring-with-prometheus-3pca</link>
      <guid>https://dev.to/sysdig/top-metrics-for-elasticsearch-monitoring-with-prometheus-3pca</guid>
      <description>&lt;p&gt;Starting the journey for Elasticsearch monitoring is crucial to get the right visibility and transparency over its behavior.&lt;/p&gt;

&lt;p&gt;Elasticsearch is the most used &lt;strong&gt;search and analytics engine&lt;/strong&gt;. It provides both scalability and redundancy to provide a high-availability search. As of 2023, more than sixty thousand companies of all sizes and backgrounds are using it as their search solution to track a diverse range of data, like analytics, logging, or business information.&lt;/p&gt;

&lt;p&gt;By distributing data in JSON documents and indexing that data into several shards, Elastic search provides high availability, quick search, and redundancy capabilities.&lt;/p&gt;

&lt;p&gt;In this article, we will evaluate the most important Prometheus metrics provided by the Elasticsearch exporter.&lt;/p&gt;

&lt;p&gt;You will learn what are the main areas to focus on when monitoring an Elasticsearch system:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Start monitoring Elasticsearch with Prometheus.&lt;/li&gt;



&lt;li&gt;How to monitor Golden Signals.&lt;/li&gt;



&lt;li&gt;How to monitor infra metrics.&lt;/li&gt;



&lt;li&gt;How to monitor index performance.&lt;/li&gt;



&lt;li&gt;How to monitor search performance.&lt;/li&gt;



&lt;li&gt;How to monitor cluster performance.&lt;/li&gt;



&lt;li&gt;Advanced monitoring and next steps&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id="start-monitoring"&gt;How to start monitoring ElasticSearch with Prometheus&lt;/h2&gt;

&lt;p&gt;As usual, the easiest way to start your Prometheus monitoring journey with Elasticsearch is to use &lt;a href="https://promcat.io" rel="noopener nofollow noreferrer"&gt;PromCat.io&lt;/a&gt; to find the best configs, dashboards, and alerts. The &lt;a href="https://promcat.io/apps/elasticsearch#SetupGuide" rel="noopener nofollow noreferrer"&gt;Elasticsearch setup guide in Promcat&lt;/a&gt; includes the Elasticsearch exporter with a series of out-of-box metrics that will be automatically scrapped to Prometheus. It also includes a collection of curated alerts and dashboards to start monitoring Elasticsearch right away.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZfNQKQOA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://sysdig.com/wp-content/uploads/Top-metrics-elasticsearch-image1-1170x383.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZfNQKQOA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://sysdig.com/wp-content/uploads/Top-metrics-elasticsearch-image1-1170x383.png" alt="Top metrics for Elasticsearch - metric list" title="image_tooltip" width="800" height="262"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can combine these metrics with the &lt;a href="https://sysdig.com/blog/exporters-and-target-labels/" rel="noopener"&gt;Node Exporter&lt;/a&gt; to get more insights into your infrastructure. Also, if you're running Elasticsearch on Kubernetes, you can &lt;a href="https://sysdig.es/blog/kubernetes-monitoring-prometheus/#kube-state-metrics" rel="noopener nofollow noreferrer"&gt;use KSM and CAdvisor&lt;/a&gt; to combine Kubernetes metrics with Elasticsearch metrics.&lt;/p&gt;

&lt;h2 id="monitor-golden-signals"&gt;How to monitor Golden Signals in Elasticsearch&lt;/h2&gt;

&lt;p&gt;To review a bare minimum of important metrics, remember to check the so-called &lt;a href="https://sysdig.com/blog/golden-signals-kubernetes/" rel="noopener"&gt;Golden Signals&lt;/a&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Errors.&lt;/li&gt;



&lt;li&gt;Traffic.&lt;/li&gt;



&lt;li&gt;Saturation.&lt;/li&gt;



&lt;li&gt;Latency.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These represent a set of the essential metrics to look for in a system, in order to track black-box monitoring (focus only on what’s happening in the system, not why). In other words, Golden Signals will measure symptoms, not solutions to the current problem. This could be a good starting point for creating an Elasticsearch monitoring dashboard.&lt;/p&gt;

&lt;h3&gt;Errors&lt;/h3&gt;

&lt;h5&gt;elasticsearch_cluster_health_status&lt;/h5&gt;

&lt;p&gt;Cluster health in Elasticsearch is measured by the colors green, yellow, and red, as follows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Green&lt;/strong&gt;: Data integrity is correct, no shard is missing.&lt;/li&gt;



&lt;li&gt;
&lt;strong&gt;Yellow&lt;/strong&gt;: There’s at least one shard missing, but data integrity can be preserved due to replicas.&lt;/li&gt;



&lt;li&gt;
&lt;strong&gt;Red&lt;/strong&gt;: A primary shard is missing or unassigned, and there’s a data loss.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;With &lt;code&gt;elasticsearch_cluster_health_status&lt;/code&gt;, you can quickly check the current situation for Elasticsearch data on a particular cluster. Remember that this won’t retrieve the actual causes of the data integrity loss, just that you need to act in order to prevent further problems.&lt;/p&gt;

&lt;h3&gt;Traffic&lt;/h3&gt;

&lt;h5&gt;elasticsearch_indices_search_query_total&lt;/h5&gt;

&lt;p&gt;This metric is a counter with the total number of search queries executed, which by itself won’t give you much information as a number.&lt;/p&gt;

&lt;p&gt;&lt;span&gt;&lt;em&gt;Consider as well using &lt;code&gt;rate()&lt;/code&gt; or &lt;code&gt;irate()&lt;/code&gt;, to detect sudden changes or spikes in traffic. Dig deeper into Prometheus queries with our &lt;a href="https://sysdig.com/blog/getting-started-with-promql-cheatsheet/" rel="noreferrer noopener"&gt;Getting started with PromQL guide&lt;/a&gt;&lt;/em&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;h3&gt;Saturation&lt;/h3&gt;

&lt;p&gt;For a detailed latency analysis, check the section on How to monitor Elasticsearch infra metrics.&lt;/p&gt;

&lt;h3&gt;Latency&lt;/h3&gt;

&lt;p&gt;For a detailed latency analysis, check the section on How to monitor Elasticsearch index performance.&lt;/p&gt;

&lt;h2 id="monitor-elasticsearch-infra-metrics"&gt;How to monitor Elasticsearch infra metrics&lt;/h2&gt;

&lt;p&gt;Infrastructure monitoring focuses on tracking the overall performance of the servers and nodes of a system. As with similar cloud applications, most of the effort will be spent on monitoring CPU and Memory consumption. &lt;/p&gt;

&lt;h3&gt;Monitoring Elasticsearch CPU&lt;/h3&gt;

&lt;h5&gt;elasticsearch_process_cpu_percent&lt;/h5&gt;

&lt;p&gt;This is a gauge metric used to measure the current CPU usage percent (0-100) of the Elasticsearch process. Since chances are that you’re running several Elasticsearch nodes, you will need to track each one separately.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--R1QaaKO---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://sysdig.com/wp-content/uploads/Top-metrics-elasticsearch-image2-1170x553.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--R1QaaKO---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://sysdig.com/wp-content/uploads/Top-metrics-elasticsearch-image2-1170x553.png" alt="Top metrics for Elasticsearch - CPU usage" title="image_tooltip" width="800" height="378"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h5&gt;elasticsearch_indices_store_throttle_time_seconds_total&lt;/h5&gt;

&lt;p&gt;In case you’re using a file system as an index store, you can expect a certain level of delays in input and output operations. This metric represents how much your Elasticsearch index store is being throttled.&lt;/p&gt;

&lt;p&gt;Since this is a counter metric that will only aggregate the total number of seconds, consider using &lt;code&gt;rate&lt;/code&gt; or &lt;code&gt;irate&lt;/code&gt; for an evaluation of how much it’s suddenly changing.&lt;/p&gt;

&lt;h3&gt;Monitoring Elasticsearch JVM Memory&lt;/h3&gt;

&lt;p&gt;Elasticsearch is based on &lt;a rel="noopener nofollow noreferrer" href="https://lucene.apache.org/"&gt;Lucene&lt;/a&gt;, which is built in Java. This means that monitoring the Java Virtual Machine (JVM) memory is crucial to understand the current usage of the whole system.&lt;/p&gt;

&lt;h5&gt;elasticsearch_jvm_memory_used_bytes&lt;/h5&gt;

&lt;p&gt;This metric is a gauge that represents the memory usage in bytes for each area.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7PmWYJ4H--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://sysdig.com/wp-content/uploads/Top-metrics-elasticsearch-image3-1170x455.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7PmWYJ4H--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://sysdig.com/wp-content/uploads/Top-metrics-elasticsearch-image3-1170x455.png" alt="Top metrics for Elasticsearch - Memory used" title="image_tooltip" width="800" height="311"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2 id="monitor-elasticsearch-index-performance"&gt;How to monitor Elasticsearch index performance&lt;/h2&gt;

&lt;p&gt;Indices in ElasticSearch partition the data as a logical namespace. Elasticsearch indexes documents in order to retrieve or search them as fast as possible.&lt;/p&gt;

&lt;p&gt;Every time a new index is created, you can define the number of shards and replicas for it:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;{
  "settings": {
    "number_of_shards": 1,
    "number_of_replicas": 1
  }
}&lt;/code&gt;&lt;/pre&gt;

&lt;h5&gt;elasticsearch_indices_indexing_index_time_seconds_total&lt;/h5&gt;

&lt;p&gt;This metric is a counter of the seconds accumulated spent on indexing. It can give you a very approximated idea of the Elasticsearch indexing performance.&lt;/p&gt;

&lt;p&gt;Note that you can divide this metric by elasticsearch_indices_indexing_index_total in order to get the average indexing time per operation.&lt;/p&gt;

&lt;h5&gt;elasticsearch_indices_refresh_time_seconds_total&lt;/h5&gt;

&lt;p&gt;For an index to be searchable, Elasticsearch needs a refresh to be executed. This is set up with the config index.refresh_interval, which is set by default to one minute.&lt;/p&gt;

&lt;p&gt;This metric elasticsearch_indices_refresh_time_seconds_total represents a counter with the total time dedicated to refreshing in Elasticsearch.&lt;/p&gt;

&lt;p&gt;In case you want to measure the average time for refresh, you can divide this metric by &lt;code&gt;elasticsearch_indices_refresh_total&lt;/code&gt;.&lt;/p&gt;

&lt;h2 id="monitor-elasticsearch-search-performance"&gt;How to monitor Elasticsearch search performance&lt;/h2&gt;

&lt;p&gt;While Elasticsearch promises near-instant query speed, chances are that in the real world, you may feel that is not the case. The number of shards, the storage solution chosen, or the cache configuration might impact search performance, and it’s crucial to track what is the current behavior.&lt;/p&gt;

&lt;p&gt;Additionally, the usage of wildcards, joins or the number of fields being searched will affect drastically the overall processing time of search queries.&lt;/p&gt;

&lt;h5&gt;elasticsearch_indices_search_fetch_time_seconds&lt;/h5&gt;

&lt;p&gt;A counter metric aggregating the total amount of seconds dedicated to fetching results in search.&lt;/p&gt;

&lt;p&gt;In case you want to retrieve the average fetch time per operation, just divide the result by &lt;code&gt;elasticsearch_indices_search_fetch_total&lt;/code&gt;.&lt;/p&gt;

&lt;h2 id="monitor-elasticsearch-cluster"&gt;How to monitor Elasticsearch cluster performance&lt;/h2&gt;

&lt;p&gt;Apart from the usual cloud requirements, an Elasticsearch system would like to look at:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Number of shards.&lt;/li&gt;



&lt;li&gt;Number of replicas.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As a rule of thumb, the ratio between the number of shards and GB of heap space should be less than 20.&lt;/p&gt;

&lt;p&gt;Note as well that it’s suggested to have a separate cluster dedicated to monitoring.&lt;/p&gt;

&lt;h5&gt;elasticsearch_cluster_health_active_shards&lt;/h5&gt;

&lt;p&gt;This metric is a gauge that will indicate the number of active shards (both primary and replicas) from all the clusters.&lt;/p&gt;

&lt;h5&gt;elasticsearch_cluster_health_relocating_shards&lt;/h5&gt;

&lt;p&gt;Elasticsearch will dynamically move shards between nodes based on balancing or current usage. With this metric, you can control when this movement is happening.&lt;/p&gt;

&lt;h2 id="advanced-monitoring"&gt;Advanced Monitoring&lt;/h2&gt;

&lt;p&gt;Remember that the Prometheus exporter will give you a set of out-of-the-box metrics that are relevant enough to kickstart your monitoring journey. But the real challenge comes when you take the step to create your own custom metrics tailored to your application.&lt;/p&gt;

&lt;h3&gt;REST API&lt;/h3&gt;

&lt;p&gt;Additionally, mind that Elasticsearch &lt;a rel="noopener nofollow noreferrer" href="https://www.elastic.co/guide/en/elasticsearch/reference/current/rest-apis.html"&gt;provides a REST API&lt;/a&gt; that you can query for more fine-grained monitoring.&lt;/p&gt;

&lt;h3&gt;VisualVM&lt;/h3&gt;

&lt;p&gt;The &lt;a rel="noopener nofollow noreferrer" href="https://visualvm.github.io/"&gt;Java VisualVM&lt;/a&gt; project is an advanced dashboard for Memory and CPU monitoring. It features advanced resource visualization, as well as process and thread utilization.&lt;/p&gt;

&lt;h2&gt;Download the Dashboards&lt;/h2&gt;

&lt;p&gt;You can download the dashboards with the metrics seen in this article &lt;a rel="noopener nofollow noreferrer" href="https://promcat.io/apps/elasticsearch"&gt;through the Promcat official page&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;This is a curated selection of the above metrics that can be easily integrated with your Grafana or Sysdig Monitor solution.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--cidTehhY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://sysdig.com/wp-content/uploads/Top-metrics-elasticsearch-image4-1170x739.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--cidTehhY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://sysdig.com/wp-content/uploads/Top-metrics-elasticsearch-image4-1170x739.png" alt="Top metrics for Elasticsearch - Grafana dashboards" title="image_tooltip" width="800" height="505"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;Elasticsearch is one of the most important search engines available, featuring high availability, high scalability, and distributed capabilities through redundancy.&lt;/p&gt;

&lt;p&gt;Using the Elasticsearch exporter for Prometheus you can kickstart the monitoring journey in an easy way, by automatically receiving the important metrics directly.&lt;/p&gt;

&lt;p&gt;As with many other applications, CPU, and Memory are crucial to understand system saturation. You should be aware of the current CPU throttling and the memory handling of the JVM.&lt;/p&gt;

&lt;p&gt;Finally, it’s important to dig deeper into the particularities of Elasticsearch, like indices and search capabilities, to truly understand the challenges of monitoring and visualization.&lt;/p&gt;





</description>
      <category>elasticsearch</category>
      <category>prometheus</category>
      <category>monitoring</category>
      <category>devops</category>
    </item>
    <item>
      <title>Kubernetes CreateContainerConfigError and CreateContainerError</title>
      <dc:creator>Javier Martínez</dc:creator>
      <pubDate>Thu, 23 Mar 2023 15:58:05 +0000</pubDate>
      <link>https://dev.to/sysdig/kubernetes-createcontainerconfigerror-and-createcontainererror-1o5a</link>
      <guid>https://dev.to/sysdig/kubernetes-createcontainerconfigerror-and-createcontainererror-1o5a</guid>
      <description>&lt;p&gt;CreateContainerConfigError and CreateContainerError are two of the most prevalent Kubernetes errors found in cloud-native applications.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CreateContainerConfigError&lt;/strong&gt; is an error happening when the &lt;strong&gt;configuration specified for a container in a Pod is not correct&lt;/strong&gt; or is missing a vital part.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CreateContainerError&lt;/strong&gt; is a problem happening&lt;strong&gt; at a later stage&lt;/strong&gt; in the container creation flow. Kubernetes displays this error when it attempts to create the container in the Pod.&lt;/p&gt;

&lt;p&gt;In this article, you will learn:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What is Kubernetes CreateContainerConfigError?&lt;/li&gt;



&lt;li&gt;What is Kubernetes CreateContainerError?&lt;/li&gt;



&lt;li&gt;Kubernetes container creation flow&lt;/li&gt;



&lt;li&gt;Common causes for CreateContainerError and CreateConfigError&lt;/li&gt;



&lt;li&gt;How to troubleshoot both errors&lt;/li&gt;



&lt;li&gt;How to detect both errors in Prometheus&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id="what-is-createcontainerconfigerror"&gt;What is CreateContainerConfigError?&lt;/h2&gt;

&lt;p&gt;During the process to start a new container, Kubernetes first tries to generate the configuration for it. In fact, this is handled internally by calling a method called &lt;em&gt;generateContainerConfig&lt;/em&gt;, which will try to retrieve:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Container command and arguments&lt;/li&gt;



&lt;li&gt;Relevant persistent volumes for the container&lt;/li&gt;



&lt;li&gt;Relevant ConfigMaps for the container&lt;/li&gt;



&lt;li&gt;Relevant secrets for the container&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Any problem in the elements above will result in a CreateContainerConfigError.  &lt;/p&gt;

&lt;h2 id="what-is-createcontainererror"&gt;What is CreateContainerError?&lt;/h2&gt;

&lt;p&gt;Kubernetes throws a CreateContainerError when there’s a problem in the creation of the container, but unrelated with configuration, like a referenced volume not being accessible or a container name already being used.&lt;/p&gt;

&lt;p&gt;&lt;span&gt;&lt;em&gt;Similar to other problems like &lt;a href="https://sysdig.com/blog/debug-kubernetes-crashloopbackoff/" rel="noopener noreferrer"&gt;CrashLoopBackOff&lt;/a&gt;, this article only covers the most common causes, but there are many others depending on your current application.&lt;/em&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;h2&gt;How you can detect CreateContainerConfigError and CreateContainerError&lt;/h2&gt;

&lt;p&gt;You can detect both errors by running kubectl get pods:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;NAME  READY STATUS                     RESTARTS AGE

mypod 0/1   CreateContainerConfigError 0        11m&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;As you can see from this output:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Pod is not ready: container has an error.&lt;/li&gt;



&lt;li&gt;There are no restarts: these two errors are not like CrashLoopBackOff, where automatic retrials are in place.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id="container-creation-flow"&gt;Kubernetes container creation flow&lt;/h2&gt;

&lt;p&gt;In order to understand CreateContainerError and CreateContainerConfligError, we need to first know the exact flow for container creation.&lt;/p&gt;

&lt;p&gt;Kubernetes follows the next steps every time a new container needs to be started:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Pull the image.&lt;/li&gt;



&lt;li&gt;Generate container configuration.&lt;/li&gt;



&lt;li&gt;Precreate container.&lt;/li&gt;



&lt;li&gt;Create container.&lt;/li&gt;



&lt;li&gt;Pre-start container.&lt;/li&gt;



&lt;li&gt;Start container.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;As you can see, steps 2 and 4 are where a CreateContainerConfig and CreateContainerErorr might appear, respectively.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://sysdig.com/wp-content/uploads/Createcontainererror-02-1170x464.png" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsysdig.com%2Fwp-content%2Fuploads%2FCreatecontainererror-02-1170x464.png" alt="Create container and start container flow"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2 id="common-causes-createcontainerconfigerror"&gt;Common causes for CreateContainerError and CreateContainerConfigError&lt;/h2&gt;

&lt;h3&gt;Not found ConfigMap&lt;/h3&gt;

&lt;p&gt;Kubernetes &lt;a href="https://kubernetes.io/docs/concepts/configuration/configmap/" rel="noopener noreferrer"&gt;ConfigMaps&lt;/a&gt; are a key element to store non-confidential information to be used by Pods as key-value pairs.&lt;/p&gt;

&lt;p&gt;When adding a ConfigMap reference in a Pod, you are effectively indicating that it should retrieve specific data from it. But, if a Pod references a non-existent ConfigMap, Kubernetes will return a CreateContainerConfigError.&lt;/p&gt;

&lt;h3&gt;Not found Secret&lt;/h3&gt;

&lt;p&gt;Secrets are a more secure manner to store sensitive information in Kubernetes. Remember, though, this is just raw data encoded in base64, so it’s not really encrypted, just obfuscated.&lt;/p&gt;

&lt;p&gt;In case a Pod contains a reference to a non-existent secret, Kubelet will throw a CreateContainerConfigError, indicating that necessary data couldn’t be retrieved in order to form container config.&lt;/p&gt;

&lt;h3&gt;Container name already in use&lt;/h3&gt;

&lt;p&gt;While an unusual situation, in some cases a conflict might occur because a particular container name is already being used. Since every docker container should have a unique name, you will need to either delete the original or rename the new one being created.&lt;/p&gt;

&lt;h2 id="troubleshoot"&gt;How to troubleshoot CreateContainerError and CreateContainerConfigError&lt;/h2&gt;

&lt;p&gt;While the causes for an error in container creation might vary, you can always rely on the following methods to troubleshoot the problem that’s preventing the container from starting.&lt;/p&gt;

&lt;h3&gt;Describe Pods&lt;/h3&gt;

&lt;p&gt;With &lt;code&gt;kubectl describe pod&lt;/code&gt;, you can retrieve the detailed information for the affected Pod and its containers:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Containers:
  mycontainer:
    Container ID:
    Image:          nginx
    Image ID:
    Port:           &amp;lt;none&amp;gt;
    Host Port:      &amp;lt;none&amp;gt;
    State:          Waiting
      Reason:       CreateContainerConfigError
    Ready:          False
    Restart Count:  0
    Limits:
      cpu:  3
---
Volumes:
  config:
    Type:      ConfigMap (a volume populated by a ConfigMap)
    Name:      myconfigmap
    Optional:  false&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;Get logs from containers&lt;/h3&gt;

&lt;p&gt;Use &lt;code&gt;kubectl logs&lt;/code&gt; to retrieve the log information from containers in the Pod. Note that for Pods with multiple containers, you need to use the &lt;code&gt;–all-containers&lt;/code&gt; parameter:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Error from server (BadRequest): container "mycontainer" in pod "mypod" is waiting to start: CreateContainerConfigError&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;Check the events&lt;/h3&gt;

&lt;p&gt;You can also run &lt;code&gt;kubectl get events&lt;/code&gt; to retrieve all the recent events happening in your Pods. Remember that the describe pods command also displays the particular events at the end.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://sysdig.com/wp-content/uploads/Createcontainererror-03-1170x586.png" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsysdig.com%2Fwp-content%2Fuploads%2FCreatecontainererror-03-1170x586.png" alt="Createcontainerconfig error troubleshooting diagram"&gt;&lt;/a&gt;Terminal windows for the kubectl commands used to troubleshoot a CreateContainerConfigError&lt;/p&gt;



&lt;h2 id="detect-in-prometheus"&gt;How to detect CreateContainerConfigError and CreateContainerError in Prometheus&lt;/h2&gt;

&lt;p&gt;When using Prometheus + kube-state-metrics, you can quickly retrieve Pods that have containers with errors at creation or config steps:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;kube_pod_container_status_waiting_reason{reason="CreateContainerConfigError"} &amp;gt; 0
kube_pod_container_status_waiting_reason{reason="CreateContainerError"} &amp;gt; 0&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;a href="https://sysdig.com/wp-content/uploads/image2-53-1170x997.png" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsysdig.com%2Fwp-content%2Fuploads%2Fimage2-53-1170x997.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2 id="other-errors"&gt;Other similar errors&lt;/h2&gt;

&lt;h3&gt;Pending&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://sysdig.com/blog/kubernetes-pod-pending-problems/" rel="noopener noreferrer"&gt;Pending is a Pod status&lt;/a&gt; that appears when the Pod couldn’t even be started. Note that this happens at schedule time, so Kube-scheduler couldn’t find a node because of not enough resources or not proper taints/tolerations config.&lt;/p&gt;

&lt;h3&gt;ContainerCreating&lt;/h3&gt;

&lt;p&gt;ContainerCreating is another waiting status reason that can happen when the container could not be started because of a problem in the execution (e.g: &lt;code&gt;No command specified&lt;/code&gt;)&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Error from server (BadRequest): container "mycontainer" in pod "mypod" is waiting to start: ContainerCreating   &lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;RunContainerError&lt;/h3&gt;

&lt;p&gt;This might be a similar situation to CreateContainerError, but note that this happens during the run step and not the container creation step.&lt;/p&gt;

&lt;p&gt;A RunContainerError most likely points to problems happening at runtime, like attempts to write on a read-only volume.&lt;/p&gt;

&lt;h3&gt;CrashLoopBackOff&lt;/h3&gt;

&lt;p&gt;Remember that &lt;a href="https://sysdig.com/blog/debug-kubernetes-crashloopbackoff/" rel="noopener noreferrer"&gt;CrashLoopBackOff&lt;/a&gt; is not technically an error, but the waiting time grace period that is added between retrials.&lt;/p&gt;

&lt;p&gt;Unlike CrashLoopBackOff events, CreateContainerError and CreateContainerConfigError won’t be retried automatically.&lt;/p&gt;

&lt;h2&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;In this article, you have seen how both CreateContainerConfigError and CreateContainerError are important messages in the Kubernetes container creation process. Being able to detect them and understand at which stage they are happening is crucial for the day-to-day debugging of cloud-native services.&lt;/p&gt;

&lt;p&gt;Also, it’s important to know the internal behavior of the Kubernetes container creation flow and what is errors might appear at each step.&lt;/p&gt;

&lt;p&gt;Finally, CreateContainerConfigError and CreateContainerError might be mistaken with other different Kubernetes errors, but these two happen at container creation stage and they are not automatically retried.&lt;/p&gt;









&lt;h2&gt;&lt;em&gt;Troubleshoot CreateContainerError with Sysdig Monitor
&lt;/em&gt;&lt;/h2&gt;
&lt;p&gt;With Sysdig Monitor’s Advisor, you can easily detect which containers are having CreateContainerConfigError or CreateContainerError problems in your Kubernetes cluster.&lt;/p&gt;

&lt;p&gt;Advisor accelerates mean time to resolution (MTTR) with live logs, performance data, and suggested remediation steps. It’s the easy button for Kubernetes troubleshooting!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://sysdig.com/wp-content/uploads/image3-39-1170x579.png" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsysdig.com%2Fwp-content%2Fuploads%2Fimage3-39-1170x579.png" alt="Rightsize your Kubernetes Resources with Sysdig Monitor"&gt;&lt;/a&gt;&lt;/p&gt;


&lt;p&gt;&lt;a href="https://sysdig.com/start-free/" rel="noopener noreferrer"&gt;Try it free&lt;/a&gt; for 30 days!&lt;/p&gt;

</description>
      <category>kubernetes</category>
      <category>monitoring</category>
      <category>cloud</category>
      <category>devops</category>
    </item>
    <item>
      <title>Monitoring with Custom Metrics</title>
      <dc:creator>Javier Martínez</dc:creator>
      <pubDate>Thu, 02 Mar 2023 10:19:53 +0000</pubDate>
      <link>https://dev.to/sysdig/monitoring-with-custom-metrics-p52</link>
      <guid>https://dev.to/sysdig/monitoring-with-custom-metrics-p52</guid>
      <description>&lt;p&gt;&lt;strong&gt;Custom metrics&lt;/strong&gt; are application-level or business-related tailored metrics, as opposed to the ones that come directly out-of-the-box from monitoring systems like Prometheus (e.g: kube-state-metrics or node exporter)&lt;/p&gt;

&lt;p&gt;By kickstarting a monitoring project with Prometheus, you might realize that you get an initial set of out-of-the-box metrics with just Node Exporter and Kube State Metrics. But, this will only get you so far since you will just be performing black box monitoring. How can you go to the next level and observe what’s beyond?&lt;/p&gt;

&lt;p&gt;They are an essential part of the day-to-day monitoring of cloud-native systems, as they provide an additional dimension to the business and app level.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Metrics provided by an exporter&lt;/li&gt;



&lt;li&gt;Tailored metrics designed by the customer&lt;/li&gt;



&lt;li&gt;An aggregate from previous existing metrics&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In this article, you will see:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt; &lt;a href="https://docs.google.com/document/d/19Z6q_lY60IqRz4DcnubmU4U1HwjxBPJJy3q_okC6-rE/edit#heading=h.hl0n2legtxy2"&gt;Why custom metrics are important&lt;/a&gt;
&lt;/li&gt;



&lt;li&gt;&lt;a href="https://docs.google.com/document/d/19Z6q_lY60IqRz4DcnubmU4U1HwjxBPJJy3q_okC6-rE/edit#heading=h.1pkldw1lpoee"&gt;When to use custom metrics&lt;/a&gt;&lt;/li&gt;



&lt;li&gt;&lt;a href="https://docs.google.com/document/d/19Z6q_lY60IqRz4DcnubmU4U1HwjxBPJJy3q_okC6-rE/edit#heading=h.7o1c1smwtm7b"&gt;Considerations when creating custom metrics&lt;/a&gt;&lt;/li&gt;



&lt;li&gt;&lt;a href="https://docs.google.com/document/d/19Z6q_lY60IqRz4DcnubmU4U1HwjxBPJJy3q_okC6-rE/edit#heading=h.8hxg63te0986"&gt;Kubernetes Metric API&lt;/a&gt;&lt;/li&gt;



&lt;li&gt;&lt;a href="https://docs.google.com/document/d/19Z6q_lY60IqRz4DcnubmU4U1HwjxBPJJy3q_okC6-rE/edit#heading=h.q5qjsc4mpwar"&gt;Prometheus custom metrics&lt;/a&gt;&lt;/li&gt;



&lt;li&gt;&lt;a href="https://docs.google.com/document/d/19Z6q_lY60IqRz4DcnubmU4U1HwjxBPJJy3q_okC6-rE/edit#heading=h.lfrto1shfhfv"&gt;Challenges when using custom metrics&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;Why custom metrics are important&lt;/h2&gt;

&lt;p&gt;Custom metrics allow companies to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Monitor Key Performance Indicators (KPIs).&lt;/li&gt;



&lt;li&gt;Detect issues faster.&lt;/li&gt;



&lt;li&gt;Track resource utilization.&lt;/li&gt;



&lt;li&gt;Measure latency.&lt;/li&gt;



&lt;li&gt;Track specific values from their services and systems.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Examples of custom metrics:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Latency of transactions in milliseconds.&lt;/li&gt;



&lt;li&gt;Database open connections.&lt;/li&gt;



&lt;li&gt;% cache hits / cache misses.&lt;/li&gt;



&lt;li&gt;orders/sales in e-commerce site.&lt;/li&gt;



&lt;li&gt;% of slow responses.&lt;/li&gt;



&lt;li&gt;% of responses that are resource intensive.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As you can see, any metrics retrieved from an exporter or created ad hoc will fit into the definition for custom metric.&lt;/p&gt;

&lt;h2&gt;When to use Custom Metrics&lt;/h2&gt;

&lt;h3&gt;Autoscaling&lt;/h3&gt;

&lt;p&gt;By providing specific visibility over your system, you can define rules on how the workload should scale.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Horizontal autoscaling: add or remove replicas of a Pod.&lt;/li&gt;



&lt;li&gt;Vertical autoscaling: modify limits and requests of a container.&lt;/li&gt;



&lt;li&gt;Cluster autoscaling: add or remove nodes in a cluster.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you want to dig deeper, check &lt;a href="https://sysdig.com/blog/kubernetes-autoscaler/" rel="noopener"&gt;this article about autoscaling in Kubernetes&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;Latency monitoring&lt;/h3&gt;

&lt;p&gt;Latency measures the time it takes for a system to serve a request. This monitoring &lt;a href="https://sysdig.com/blog/golden-signals-kubernetes/" rel="noopener"&gt;golden signal&lt;/a&gt; is essential to understand what the end-user experience for your application is.&lt;/p&gt;

&lt;p&gt;These are considered custom metrics as they are not part of the out-of-the-box set of metrics coming from Kube State Metrics or Node Exporter. In order to measure latency, you might want to either track individual systems (database, API) or end-to-end.&lt;/p&gt;

&lt;h3&gt;Application level monitoring&lt;/h3&gt;

&lt;p&gt;Kube-state-metrics or node-exporter might be a good &lt;a href="https://sysdig.com/blog/cloud-monitoring-journey/" rel="noopener"&gt;starting point for observability&lt;/a&gt;, but they just scratch the surface as they perform black-box monitoring. By instrumenting your own application and services, you create a curated and personalized set of metrics for your own particular case.&lt;/p&gt;

&lt;h2&gt;Considerations when creating Custom Metrics&lt;/h2&gt;

&lt;h3&gt;Naming&lt;/h3&gt;

&lt;p&gt;Check for any &lt;a href="https://prometheus.io/docs/practices/naming/" rel="noreferrer noopener"&gt;existing convention on naming&lt;/a&gt;, as they might be either colliding with existing names or confusing. Custom metric name is the first description for its purpose.&lt;/p&gt;

&lt;h3&gt;Labels&lt;/h3&gt;

&lt;p&gt;Thanks to labels, we can add parameters to our metrics, as we will be able to filter and refine through additional characteristics. Cardinality is the number of possible values for each label and since each combination of possible values will require a time series entry, that can increase resources drastically. Choosing the correct labels carefully is key to avoiding this cardinality explosion, which is one of the causes of resource spending spikes.&lt;/p&gt;

&lt;h3&gt;Costs&lt;/h3&gt;

&lt;p&gt;Custom metrics may have some costs associated with them depending on the monitoring system you are using. Double-check what is the dimension used to scale costs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Number of time series&lt;/li&gt;



&lt;li&gt;Number of labels&lt;/li&gt;



&lt;li&gt;Data storage&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;Custom Metric lifecycle&lt;/h3&gt;

&lt;p&gt;In case the Custom Metric is related to a job or a short-living script, consider using &lt;a href="https://github.com/prometheus/pushgateway" rel="noopener nofollow noreferrer"&gt;Pushgateway&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;Kubernetes Metric API&lt;/h2&gt;

&lt;p&gt;One of the most important features of Kubernetes is the ability to scale the workload based on the values of metrics automatically.&lt;/p&gt;

&lt;p&gt;Metrics API are defined in the &lt;a rel="noopener nofollow noreferrer" href="https://github.com/kubernetes/metrics"&gt;official repository from Kubernetes&lt;/a&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;metrics.k8s.io&lt;/code&gt;&lt;/li&gt;



&lt;li&gt;&lt;code&gt;custom.metrics.k8s.io&lt;/code&gt;&lt;/li&gt;



&lt;li&gt;&lt;code&gt;external.metrics.k8s.io&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;Creating new metrics&lt;/h3&gt;

&lt;p&gt;You can set new metrics by calling the K8s metrics API as follows:&lt;/p&gt;

&lt;pre&gt;curl -X POST \
  -H 'Content-Type: application/json' \
  http://localhost:8001/api/v1/namespaces/custom-metrics/services/custom-metrics-apiserver:http/proxy/write-metrics/namespaces/default/services/kubernetes/test-metric \
  --data-raw '"300m"'
&lt;/pre&gt;

&lt;h2&gt;Prometheus custom metrics&lt;/h2&gt;

&lt;p&gt;As we mentioned, every exporter that we include in our Prometheus integration will account for several custom metrics.&lt;/p&gt;

&lt;p&gt;Check the following post for a &lt;a href="https://sysdig.com/blog/prometheus-metrics/" rel="noopener"&gt;detailed guide on Prometheus metrics&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;Challenges when using custom metrics&lt;/h2&gt;

&lt;h3&gt;Cardinality explosion&lt;/h3&gt;

&lt;p&gt;While the resources consumed by some metrics might be negligible, the moment these are available to be used with labels in queries, things might get out of hand.&lt;/p&gt;

&lt;p&gt;Cardinality refers to the cartesian products of metrics and labels. The result will be the amount of time series entries that need to be used for that single metric.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0nVj2Ktr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://sysdig.com/wp-content/uploads/Custom-metrics-image-1-1-1170x644.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0nVj2Ktr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://sysdig.com/wp-content/uploads/Custom-metrics-image-1-1-1170x644.png" alt="Custom metrics - cardinality example" width="880" height="484"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Also, every metric will be scraped and stored in a time series database based on your &lt;code&gt;scrape_interval.&lt;/code&gt; The higher this value, the higher the amount of time series entries.&lt;/p&gt;

&lt;p&gt;All these factors will eventually lead to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Higher resource consumption.&lt;/li&gt;



&lt;li&gt;Higher storage demand.&lt;/li&gt;



&lt;li&gt;Monitoring performance degradation.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Moreover, most common monitoring tools don’t give &lt;a href="https://sysdig.com/use-cases/cloud-monitoring/" rel="noopener"&gt;visibility on current cardinality of metrics or costs associated&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;Exporter over usage&lt;/h3&gt;

&lt;p&gt;Exporters are a great way to include relevant metrics to your system. With them, you can easily instrument relevant metrics bound to your microservices and containers. But with great power comes great responsibility. Chances are that many of the metrics included in the package may not be relevant to your business at all.&lt;/p&gt;

&lt;p&gt;By enabling custom metrics and exporters in your solution, you may end up having a burst in the amount of time series database entries.&lt;/p&gt;

&lt;h3&gt;Cost spikes&lt;/h3&gt;

&lt;p&gt;Because of the elements explained above, monitoring costs could increase suddenly, as your current solution might be consuming more resources than expected, or your current monitoring solution has certain thresholds that were surpassed.&lt;/p&gt;

&lt;h3&gt;Alert fatigue&lt;/h3&gt;

&lt;p&gt;With metrics, most companies and individuals would love to start adding alerts and notifications when their values exceed certain thresholds. However, this could lead to higher notification sources and a reduced attention span.&lt;br&gt;Learn more about &lt;a href="sysdig.com/blog//prometheus-alertmanager" rel="noopener"&gt;Alert Fatigue and how to mitigate it&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;Custom metrics represent the next step for cloud-native monitoring as they represent the core of business observability. While using Prometheus along kube-state-metrics and node exporter is a nice starting step, eventually companies and organizations will need to take the next step and create tailored and on-point metrics to suit their needs.&lt;/p&gt;

</description>
      <category>prometheus</category>
      <category>monitoring</category>
      <category>devops</category>
    </item>
    <item>
      <title>ChatGPT creating OSS security rules and plugins</title>
      <dc:creator>Miguel</dc:creator>
      <pubDate>Mon, 27 Feb 2023 09:44:31 +0000</pubDate>
      <link>https://dev.to/sysdig/chatgpt-creating-security-rules-and-plugins-5g23</link>
      <guid>https://dev.to/sysdig/chatgpt-creating-security-rules-and-plugins-5g23</guid>
      <description>&lt;p&gt;Can &lt;a href="https://openai.com/blog/chatgpt/" rel="noopener noreferrer"&gt;OpenAI ChatGPT&lt;/a&gt; become a contributor for an open source project like &lt;a href="https://falco.org/" rel="noopener noreferrer"&gt;Falco&lt;/a&gt;? Is this the end of GitHub Copilot?&lt;/p&gt;

&lt;p&gt;ChatGPT is SO trendy that I overheard my grandma talking about it to her friends the other day. We’re seeing more and more uses of this AI for real world applications. That made us think…&lt;/p&gt;

&lt;p&gt;Falco, the first runtime security project to join CNCF as an incubation-level project, needs contributors. Would OpenAI’s ChatGPT language model be able to write security rules or plugins for Falco, and become a contributor?&lt;/p&gt;

&lt;h3&gt;
  
  
  ChatGPT as a potential new Falco partner
&lt;/h3&gt;

&lt;p&gt;Jokes aside, in this article we explore the viability of ChatGPT as a tool for organizations to create effective and efficient security rules. Would those new rules in Falco ensure their containers and hosts are protected from potential threats?&lt;/p&gt;

&lt;h2&gt;
  
  
  What is runtime security for ChatGPT?
&lt;/h2&gt;

&lt;p&gt;In order to begin, we need to understand &lt;a href="https://sysdig.com/learn-cloud-native/kubernetes-security/runtime-security/" rel="noopener noreferrer"&gt;what runtime security is&lt;/a&gt;. Rather than using a search engine, we will ask ChatGPT in order to speed up the process. &lt;/p&gt;

&lt;p&gt;According to ChatGPT:&lt;/p&gt;

&lt;p&gt; “&lt;em&gt;Runtime security involves monitoring and protecting software systems in&lt;/em&gt; &lt;strong&gt;&lt;em&gt;real-time&lt;/em&gt;&lt;/strong&gt; &lt;em&gt;as they are running, detecting, and responding to security threats, and implementing mitigation techniques to prevent further damage. The goal of runtime security is to&lt;/em&gt; &lt;strong&gt;&lt;em&gt;identify and respond&lt;/em&gt;&lt;/strong&gt; &lt;em&gt;to security threats and vulnerabilities&lt;/em&gt; &lt;strong&gt;&lt;em&gt;before they can be exploited and cause harm&lt;/em&gt;&lt;/strong&gt;&lt;em&gt;.&lt;/em&gt;”&lt;/p&gt;

&lt;p&gt;&lt;a href="https://sysdig.com/wp-content/uploads/image-27.png" rel="noopener noreferrer"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsysdig.com%2Fwp-content%2Fuploads%2Fimage-27-1170x855.png" alt="ChatGPT: What is runtime security?" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A good definition, but let’s see if we can go deeper.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Falco for ChatGPT?
&lt;/h2&gt;

&lt;p&gt;ChatGPT summarized the open source project Falco in a clear and concise manner. &lt;/p&gt;

&lt;p&gt;Rather than copying the information from the landing page of &lt;a href="https://falco.org/" rel="noopener noreferrer"&gt;falco.org&lt;/a&gt;, ChatGPT provided useful context as to how Falco utilizes eBPF to achieve low-overhead when detecting security threats from data collected within the Linux Kernel. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://sysdig.com/wp-content/uploads/image-28-1170x683.png" rel="noopener noreferrer"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsysdig.com%2Fwp-content%2Fuploads%2Fimage-28-1170x683.png" alt="Chatgpt what is Falco" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;At this point, we understand what runtime security is, and how Falco can be used to detect anomalous runtime security issues. Now that we are familiar with open source Falco, let’s ask ChatGPT to write us some useful Falco rules.&lt;/p&gt;

&lt;h2&gt;
  
  
  Asking ChatGPT to create a Falco rule
&lt;/h2&gt;

&lt;p&gt;Now, let’s ask ChatGPT if the language model is capable of writing OSS Falco security rules. &lt;/p&gt;

&lt;p&gt;Based on the below screenshot, &lt;strong&gt;does ChatGPT looks like a useful contributor to the Falco community?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://sysdig.com/wp-content/uploads/image-29.png" rel="noopener noreferrer"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsysdig.com%2Fwp-content%2Fuploads%2Fimage-29-1170x820.png" alt="Chatgpt Falco rule" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;At this point, we are happy with the answer that was returned. &lt;/p&gt;

&lt;p&gt;There was a correctly-formatted Falco rule and the language model also returned some added context as to how the rule will work. &lt;/p&gt;

&lt;p&gt;My only concern is that the first rule they created is similar to a rule that already exists in the &lt;a href="https://github.com/falcosecurity/rules/blob/c558fc7d2d02cc2c2edc968fe5770d544f1a9d55/rules/falco_rules.yaml#L2060" rel="noopener noreferrer"&gt;Falco community rules feed&lt;/a&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;- rule: Terminal shell in container
  desc: A shell was used as the entrypoint/exec point into a container with an attached terminal.
  condition: &amp;gt;
    spawned_process and container
    and shell_procs and proc.tty != 0
    and container_entrypoint
    and not user_expected_terminal_shell_in_container_conditions
  output: &amp;gt;
    A shell was spawned in a container with an attached terminal (user=%user.name user_loginuid=%user.loginuid %container.info
    shell=%proc.name parent=%proc.pname cmdline=%proc.cmdline pid=%proc.pid terminal=%proc.tty container_id=%container.id image=%container.image.repository)
  priority: NOTICE
  tags: [container, shell, mitre_execution, T1059]Code language: Perl (perl)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above Falco community rule includes different use cases; proc.name is not just sh, it is a long list which is contained in shell_procs. As a result, this would lead to fewer false/positive detections and reduce the attackers’ chances of bypassing the rule. If the rules are too generic, it can potentially capture expected behavior.&lt;/p&gt;

&lt;p&gt;When asking our questions to ChatGPT, we need to be more precise to generate an accurate rule. For example, we would ask ChatGPT to create a Falco rule that detects suspicious login activity on a Linux workstation between certain hours of the day.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://sysdig.com/wp-content/uploads/image-30.png" rel="noopener noreferrer"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsysdig.com%2Fwp-content%2Fuploads%2Fimage-30-1170x918.png" alt="Chatgpt Falco OSS rule" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Again, we like how the rule looks. &lt;/p&gt;

&lt;p&gt;Since Falco is designed to handle Linux system calls, there is no need to explicitly mention the workstation OS type. However, ChatGPT nicely mentioned that the rule triggers for activity on Linux workstations because we specifically requested this. We will copy the code snippet and paste it below so that we can dissect it further:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;- rule: Detect suspicious login activity during off-hours
  desc: Detects login sessions initiated during off-hours on a Linux workstation
  condition: (evt.time &amp;gt; "2022-12-31T02:00:00.000Z" and evt.time &amp;lt; "2022-12-31T07:00:00.000Z") and (evt.type=execve and evt.argc=3 and evt.argv[2]=login)
  output: Suspicious login activity detected during off-hours: user=%user.name command=%proc.cmdline
  priority: WARNINGCode language: Perl (perl)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The Falco rule uses the below system call activity:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; &lt;a href="https://man7.org/linux/man-pages/man8/sysdig.8.html#:~:text=evt.time%20is%20the%20event%20timestamp" rel="noopener noreferrer"&gt;evt.time&lt;/a&gt; – This is the event timestamp. It’s between T02:00 (2 a.m.) and T07:00 (7 a.m.).&lt;/li&gt;
&lt;li&gt; &lt;a href="https://man7.org/linux/man-pages/man8/sysdig.8.html#:~:text=evt.type%20is%20the%20name%20of%20the%20event%2C%20e.g.%20%20%27open%27%20or%20%27read%27" rel="noopener noreferrer"&gt;evt.type&lt;/a&gt; – This is the name of the event, for example, ‘open’ or ‘read.’ In this case, it’s &lt;a href="https://man7.org/linux/man-pages/man2/execve.2.html" rel="noopener noreferrer"&gt;execve&lt;/a&gt;. The execve event executes the program referred to by pathname.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If you are ever unsure about a certain argument used, what it means, or how to use it going forward, you can ask ChatGPT to elaborate on its findings without re-writing the entire question.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://sysdig.com/wp-content/uploads/image-31.png" rel="noopener noreferrer"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsysdig.com%2Fwp-content%2Fuploads%2Fimage-31-1170x918.png" alt="ChatGPT evt.argc and evt.argv" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Since ChatGPT is a language model, it does a great job of not just providing rules, but also providing clarity on its findings. With this additional context provided by ChatGPT, we are happy with how this rule turned out. &lt;/p&gt;

&lt;p&gt;Since we don’t have any business need for this specific rule, let’s use ChatGPT to solve some real business problems.&lt;/p&gt;

&lt;h2&gt;
  
  
  ChatGPT, MITRE ATT&amp;amp;CK, and Falco
&lt;/h2&gt;

&lt;p&gt;Continuing the conversation, we got more technical with ChatGPT and tried to combine two areas of expertise: Falco and MITRE.&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://attack.mitre.org/matrices/enterprise/" rel="noopener noreferrer"&gt;MITRE ATT&amp;amp;CK framework&lt;/a&gt; for Enterprise environments is BIG! As a result, it can be hard to provide extensive coverage of all Tactics, Techniques, and Sub-Techniques for Linux Systems. &lt;/p&gt;

&lt;p&gt;Since ChatGPT can read and interpret large values of operational data, it speeds up the process of building Falco rules to better align with this widely-used risk framework.&lt;/p&gt;

&lt;p&gt;In the &lt;a href="https://github.com/falcosecurity/rules/blob/c558fc7d2d02cc2c2edc968fe5770d544f1a9d55/rules/falco_rules.yaml" rel="noopener noreferrer"&gt;Falco community rules feed&lt;/a&gt;, there was no existing rule aligned to the Technique ID ‘&lt;a href="https://attack.mitre.org/techniques/T1529/" rel="noopener noreferrer"&gt;T1529&lt;/a&gt;.’ For this technique ID, the adversaries may shutdown or reboot the workstation to interrupt access to workstations, or aid in the destruction of those systems. When requesting a rule that detects system shutdown or reboot, we also want to request the appropriate tagging for rules alignment with the MITRE ATT&amp;amp;CK framework. Surprisingly, &lt;strong&gt;ChatGPT answered with an incorrect tactic and technique associated with that technique ID&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://sysdig.com/wp-content/uploads/image-33.png" rel="noopener noreferrer"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsysdig.com%2Fwp-content%2Fuploads%2Fimage-33-1170x918.png" alt="ChatGPT Falco MITRE" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The technique &lt;a href="https://attack.mitre.org/techniques/T1538/" rel="noopener noreferrer"&gt;&lt;strong&gt;Cloud Service Dashboard&lt;/strong&gt;&lt;/a&gt; is assigned to the Tactic ‘&lt;strong&gt;Discovery&lt;/strong&gt;’ and the associated Technique ID T1538. Whereas, the technique ID T1529 is associated with &lt;a href="https://attack.mitre.org/techniques/T1529/" rel="noopener noreferrer"&gt;&lt;strong&gt;shutdown/reboot activity&lt;/strong&gt;&lt;/a&gt;, this would be aligned with the Tactic ‘&lt;strong&gt;Impact&lt;/strong&gt;.’ &lt;/p&gt;

&lt;p&gt;For the first time, ChatGPT made an obvious mistake in its answer. When we confronted ChatGPT, it immediately apologized and provided an amended answer that looks more like the Falco rule we would expect.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://sysdig.com/wp-content/uploads/image-32.png" rel="noopener noreferrer"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsysdig.com%2Fwp-content%2Fuploads%2Fimage-32-1170x918.png" alt="ChatGPT Falco MITRE wrong" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This regained my trust in ChatGPT becoming an approved Falco contributor. &lt;/p&gt;

&lt;p&gt;However, since we cannot guarantee that ChatGPT is going to return the correct rule, we also need to validate that the rule conditions are valid.&lt;/p&gt;

&lt;p&gt;Again, I’ve pasted the findings into the following snippet field for further inspection. As mentioned by ChatGPT, this rule checks for &lt;em&gt;execve&lt;/em&gt; events where the second argument (evt.argv[1]) contains either shutdown or reboot. This indicates that the process is attempting to shut down or reboot the system, which is a technique used to disrupt normal system operation and, therefore, correctly aligns with the MITRE tactic and technique.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;- rule: Detect T1529 - System Shutdown/Reboot
  desc: Detects attempts to shut down or reboot the system
  condition: (evt.type=execve and (evt.argv[1] contains "shutdown" or evt.argv[1] contains "reboot"))
  output: "Detected attempt to shut down or reboot the system. T1529 - System Shutdown/Reboot detected"
  priority: WARNING
  tags: [tactic=impact, technique=T1529, technique_id=T1529]Code language: Perl (perl)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So far, we have learned that we cannot rely on ChatGPT to contribute Falco rules without being vetted by an experienced Falco user. &lt;/p&gt;

&lt;p&gt;That said, ChatGPT has quickly contributed rules that can be used to address regulatory frameworks and/or risk frameworks such as MITRE ATT&amp;amp;CK. The injected tags allow users to categorize and track detections of this technique within your security management tooling.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to detect cryptomining with ChatGPT and Falco
&lt;/h2&gt;

&lt;p&gt;The rules we have created so far are fairly simplistic. In order to test the true power of ChatGPT, we need to ask it for help creating more complex Falco rules involving additional abstractions such as &lt;a href="https://falco.org/docs/rules/appending/" rel="noopener noreferrer"&gt;Macros and Lists&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;An example that we were working on recently was the creation of a small list of known cryptomining binaries for a &lt;a href="https://community.cncf.io/events/details/cncf-cncf-online-programs-presents-cloud-native-live-detecting-crypto-jacking-in-kubernetes-workloads/" rel="noopener noreferrer"&gt;CNCF Livestream&lt;/a&gt;. We would like to see how ChatGPT addresses this request.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://sysdig.com/wp-content/uploads/image-36.png" rel="noopener noreferrer"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsysdig.com%2Fwp-content%2Fuploads%2Fimage-36-1170x769.png" alt="ChatGPT Falco Rule Cryptomining" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We were disappointed with this response. &lt;/p&gt;

&lt;p&gt;While the syntax is valid, the default approach from ChatGPT is always to list the process names within the Falco rule, rather than creating a list of known binaries, and mapping this to the Falco rules via a referenced Macro. &lt;/p&gt;

&lt;p&gt;We can ask ChatGPT to specifically reference the binaries in the List.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://sysdig.com/wp-content/uploads/image-35.png" rel="noopener noreferrer"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsysdig.com%2Fwp-content%2Fuploads%2Fimage-35-1170x861.png" alt="ChatGPT Falco List" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Funnily, ChatGPT was even more confused by this instruction to the point where it started appending syntax that is foreign to the Falco rules syntax. &lt;/p&gt;

&lt;p&gt;At this point, the rule would no longer work and ChatGPT is losing credibility as a valid contributor to the Falco project.&lt;/p&gt;

&lt;p&gt;As an experienced Falco user, I had to explain that ChatGPT misunderstood my request and that further evaluation is required. It’s not that ChatGPT is unable to answer the request, but it can misunderstand certain aspects of the request depending on our phrasing. &lt;/p&gt;

&lt;p&gt;That’s why your request might require further fine tuning, but we can see that ChatGPT got there in the end. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://sysdig.com/wp-content/uploads/image-34.png" rel="noopener noreferrer"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsysdig.com%2Fwp-content%2Fuploads%2Fimage-34-1170x913.png" alt="Wrong Falco List" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;ChatGPT has given us a correctly-formatted Falco rule, which is a great foundation for further development. However, the rule is certainly not foolproof. &lt;/p&gt;

&lt;p&gt;There are many examples of cryptomining binaries other than ‘&lt;a href="https://xmrig.com/download" rel="noopener noreferrer"&gt;&lt;strong&gt;xmrig&lt;/strong&gt;&lt;/a&gt;’ – though xmrig is certainly the most common example. The value here is creating an extensive, up-to-date list of all common binaries so we can provide as much security coverage as possible. We mention some of these binaries in the following &lt;a href="https://falco.org/blog/falco-detect-cryptomining/#list" rel="noopener noreferrer"&gt;Falco blog&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Can ChatGPT create Falco plugins?
&lt;/h2&gt;

&lt;p&gt;Don’t get disappointed. Let’s see if ChatGPT is able to help us create a plugin for Falco.&lt;/p&gt;

&lt;p&gt;It’s super important to understand how ChatGPT responds to generic commands. When we asked if ChatGPT can create Falco plugins, it said, “&lt;em&gt;I do not have the ability to write or compile code. However, I can assist you in writing the code for a Falco plugin&lt;/em&gt;.”&lt;/p&gt;

&lt;p&gt;&lt;a href="https://sysdig.com/wp-content/uploads/image-37.png" rel="noopener noreferrer"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsysdig.com%2Fwp-content%2Fuploads%2Fimage-37-1170x816.png" alt="ChatGPT Falco Plugins" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It’s also worth noting that ChatGPT explains the supported protocol (gRPC) and the languages that support it (C++, Go, or Python). &lt;/p&gt;

&lt;p&gt;In that case, we just need to ask for guidance in how to write a Falco plugin. We need the request to be for a specific service for this request to be effective. Since &lt;a href="https://www.ghacks.net/2023/02/10/if-you-use-lastpass-you-need-to-change-all-of-your-passwords-asap/" rel="noopener noreferrer"&gt;LastPass is in the news lately&lt;/a&gt;, we will ask ChatGPT to help us create a LastPass Plugin.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://sysdig.com/wp-content/uploads/image-38.png" rel="noopener noreferrer"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsysdig.com%2Fwp-content%2Fuploads%2Fimage-38-1170x911.png" alt="LastPass Falco Plugin" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Amazingly, the below Python code snippet was provided to help configure a LastPass plugin with the appropriate gRPC protocol that we mentioned previously.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import grpc
from falco_proto import event_pb2
from falco_proto import event_pb2_grpc

class LastPassPlugin(event_pb2_grpc.EventServiceServicer):
    def HandleEvent(self, request, context):
        event = request.event
        if event.event_type == "executed" and event.output.find("lastpass-cli") != -1:
            print("LastPass CLI was executed")
        return event_pb2.HandleEventResponse()

server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
event_pb2_grpc.add_EventServiceServicer_to_server(LastPassPlugin(), server)
server.add_insecure_port('[::]:50051')
server.start()
server.wait_for_termination()Code language: Perl (perl)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code sets up a gRPC server and implements a custom HandleEvent method that is called whenever a Falco event occurs. The method checks if the event is an “executed” event and if the output contains the string “lastpass-cli.” If both conditions are met, it prints a message indicating that LastPass CLI was executed.&lt;/p&gt;

&lt;p&gt;Note that this is just a basic example. ChatGPT clearly explains that this was provided as guidance and therefore you will likely need to modify the code to meet your specific requirements. &lt;/p&gt;

&lt;p&gt;For more information on creating Falco plugins, we would recommend referring to the &lt;a href="https://falco.org/docs/plugins/developers-guide/" rel="noopener noreferrer"&gt;official Falco documentation&lt;/a&gt; and the gRPC protocol documentation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Can ChatGPT contribute to the Falco project?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Unfortunately, no!&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;As ChatGPT explained to us, it can help with the rule creation. But as an &lt;strong&gt;AI language model, it is not authorized to create pull requests&lt;/strong&gt;. As a result, ChatGPT cannot be officially included as a contributor to the open source project. However, project contributors and community members can rely on ChatGPT to validate their rule formatting, identify discrepancies in misconfigured rules, as well as provide insights on how a rule should be formatted to address a framework requirement.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://sysdig.com/wp-content/uploads/image-39.png" rel="noopener noreferrer"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsysdig.com%2Fwp-content%2Fuploads%2Fimage-39-1170x736.png" alt="ChatGPT Falco PR" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;ChatGPT is a powerful language model that can assist in creating Falco security rules. With its vast knowledge of various topics and its ability to generate text, it can provide helpful guidance and examples of how to create a rule that detects a specific threat. However, while it can be a valuable resource, ChatGPT should not be trusted to fully automate the creation of security rules. &lt;/p&gt;

&lt;p&gt;The accuracy and relevance of the information it provides can be limited by its training data and its knowledge cutoff, and it may not have the expertise or context to make informed decisions about the specific security needs of an organization. Additionally, security rule creation is an ongoing process that requires constant monitoring, tuning, and updating to keep up with new threats and changes in technology. &lt;/p&gt;

&lt;p&gt;Therefore, it is an option to use ChatGPT and consult security experts to verify and refine the rules before deploying them in a production environment.&lt;/p&gt;

</description>
      <category>chatgpt</category>
      <category>security</category>
      <category>devops</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Prometheus Alertmanager best practices</title>
      <dc:creator>Javier Martínez</dc:creator>
      <pubDate>Thu, 09 Feb 2023 09:59:54 +0000</pubDate>
      <link>https://dev.to/sysdig/prometheus-alertmanager-best-practices-4872</link>
      <guid>https://dev.to/sysdig/prometheus-alertmanager-best-practices-4872</guid>
      <description>&lt;p&gt;Have you ever fallen asleep to the sounds of your on-call team in a Zoom call? If you’ve had the misfortune to sympathize with this experience, you likely understand the problem of &lt;strong&gt;Alert Fatigue&lt;/strong&gt; firsthand.&lt;/p&gt;

&lt;p&gt;During an active incident, it can be exhausting to tease the upstream root cause from downstream noise while you’re context switching between your terminal and your alerts.&lt;/p&gt;

&lt;p&gt;This is where &lt;strong&gt;Alertmanager&lt;/strong&gt; comes in, providing a way to mitigate each of the problems related to Alert Fatigue.&lt;/p&gt;

&lt;p&gt;In this article, you will learn:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What Alert Fatigue is&lt;/li&gt;



&lt;li&gt;What AlertManager is&lt;/li&gt;



&lt;li&gt;Routing&lt;/li&gt;



&lt;li&gt;Inhibition&lt;/li&gt;



&lt;li&gt;Silencing and Throttling&lt;/li&gt;



&lt;li&gt;Grouping&lt;/li&gt;



&lt;li&gt;Notification Template&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id="alert-fatigue"&gt;Alert Fatigue&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Alert Fatigue&lt;/strong&gt; is the exhaustion of frequently responding to unprioritized and unactionable alerts. This is not sustainable in the long term. Not every alert is so urgent that it should wake up a developer. Ensuring that an on-call week is sustainable must prioritize sleep as well.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Was an engineer woken up more than twice this week?&lt;/li&gt;



&lt;li&gt;Can the resolution be automated or wait until morning?&lt;/li&gt;



&lt;li&gt;How many people were involved?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Companies often focus on response time and how long a resolution takes but how do they know the on-call process is not contributing to burn out?&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Pain Point&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Feature&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Alertmanager&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Send alerts to the right team&lt;/td&gt;
&lt;td&gt;Routing&lt;/td&gt;
&lt;td&gt;Labeled alerts are routed to the corresponding receiver&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Too many alerts at once&lt;/td&gt;
&lt;td&gt;Inhibition&lt;/td&gt;
&lt;td&gt;Alerts can inhibit other alerts (e.g., Datacenter down alert inhibits downtime alert)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;False positive on an Alert&lt;/td&gt;
&lt;td&gt;Silencing&lt;/td&gt;
&lt;td&gt;Temporarily silence an alert, especially when performing scheduled maintenance&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Alerts are too frequent&lt;/td&gt;
&lt;td&gt;Throttling&lt;/td&gt;
&lt;td&gt;Customizable back-off options to avoid re-notifying too frequently&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Unorganized alerts&lt;/td&gt;
&lt;td&gt;Grouping&lt;/td&gt;
&lt;td&gt;Logically group alerts by labels such as 'environment=dev' or 'service=broker'&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Notifications are unstructured&lt;/td&gt;
&lt;td&gt;Notification Template&lt;/td&gt;
&lt;td&gt;Standardize alerts to a template so that alerts are structured across services&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;

&lt;h2 id="alertmanager"&gt;Alertmanager&lt;/h2&gt;

&lt;p&gt;Prometheus &lt;strong&gt;Alertmanager&lt;/strong&gt; is the open source standard for translating alerts into alert notifications for your engineering team. &lt;a href="https://prometheus.io/docs/alerting/latest/alertmanager/" rel="noreferrer noopener"&gt;Alertmanager&lt;/a&gt; challenges the assumption that a dozen alerts should result in a dozen alert notifications. By leveraging the features of Alertmanager, dozens of alerts can be distilled into a handful of alert notifications, allowing on-call engineers to context switch less by thinking in terms of incidents rather than alerts.&lt;/p&gt;

&lt;h2 id="routing"&gt;Routing&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Routing&lt;/strong&gt; is the ability to send alerts to a variety of receivers including Slack, Pagerduty, and email. It is the core feature of Alertmanager.&lt;/p&gt;

&lt;pre&gt;route:
  receiver: slack-default            # Fallback Receiver if no routes are matched
  routes:
    - receiver: pagerduty-logging
      continue: true
    - match:
      team: support
      receiver: jira
    - match:
      team: on-call
      receiver: pagerduty-prod&lt;/pre&gt;

&lt;p&gt;&lt;a href="https://sysdig.com/wp-content/uploads/BlogImages-PrometheusAlertmanagerBestPractices-diagram1-1170x351.png" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsysdig.com%2Fwp-content%2Fuploads%2FBlogImages-PrometheusAlertmanagerBestPractices-diagram1-1170x351.png" alt="Prometheus alertmanager diagram 1" title="image_tooltip"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here, an alert with the label {team:on-call} was triggered. Routes are matched from top to bottom with the first receiver being &lt;code&gt;pagerduty-logging&lt;/code&gt;, a receiver for your on-call manager to track all alerts at the end of each month. Since the alert does not have a &lt;code&gt;{team:support}&lt;/code&gt; label, the matching continues to &lt;code&gt;{team:on-call} &lt;/code&gt;where the alert is properly routed to the pagerduty-prod receiver. The default route, slack-default, is specified at the top of the routes, in case no matches are found.&lt;/p&gt;

&lt;h2 id="inhibition"&gt;Inhibition&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Inhibition&lt;/strong&gt; is the process of &lt;strong&gt;muting downstream alerts &lt;/strong&gt;depending on their label set. Of course, this means that alerts must be systematically tagged in a logical and standardized way, but that's a human problem, not an Alertmanager one. While there is no native support for warning thresholds, the user can take advantage of labels and inhibit a warning when the critical condition is met. &lt;/p&gt;

&lt;p&gt;This has the unique advantage of supporting a warning condition for alerts that don't use a scalar comparison. It's all well and good to warn at 60% CPU usage and alert at 80% CPU usage, but what if we wanted to craft a warning and alert that compares two queries? This alert triggers when a node has more pods than its capacity.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;(sum by (kube_node_name) (kube_pod_container_status_running)) &amp;gt; 
on(kube_node_name) kube_node_status_capacity_pods&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;We can do exactly this by using inhibition with Alertmanager. In the first example, an alert with the label &lt;code&gt;{severity=critical}&lt;/code&gt; will inhibit an alert of &lt;code&gt;{severity=warning}&lt;/code&gt; if they share the same region, and alertname.&lt;/p&gt;

&lt;p&gt;In the second example, we can also inhibit downstream alerts when we know they won't be important in the root cause. It might be expected that a Kafka consumer behaves anomalously when the Kafka producer doesn't publish anything to the topic.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;inhibit_rules:
  - source_match:
      severity: 'critical'
    target_match:
      severity: 'warning'
    equal: ['region','alertname']
  - source_match:
      service: 'kafka_producer'
    target_match:
      service: 'kafka_consumer'
    equal: ['environment','topic']
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;a href="https://sysdig.com/wp-content/uploads/BlogImages-PrometheusAlertmanagerBestPractices-diagram2-1170x429.png" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsysdig.com%2Fwp-content%2Fuploads%2FBlogImages-PrometheusAlertmanagerBestPractices-diagram2-1170x429.png" alt="Prometheus alertmanager diagram 2" title="image_tooltip"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2 id="silencing-throttling"&gt;Silencing and Throttling&lt;/h2&gt;

&lt;p&gt;Now that you've woken up at 2 a.m. to exactly one root cause alert, you may want to acknowledge the alert and move forward with remediation. It’s too early to resolve the alert but alert re-notifications don’t give any extra context. This is where silencing and throttling can help.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Silencing&lt;/strong&gt; allows you to temporarily snooze an alert if you're expecting the alert to trigger for a scheduled procedure, such as database maintenance, or if you've already acknowledged the alert during an incident and want to keep it from renotifying while you remediate.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Throttling&lt;/strong&gt; solves a similar pain point but in a slightly different fashion. Throttles allow the user to tailor the renotification settings with three main parameters:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;group_wait&lt;/li&gt;



&lt;li&gt;group_interval&lt;/li&gt;



&lt;li&gt;repeat_interval&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://sysdig.com/wp-content/uploads/BlogImages-PrometheusAlertmanagerBestPractices-diagram3-1170x468.png" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsysdig.com%2Fwp-content%2Fuploads%2FBlogImages-PrometheusAlertmanagerBestPractices-diagram3-1170x468.png" alt="Prometheus alertmanager diagram 3" title="image_tooltip"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When Alert #1 and Alert #3 are initially triggered, Alertmanager will use &lt;code&gt;group_wait&lt;/code&gt; to delay by 30 seconds before notifying. After an initial alert has been triggered, any new alert notifications are delayed by group_interval . Since there was no new alert for the next 90 seconds, there was no notification. Over the subsequent 90 seconds however, Alert #2 was triggered and a notification of Alert #2 and Alert #3 was sent. In order to not forget about the current alerts if no new alert has been triggered, &lt;code&gt;repeat_interval&lt;/code&gt; can be configured to a value, such as 24 hours, so that the currently triggered alerts send a re-notifications every 24 hours.&lt;/p&gt;

&lt;h2 id="grouping"&gt;Grouping&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Grouping&lt;/strong&gt; in Alertmanager allows multiple alerts sharing a similar label set to be sent at the same time- not to be confused with Prometheus grouping, where alert rules in a group are evaluated in sequential order. By default, all alerts for a given route are grouped together. A &lt;code&gt;group_by&lt;/code&gt; field can be specified to logically group alerts.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;route:
  receiver: slack-default            # Fallback Receiver if no routes are matched
  group_by: [env]
  routes:
    - match:
        team: on-call
      Group_by: [region, service]
      receiver: pagerduty-prod
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;a href="https://sysdig.com/wp-content/uploads/BlogImages-PrometheusAlertmanagerBestPractices-diagram4-1170x819.png" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsysdig.com%2Fwp-content%2Fuploads%2FBlogImages-PrometheusAlertmanagerBestPractices-diagram4-1170x819.png" alt="Prometheus alertmanager diagram 4" title="image_tooltip"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Alerts that have the label {team:on-call} will be grouped by both region and service. This allows users to immediately have context that all of the notifications within this alert group share the same service and region. Grouping with information such as &lt;code&gt;instance_id&lt;/code&gt; or &lt;code&gt;ip_address&lt;/code&gt; tends to be less useful, since it means that every unique &lt;code&gt;instance_id&lt;/code&gt; or &lt;code&gt;ip_address&lt;/code&gt; will produce its own notification group. This may produce noisy notifications and defeat the purpose of grouping.&lt;/p&gt;

&lt;p&gt;If no grouping is configured, all alerts will be part of the same alert notification for a given route.&lt;/p&gt;

&lt;h2 id="notification-template"&gt;Notification Template&lt;/h2&gt;

&lt;p&gt;Notification templates offer a way to customize and standardize alert notifications. For example, a notification template can use labels to automatically link to a runbook or include useful labels for the on-call team to build context. Here, &lt;code&gt;app&lt;/code&gt; and &lt;code&gt;alertname&lt;/code&gt; labels are interpolated into a path that links out to a runbook. Standardizing on a notification template can make the on-call process run more smoothly since the on-call team may not be the direct maintainers of the microservice that is paging.&lt;/p&gt;

&lt;h2&gt;&lt;em&gt;Manage alerts with a click with Sysdig Monitor&lt;/em&gt;&lt;/h2&gt;

&lt;p&gt;As organizations grow, maintaining Prometheus and Alertmanager can become difficult to manage across teams. Sysdig Monitor makes this easy with Role-Based Access Control where teams can focus on the metrics and alerts most important to them. We offer a turn-key solution where you can manage your alerts from a single pane of glass. With Sysdig Monitor you can spend less time maintaining Prometheus Alertmanager and spend more time monitoring your actual infrastructure. Come chat with industry experts in monitoring and alerting and we'll get you up and running.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://sysdig.com/wp-content/uploads/Prometheus-Alertmanager-CTA-1170x530.png" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsysdig.com%2Fwp-content%2Fuploads%2FPrometheus-Alertmanager-CTA-1170x530.png" alt="Alert Monitoring in Sysdig Monitor"&gt;&lt;/a&gt;&lt;/p&gt;


&lt;p&gt;Sign up now for a &lt;a href="https://sysdig.com/company/free-trial-monitor/" rel="noopener noreferrer"&gt;free trial of Sysdig Monitor&lt;/a&gt;&lt;/p&gt;

</description>
      <category>prometheus</category>
      <category>devops</category>
      <category>monitoring</category>
    </item>
    <item>
      <title>Kubernetes OOM and CPU Throttling</title>
      <dc:creator>Javier Martínez</dc:creator>
      <pubDate>Thu, 26 Jan 2023 09:56:52 +0000</pubDate>
      <link>https://dev.to/sysdig/kubernetes-oom-and-cpu-throttling-n55</link>
      <guid>https://dev.to/sysdig/kubernetes-oom-and-cpu-throttling-n55</guid>
      <description>&lt;h2 id="introduction"&gt;Introduction&lt;/h2&gt;

&lt;p&gt;When working with Kubernetes, Out of Memory (OOM) errors and CPU throttling are the main headaches of resource handling in cloud applications. Why is that?&lt;/p&gt;

&lt;p&gt;CPU and Memory requirements in cloud applications are ever more important, since they are tied directly to your cloud costs.&lt;/p&gt;

&lt;p&gt;With &lt;a href="https://sysdig.com/blog/kubernetes-limits-requests/" rel="noreferrer noopener"&gt;limits and requests&lt;/a&gt;, you can configure how your pods should allocate memory and CPU resources in order to prevent resource starvation and adjust cloud costs.&lt;/p&gt;

&lt;p&gt;In case a Node doesn’t have enough resources, &lt;a href="https://sysdig.com/blog/kubernetes-pod-evicted/" rel="noopener noreferrer"&gt;Pods might get evicted&lt;/a&gt; via preemption or node-pressure.&lt;br&gt;When a process runs Out Of Memory (OOM), it’s killed since it doesn’t have the required resources.&lt;br&gt;In case CPU consumption is higher than the actual limits, the process will start to be throttled.&lt;/p&gt;

&lt;p&gt;But, how can you actively monitor how close your Kubernetes Pods to OOM and CPU throttling?&lt;/p&gt;

&lt;h2 id="kubernetes-oom"&gt;Kubernetes OOM&lt;/h2&gt;

&lt;p&gt;Every container in a Pod needs memory to run.&lt;/p&gt;

&lt;p&gt;Kubernetes limits are set per container in either a Pod definition or a Deployment definition.&lt;/p&gt;

&lt;p&gt;All modern Unix systems have a way to kill processes in case they need to reclaim memory. This will be marked as Error 137 or &lt;code&gt;OOMKilled.&lt;/code&gt;&lt;/p&gt;

&lt;pre&gt;   State:          Running
      Started:      Thu, 10 Oct 2019 11:14:13 +0200
    Last State:     Terminated
      Reason:       OOMKilled
      Exit Code:    137
      Started:      Thu, 10 Oct 2019 11:04:03 +0200
      Finished:     Thu, 10 Oct 2019 11:14:11 +0200
&lt;/pre&gt;

&lt;p&gt;This Exit Code 137 means that the process used more memory than the allowed amount and had to be terminated.&lt;/p&gt;

&lt;p&gt;This is a feature present in Linux, where the kernel sets an &lt;code&gt;oom_score&lt;/code&gt; value for the process running in the system. Additionally, it allows setting a value called &lt;code&gt;oom_score_adj&lt;/code&gt;, which is used by Kubernetes to allow Quality of Service. It also features an &lt;code&gt;OOM Killer,&lt;/code&gt; which will review the process and terminate those that are using more memory than they should.&lt;/p&gt;

&lt;p&gt;Note that in Kubernetes, a process can reach any of these limits:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A Kubernetes Limit set on the container.&lt;/li&gt;



&lt;li&gt;A Kubernetes ResourceQuota set on the namespace.&lt;/li&gt;



&lt;li&gt;The node’s actual Memory size.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://sysdig.com/wp-content/uploads/BlogImages-TroubleshootKubernetesOOM-1.png" rel="noopener noreferrer"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsysdig.com%2Fwp-content%2Fuploads%2FBlogImages-TroubleshootKubernetesOOM-1.png" alt="Kubernetes OOM graph" title="image_tooltip" width="800" height="482"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;Memory overcommitment&lt;/h3&gt;

&lt;p&gt;Limits can be higher than requests, so the sum of all limits can be higher than node capacity. This is called overcommit and it is very common. In practice, if all containers use more memory than requested, it can exhaust the memory in the node. This usually causes the &lt;a href="https://sysdig.com/blog/kubernetes-pod-evicted/" rel="noopener noreferrer"&gt;death of some pods&lt;/a&gt; in order to free some memory.&lt;/p&gt;

&lt;h3&gt;Monitoring Kubernetes OOM&lt;/h3&gt;

&lt;p&gt;When using node exporter in Prometheus, there’s one metric called &lt;code&gt;node_vmstat_oom_kill&lt;/code&gt;. It’s important to track when an OOM kill happens, but you might want to get ahead and have visibility of such an event before it happens.&lt;/p&gt;

&lt;p&gt;Instead, you can check how close a process is to the Kubernetes limits:&lt;/p&gt;

&lt;pre&gt;(sum by (namespace,pod,container)
(rate(container_cpu_usage_seconds_total{container!=""}[5m])) / sum by 
(namespace,pod,container)
(kube_pod_container_resource_limits{resource="cpu"})) &amp;gt; 0.8
&lt;/pre&gt;

&lt;h2 id="kubernetes-cpu-throttling"&gt;Kubernetes CPU throttling&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;CPU Throttling&lt;/strong&gt; is a behavior where processes are slowed when they are about to reach some resource limits.&lt;/p&gt;

&lt;p&gt;Similar to the memory case, these limits could be:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A Kubernetes Limit set on the container.&lt;/li&gt;



&lt;li&gt;A Kubernetes ResourceQuota set on the namespace.&lt;/li&gt;



&lt;li&gt;The node’s actual Memory size.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Think of the following analogy. We have a highway with some traffic where:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;CPU is the road.&lt;/li&gt;



&lt;li&gt;Vehicles represent the process, where each one has a different size.&lt;/li&gt;



&lt;li&gt;Multiple lanes represent having several cores.&lt;/li&gt;



&lt;li&gt;A request would be an exclusive road, like a bike lane.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Throttling here is represented as a traffic jam: eventually, all processes will run, but everything will be slower.&lt;/p&gt;

&lt;h3&gt;CPU process in Kubernetes&lt;/h3&gt;

&lt;p&gt;CPU is handled in Kubernetes with &lt;strong&gt;shares&lt;/strong&gt;. Each CPU core is divided into 1024 shares, then divided between all processes running by using the cgroups (control groups) feature of the Linux kernel.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://sysdig.com/wp-content/uploads/BlogImages-TroubleshootKubernetesOOM-4.png" rel="noopener noreferrer"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsysdig.com%2Fwp-content%2Fuploads%2FBlogImages-TroubleshootKubernetesOOM-4.png" alt="Kubernetes shares system for CPU" width="800" height="390"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If the CPU can handle all current processes, then no action is needed. If processes are using more than 100% of the CPU, then shares come into place. As any Linux Kernel, Kubernetes uses the CFS (Completely Fair Scheduler) mechanism, so the processes with more shares will get more CPU time.&lt;/p&gt;

&lt;p&gt;Unlike memory, a Kubernetes won't kill Pods because of throttling.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://sysdig.com/wp-content/uploads/BlogImages-TroubleshootKubernetesOOM-2.png" rel="noopener noreferrer"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsysdig.com%2Fwp-content%2Fuploads%2FBlogImages-TroubleshootKubernetesOOM-2.png" alt="Kubernetes Throttling graph" title="image_tooltip" width="800" height="365"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;span&gt;&lt;em&gt;You can check CPU stats in /sys/fs/cgroup/cpu/cpu.stat&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;

&lt;h3&gt;CPU overcommitment&lt;/h3&gt;

&lt;p&gt;As we saw in the &lt;a href="https://sysdig.com/blog/kubernetes-limits-requests/" rel="noopener noreferrer"&gt;limits and requests article&lt;/a&gt;, it’s important to set limits or requests when we want to restrict the resource consumption of our processes. Nevertheless, beware of setting up total requests larger than the actual CPU size, as this means that every container should have a guaranteed amount of CPU.&lt;/p&gt;

&lt;h3&gt;Monitoring Kubernetes CPU throttling&lt;/h3&gt;

&lt;p&gt;You can check how close a process is to the Kubernetes limits:&lt;/p&gt;

&lt;pre&gt;(sum by (namespace,pod,container)(rate(container_cpu_usage_seconds_total
{container!=""}[5m])) / sum by (namespace,pod,container)
(kube_pod_container_resource_limits{resource="cpu"})) &amp;gt; 0.8&lt;/pre&gt;

&lt;p&gt;In case we want to track the amount of throttling happening in our cluster, cadvisor provides &lt;code&gt;container_cpu_cfs_throttled_periods_total&lt;/code&gt; and &lt;code&gt;container_cpu_cfs_periods_total&lt;/code&gt;. With these two, you can easily calculate the % of throttling in all CPU periods.&lt;/p&gt;

&lt;h2 id="best-practices"&gt;Best practices&lt;/h2&gt;

&lt;h3&gt;Beware of limits and requests&lt;/h3&gt;

&lt;p&gt;Limits are a way to set up a maximum cap on resources in your node, but these need to be treated carefully, as you might end up with a process throttled or killed.&lt;/p&gt;

&lt;h3&gt;Prepare against eviction&lt;/h3&gt;

&lt;p&gt;By setting very low requests, you might think this will grant a minimum of either CPU or Memory to your process. But &lt;code&gt;kubelet&lt;/code&gt; will evict first those Pods with usage higher than requests first, so you’re marking those as the first to be killed!&lt;/p&gt;

&lt;p&gt;In case you need to protect specific Pods against preemption (when &lt;code&gt;kube-scheduler&lt;/code&gt; needs to allocate a new Pod), assign Priority Classes to your most important processes.&lt;/p&gt;

&lt;h3&gt;Throttling is a silent enemy&lt;/h3&gt;

&lt;p&gt;By setting unrealistic limits or overcommitting, you might not be aware that your processes are being throttled, and performance impacted. Proactively monitor your CPU usage and know your actual limits in both containers and namespaces.&lt;/p&gt;

&lt;h2 id="wrapping-up"&gt;Wrapping up&lt;/h2&gt;

&lt;p&gt;Here’s a cheat sheet on Kubernetes resource management for CPU and Memory. This summarizes the current article plus these ones which are part of the same series:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://sysdig.com/blog/kubernetes-pod-evicted/" rel="noopener noreferrer"&gt;https://sysdig.com/blog/kubernetes-pod-evicted/&lt;/a&gt;&lt;/li&gt;



&lt;li&gt;&lt;a href="https://sysdig.com/blog/kubernetes-limits-requests/" rel="noopener noreferrer"&gt;https://sysdig.com/blog/kubernetes-limits-requests/&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://sysdig.com/wp-content/uploads/BlogImages-TroubleshootKubernetesOOM-diagram-1170x664.png" rel="noopener noreferrer"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsysdig.com%2Fwp-content%2Fuploads%2FBlogImages-TroubleshootKubernetesOOM-diagram-1170x664.png" alt="Kubernetes CPU and Memory cheatsheet" width="800" height="454"&gt;&lt;/a&gt;&lt;/p&gt;








&lt;h2&gt;Rightsize your Kubernetes Resources with Sysdig Monitor&lt;/h2&gt;





&lt;p&gt;With Sysdig Monitor’s new feature, Cost Advisor, you can optimize your Kubernetes costs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Memory requests&lt;/li&gt;



&lt;li&gt;CPU requests&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;With our out-of-the-box Kubernetes Dashboards, you can &lt;a href="https://sysdig.com/blog/kubernetes-capacity-planning/" rel="noreferrer noopener"&gt;discover underutilized resources&lt;/a&gt;&lt;br&gt;in a couple of clicks.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsysdig.com%2Fwp-content%2Fuploads%2FBlog-How-to-do-capacity-planning-for-Kubernetes-Image-14.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsysdig.com%2Fwp-content%2Fuploads%2FBlog-How-to-do-capacity-planning-for-Kubernetes-Image-14.png" alt="Capacity planning Kubernetes Sysdig Monitor" width="800" height="515"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://sysdig.com/company/free-trial-monitor/" rel="noopener noreferrer"&gt;Try it free for 30 days!&lt;/a&gt;&lt;/p&gt;

</description>
      <category>kubernetes</category>
      <category>devops</category>
      <category>cloud</category>
      <category>prometheus</category>
    </item>
    <item>
      <title>Getting started with kubectl plugins</title>
      <dc:creator>Miguel</dc:creator>
      <pubDate>Wed, 18 Jan 2023 16:46:11 +0000</pubDate>
      <link>https://dev.to/sysdig/getting-started-with-kubectl-plugins-372e</link>
      <guid>https://dev.to/sysdig/getting-started-with-kubectl-plugins-372e</guid>
      <description>&lt;p&gt;Let's dig deeper into this list of Kubectl plugins that we strongly feel will be very useful for anyone, especially security engineers.&lt;/p&gt;

&lt;p&gt;Kubernetes, by design, is incredibly customizable. Kubernetes supports custom configurations for specific use case scenarios. This eliminates the need to apply patches to underlying features. Plugins are the means to extend Kubernetes features and deliver out-of-the-box offerings.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are Kubernetes Plugins?
&lt;/h2&gt;

&lt;p&gt;Users can install and write extensions for kubectl, the &lt;a href="https://kubernetes.io/docs/reference/kubectl/" rel="noopener noreferrer"&gt;Kubernetes command line tool&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;By observing the core kubectl commands as essential building blocks for interacting with a Kubernetes cluster, a cluster administrator can think of plugins as a means of utilizing these building blocks to create more complex behavior.&lt;/p&gt;

&lt;p&gt;Plugins extend kubectl with new sub-commands, allowing for new and custom features not included in the main distribution of kubectl.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why are plugins useful for security operations?
&lt;/h3&gt;

&lt;p&gt;Kubernetes plugins provide countless security benefits to the platform. Incident responders can develop additional functionality “on the fly” in their language of choice.&lt;/p&gt;

&lt;p&gt;Since Kubernetes features often fall short in cases where businesses need to achieve “out-of-scope” functionality, teams will often need to implement their own custom operations.&lt;/p&gt;

&lt;h2&gt;
  
  
  Potential security considerations for Kubernetes plugins
&lt;/h2&gt;

&lt;p&gt;While custom implementations add functionality that is not necessarily provided out-of-the-box with &lt;em&gt;kubectl&lt;/em&gt;, these plugins are not always as secure as we would like them to be. This article aims to address the most common or &lt;strong&gt;useful Kubernetes plugins for improving your security posture&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Managing plugins with Krew
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://krew.sigs.k8s.io/" rel="noopener noreferrer"&gt;Krew&lt;/a&gt; is a plugin manager maintained by the Kubernetes Special Interest Group (&lt;a href="https://github.com/kubernetes/community/blob/master/sig-cli/README.md" rel="noopener noreferrer"&gt;SIG&lt;/a&gt;) CLI community. Krew makes it easy to use kubectl plugins and helps you discover, install, and manage them on your machine. It is similar to tools like &lt;a href="https://en.wikipedia.org/wiki/APT_(software)" rel="noopener noreferrer"&gt;apt&lt;/a&gt;, &lt;a href="https://en.wikipedia.org/wiki/DNF_(software)" rel="noopener noreferrer"&gt;dnf&lt;/a&gt;, or &lt;a href="https://en.wikipedia.org/wiki/Homebrew_(package_manager)" rel="noopener noreferrer"&gt;brew&lt;/a&gt;. Today, over 200 kubectl plugins are available on Krew - and that number is only increasing. Some projects are actively used and some get deprecated over time, but are still accessible via Krew.&lt;/p&gt;

&lt;p&gt;Command to install kubectl plugins via Krew:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl krew install &amp;lt;PLUGIN_NAME&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Kubectl plugins available via the Krew plugin index are &lt;strong&gt;not audited, which can cause a problem in the &lt;a href="https://sysdig.com/blog/software-supply-chain-security/" rel="noopener noreferrer"&gt;supply chain&lt;/a&gt;&lt;/strong&gt;. As mentioned earlier, the Krew plugin index houses hundreds of kubectl plugins:&lt;br&gt;&lt;br&gt;
&lt;a href="https://krew.sigs.k8s.io/plugins/" rel="noopener noreferrer"&gt;https://krew.sigs.k8s.io/plugins/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When you install and run third-party plugins, you are doing this at your own risk. At the end of the day, kubectl plugins are just arbitrary programs running in your shell.&lt;/p&gt;

&lt;p&gt;Finally, we want to share our top 15 kubectl plugins that will improve your security posture in your Kubernetes cluster.&lt;/p&gt;
&lt;h3&gt;
  
  
  1. Stern plugin
&lt;/h3&gt;

&lt;p&gt;Link to &lt;a href="https://github.com/stern/stern" rel="noopener noreferrer"&gt;GitHub Repository&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Stern&lt;/strong&gt; is a kubectl plugin that works a lot like ‘&lt;a href="https://linuxways.net/centos/tail-command-in-linux/" rel="noopener noreferrer"&gt;tail -f&lt;/a&gt;’ in Linux. Unlike &lt;strong&gt;kubectl log -f&lt;/strong&gt;, which has its own limitations around input parameters, Stern allows you to specify both the Pod ID and the Container ID as regular expressions.&lt;/p&gt;

&lt;p&gt;Any match will be followed and the output is multiplexed together, prefixed with the Pod and Container ID, and color-coded for human consumption (colors are stripped if piping to a file).&lt;/p&gt;

&lt;p&gt;You can install Stern with the below Krew command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl krew install stern
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Command to tail an appname in Stern:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl stern appname
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will match any pod containing the word service and listen to all containers within it. If you only want to see traffic to the server container, you could do:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl stern --container 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will stream the logs of all the server containers, even if running in multiple pods.&lt;/p&gt;

&lt;p&gt;One interesting security use case for the Stern plugin is to look at authentication activity to your Kubernetes clusters. To show the authentication activity within the last 15 minutes with relevant highlighted timestamps, run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl stern -t --since 15m auth
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. RBAC-tool
&lt;/h3&gt;

&lt;p&gt;Link to &lt;a href="https://github.com/alcideio/rbac-tool" rel="noopener noreferrer"&gt;GitHub Repository&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Role-based access control (&lt;a href="https://sysdig.com/learn-cloud-native/kubernetes-security/kubernetes-rbac/" rel="noopener noreferrer"&gt;RBAC&lt;/a&gt;) is a method of regulating access to computer or network resources based on the roles of individual users within your organization. The RBAC-tool simplifies querying and the creation of RBAC policies.&lt;/p&gt;

&lt;p&gt;You can install the &lt;strong&gt;RBAC-tool&lt;/strong&gt; with the below Krew command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl krew install rbac-tool
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you are unfamiliar with how RBAC roles are assigned to different Kubernetes components, the visualization command generates an insightful graph of all RBAC decisions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl rbac-tool viz --cluster-context nigel-douglas-cluster
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above command scans the cluster with the kubeconfig context '&lt;strong&gt;nigel-douglas-cluster&lt;/strong&gt;.' These graphs are useful for showing a visual before-and-after of permissions assigned to service accounts.&lt;/p&gt;

&lt;p&gt;There are multiple commands other than ‘&lt;strong&gt;viz&lt;/strong&gt;’ provided by the RBAC-tool plugin. The most useful is the ‘&lt;strong&gt;who-can&lt;/strong&gt;’ command. This shows which subjects have RBAC permissions to perform an action denoted by ‘VERB’ (Create, Read, Update, or Delete) on an object.&lt;/p&gt;

&lt;p&gt;To see who can read a secret resource by the name ‘&lt;strong&gt;important-secret&lt;/strong&gt;,’ run the below command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl rbac-tool who-can get secret/important-secret
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. Cilium Plugin
&lt;/h3&gt;

&lt;p&gt;Link to &lt;a href="https://github.com/bmcustodio/kubectl-cilium" rel="noopener noreferrer"&gt;GitHub Repository&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cilium&lt;/strong&gt; is a network security project that continues to grow in popularity due to its powerful eBPF dataplane. Since Kubernetes is not designed with any specific &lt;a href="https://kubernetes.io/docs/concepts/extend-kubernetes/compute-storage-net/network-plugins/" rel="noopener noreferrer"&gt;CNI (Network) Plugin&lt;/a&gt; in mind, it can be deciduous trying to manage the Cilium agent via kubectl. That’s why the Cilium team released the Cilium kubectl plugin.&lt;/p&gt;

&lt;p&gt;You can install the &lt;strong&gt;Cilium&lt;/strong&gt; plugin with the below Krew command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl krew install cilium
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As a basic first step, you can do a connectivity check for a single node powered by Cilium networking via the below command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl cilium connectivity test --single-node &amp;lt;node&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This doesn’t just provide improved operational visibility - it’s incredibly beneficial to network security engineers. For instance, if Cilium is unable to communicate with core components such as ‘&lt;a href="https://github.com/cilium/hubble" rel="noopener noreferrer"&gt;Hubble&lt;/a&gt;,’ this will show-up in the connectivity test.&lt;/p&gt;

&lt;p&gt;Hubble provides network, service, and security observability for Kubernetes. Being able to quickly diagnose a connection error, such as “connection refused,” improves the overall visibility of threats and provides the centralized network event view required to maintain regulatory compliance. If you want to dig deeper into network policies, discover &lt;a href="https://sysdig.com/blog/denial-of-service-kubernetes-calico-falco/" rel="noopener noreferrer"&gt;how to prevent a Denial of Service (DoS) attack on Kubernetes&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Kube Policy Advisor
&lt;/h3&gt;

&lt;p&gt;Link to &lt;a href="https://github.com/sysdiglabs/kube-policy-advisor" rel="noopener noreferrer"&gt;GitHub Repository&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The kube-policy-advisor plugin suggests PodSecurityPolicies and Open Policy Agent (OPA) Policies for your Kubernetes cluster. While &lt;a href="https://kubernetes.io/blog/2021/04/06/podsecuritypolicy-deprecation-past-present-and-future/" rel="noopener noreferrer"&gt;PodSecurityPolicies are deprecated&lt;/a&gt;, and therefore should not be used, OPA is very much a recommended tool for &lt;a href="https://sysdig.com/learn-cloud-native/kubernetes-security/kubernetes-admission-controllers/" rel="noopener noreferrer"&gt;admission controller&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You can install &lt;strong&gt;advise-policy&lt;/strong&gt; with the below Krew command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl krew install advise-policy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This kubectl plugin provides security and compliance checks for Kubernetes clusters. It can help identify potential security risks and violations of best practices in a cluster's configuration, and provide recommendations for how to remediate those issues. Some examples of the types of checks that kube-policy-advisor can perform include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Ensures pods are running with minimal privileges and are not granted unnecessary permissions.&lt;/li&gt;
&lt;li&gt;  Checks that secrets and other sensitive data are not stored in plain text or checked into source control.&lt;/li&gt;
&lt;li&gt;  Verifies that network policies are in place to protect against unauthorized access to resources.&lt;/li&gt;
&lt;li&gt;  Evaluates the security of container images and ensures that they come from trusted sources.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In Kubernetes, Admission Controllers enforce semantic validation of objects during create, update, and delete operations. With OPA, you can enforce custom policies on Kubernetes objects without recompiling or reconfiguring the Kubernetes API server.&lt;/p&gt;

&lt;p&gt;kube-policy-advisor is a tool that makes it easier to create OPA Policy from either a live K8s environment or from a single .yaml file containing a pod specification (Deployment, DaemonSet, Pod, etc.). In the below command, the plugin inspects any given namespace to print a report or OPA Policy.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl advise-policy inspect --namespace=&amp;lt;ns&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: If you do not enter a given namespace, it will generate the OPA Policy for all network namespace.&lt;/p&gt;

&lt;p&gt;By using kube-policy-advisor, you can help ensure that your Kubernetes cluster is secure and compliant with best practices, which can help protect your applications and data from potential threats.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Kubectl-ssm-secret
&lt;/h3&gt;

&lt;p&gt;Link to &lt;a href="https://github.com/pr8kerl/kubectl-ssm-secret" rel="noopener noreferrer"&gt;GitHub Repository&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;kubectl-ssm-secret&lt;/strong&gt; plugin allows admins to import or export their &lt;a href="https://sysdig.com/learn-cloud-native/kubernetes-101/how-to-create-and-use-kubernetes-secrets/" rel="noopener noreferrer"&gt;Kubernetes Secrets&lt;/a&gt; to or from an &lt;a href="https://docs.aws.amazon.com/systems-manager/latest/userguide/what-is-systems-manager.html" rel="noopener noreferrer"&gt;AWS SSM&lt;/a&gt; Parameter Store path. A Kubernetes Secret is sensitive information – such as a password or access key – that is used within a Kubernetes environment. It’s important to be able to safely control these sensitive credentials when transmitting between Kubernetes and AWS cloud.&lt;/p&gt;

&lt;p&gt;You can install the &lt;strong&gt;ssm-secret&lt;/strong&gt; plugin with the below Krew command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl krew install ssm-secret
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Secrets are not unique to Kubernetes, of course. You use Secrets’ data in virtually every type of modern application environment or platform. In the case of the ssm-secret plugin, all parameters found under a given parameter store path can be imported into a single kubernetes secret as “StringData.”&lt;/p&gt;

&lt;p&gt;This is incredibly useful if you are reprovisioning clusters or namespaces and need to provision the same secrets over and over. Also, it could be useful to backup/restore your &lt;a href="https://letsencrypt.org/" rel="noopener noreferrer"&gt;LetsEncrypt&lt;/a&gt; or other certificates.&lt;/p&gt;

&lt;p&gt;If an AWS parameter at path /foo/bar contains a secret value, and the parameter /foo/passwd contains a secure password, we can view the keys and values in parameter store using the kubectl ssm-secret list subcommand:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl ssm-secret list --ssm-path /foo
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Those output parameters can then be imported with the following import command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl ssm-secret import foo --ssm-path /foo
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Security considerations
&lt;/h4&gt;

&lt;p&gt;You must specify a single parameter store path for this plugin to work. It will not recursively search more than one level under a given path. As a result, the plugin is highly opinionated, and users run the risk of failing to import/export secrets to the correct path if they don’t track these paths correctly.&lt;/p&gt;

&lt;h3&gt;
  
  
  6. Kubelogin
&lt;/h3&gt;

&lt;p&gt;Link to &lt;a href="https://github.com/int128/kubelogin" rel="noopener noreferrer"&gt;GitHub Repository&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you’re running Kubectl versions v.1.12 or higher, Kubelogin (also known as &lt;strong&gt;&lt;em&gt;kubectl-login&lt;/em&gt;&lt;/strong&gt;) is a useful security plugin for logging into clusters via the CLI. It achieves this through &lt;a href="https://openid.net/connect/" rel="noopener noreferrer"&gt;OpenID Connect&lt;/a&gt; providers like DEX. OpenID Connect is a simple identity layer on top of the OAuth 2.0 protocol. It allows Clients to verify the identity of the End-User based on the authentication performed by an Authorization Server, as well as to obtain basic profile information about the End-User in an interoperable and REST-like manner.&lt;/p&gt;

&lt;p&gt;You can install the &lt;strong&gt;kubectl-login&lt;/strong&gt; plugin with the below Krew command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl krew install kubectl-login
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Your OpenID Connect provider must have the default callback endpoint for the Kubernetes API Client listed within the OpenID configuration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;http://localhost:33768/auth/callback
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This Kubectl plugin takes the OpenID Connect (OIDC) issuer URL from your &lt;em&gt;.kube/config&lt;/em&gt;, so it must be placed in your &lt;em&gt;.kube/config&lt;/em&gt;. Once you have made this change to the kubeconfig file, you can proceed to use your username assigned to your OIDC provider:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl login nigeldouglas-oidc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After this command is executed in your CLI, the browser will be opened with a redirect to the OpenID Connect Provider login page. The tokens in your kubeconfig file will be replaced after a successful authentication on the OIDC provider’s end.&lt;/p&gt;

&lt;h3&gt;
  
  
  7. Kubectl-whisper-secret
&lt;/h3&gt;

&lt;p&gt;Link to &lt;a href="https://github.com/rewanthtammana/kubectl-whisper-secret" rel="noopener noreferrer"&gt;GitHub Repository&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We mentioned the importance of securing sensitive credentials like ‘Secrets’ using the kubectl-ssm-secret plugin. The whisper-secret plugin focuses on creating those secrets with improved privacy. The plugin allows users to create secrets with secure input prompts to prevent information leakages through &lt;a href="https://gist.github.com/JPvRiel/df1d4c795ebbcad522188759c8fd69c7" rel="noopener noreferrer"&gt;terminal (bash) history&lt;/a&gt;, &lt;a href="https://capec.mitre.org/data/definitions/508.html" rel="noopener noreferrer"&gt;shoulder surfing&lt;/a&gt; attacks, etc.&lt;/p&gt;

&lt;p&gt;You can install the &lt;strong&gt;whisper-secret&lt;/strong&gt; plugin with the below Krew command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl krew install whisper-secret
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;’kubectl create secret’&lt;/strong&gt; has a few sub-commands we use most often that can possibly leak sensitive information in multiple ways, as mentioned above. For example, you can connect to a Docker registry via the &lt;strong&gt;’kubectl create secret’&lt;/strong&gt; command with a plain-text password for authentication.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl create secret docker-registry my-secret --docker-password nigelDouglasP@ssw0rD
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;’kubectl whisper-secret’&lt;/strong&gt; plugin allows users to create secrets with a secure input prompt for fields like &lt;strong&gt;--from-literal&lt;/strong&gt; and &lt;strong&gt;--docker-password&lt;/strong&gt; that contain sensitive information.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl whisper-secret docker-registry my-secret --docker-password -- -n nigel-test --docker-username &amp;lt;insert-password&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You are then prompted to enter the Docker password, but this is not inserted into the command itself. This way, the password will not show-up in the bash history as a plain text value, increasing security.&lt;/p&gt;

&lt;h3&gt;
  
  
  8. Kubectl-capture
&lt;/h3&gt;

&lt;p&gt;Link to &lt;a href="https://github.com/sysdiglabs/kubectl-capture" rel="noopener noreferrer"&gt;GitHub Repository&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Sysdig open source (&lt;a href="https://sysdig.com/blog/sysdig-inspect/" rel="noopener noreferrer"&gt;Sysdig Inspect&lt;/a&gt;) is a powerful tool for container troubleshooting, performance tuning, and security investigation. The team at Sysdig created a kubectl plugin which triggers a packet capture in the underlying host which is running a pod.&lt;/p&gt;

&lt;p&gt;You can install the &lt;strong&gt;kubectl-capture&lt;/strong&gt; plugin with the below Krew command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl krew install kubectl-capture
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Packet captures are incredibly useful for &lt;a href="https://sysdig.com/blog/guide-kubernetes-forensics-dfir/" rel="noopener noreferrer"&gt;incident response and forensics in Kubernetes&lt;/a&gt;. The capture file is created for a duration of time and is downloaded locally in order to use it with &lt;a href="https://github.com/draios/sysdig-inspect" rel="noopener noreferrer"&gt;Sysdig Inspect&lt;/a&gt;, a powerful open source interface designed to intuitively navigate the data-dense Sysdig captures that contain granular system, network, and application activity of a Linux system.&lt;/p&gt;

&lt;p&gt;Simply run the below command against any running pod in the cluster:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl capture kinsing-78f5d695bd-bcbd8
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When the capture container is being spun, it takes some time to compile the Sysdig Kernel module and capture system calls. Once completed, you can read the content within the Sysdig Inspect UI from your workstation:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsysdig.com%2Fwp-content%2Fuploads%2FScreenshot-2023-01-16-at-16.22.46.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsysdig.com%2Fwp-content%2Fuploads%2FScreenshot-2023-01-16-at-16.22.46.png" title="Sysdig Inspect" alt="alt_text" width="800" height="496"&gt;&lt;/a&gt;&lt;br&gt;&lt;br&gt;
With these tools, it will be much easier for the analyst to find the source of the problem or to audit what happened. If you want to go deeper, you can read &lt;a href="https://sysdig.com/blog/sysdig-inspect/" rel="noopener noreferrer"&gt;container troubleshooting with Sysdig Inspect&lt;/a&gt; or &lt;a href="https://sysdig.com/blog/triaging-malicious-docker-container/" rel="noopener noreferrer"&gt;triaging malicious containers&lt;/a&gt;.&lt;/p&gt;
&lt;h3&gt;
  
  
  9. Kubectl-trace
&lt;/h3&gt;

&lt;p&gt;Link to &lt;a href="https://github.com/iovisor/kubectl-trace" rel="noopener noreferrer"&gt;GitHub Repository&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;kubectl-trace&lt;/strong&gt; is a kubectl plugin that allows you to schedule the execution of bpftrace programs in your Kubernetes cluster. In short, Kubectl-trace plugin is a tool for distributed tracing in Kubernetes clusters. It allows you to trace the execution of requests as they pass through different components of a cluster, including pods, services, and ingress controllers.&lt;/p&gt;

&lt;p&gt;You can install the &lt;strong&gt;kubectl-trace&lt;/strong&gt; plugin with the below Krew command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl krew install trace
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One potential security benefit of using the Kubectl-trace plugin is that it can help you identify and troubleshoot issues related to request handling within a cluster. For example, if you suspect that a particular request is being blocked or slowed down due to some issue in the cluster, you can use Kubectl-trace to track the request as it travels through the cluster and identify the source of the problem.&lt;/p&gt;

&lt;p&gt;This plugin runs a program that probes a tracepoint on the node of choice:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl trace run &amp;lt;node-name&amp;gt; -e "tracepoint:syscalls:sys_enter_* { @[probe] = count(); }"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Another potential security benefit is that Kubectl-trace can help you understand how requests are being handled within a cluster, which can be useful for identifying potential vulnerabilities or misconfigurations. For example, if you see that a request is being handled by a pod or service that has been compromised, you can use Kubectl-trace to track the request and identify the source of the issue.&lt;/p&gt;

&lt;p&gt;Overall, the Kubectl-trace plugin can be a useful tool for improving the security of a Kubernetes cluster by helping to identify and address issues related to request handling and execution.&lt;/p&gt;

&lt;h3&gt;
  
  
  10. Access-matrix
&lt;/h3&gt;

&lt;p&gt;Link to &lt;a href="https://github.com/corneliusweig/rakkess" rel="noopener noreferrer"&gt;GitHub Repository&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Access-matrix&lt;/strong&gt; (often referred to as ‘Rakkess’) is a kubectl plugin that shows an access matrix for your server resources.&lt;/p&gt;

&lt;p&gt;You can install the &lt;strong&gt;access-matrix&lt;/strong&gt; plugin with the below Krew command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl krew install access-matrix
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Simply run the below command to see the Create, Read, Update &amp;amp; Delete (CRUD) permissions for all resources in the ‘default’ network namespace:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl rakkess –n default
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Some roles only apply to resources with a specific name. To review such configurations, provide the resource name as an additional argument. For example, show access rights for the ConfigMap called &lt;strong&gt;sysdig-controller&lt;/strong&gt; in namespace &lt;strong&gt;sysdig-agent&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl access-matrix r cm sysdig-controller -n sysdig-agent --verbs=all
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As rakkess resource needs to query &lt;strong&gt;Roles&lt;/strong&gt;, &lt;strong&gt;ClusterRoles&lt;/strong&gt;, and their &lt;strong&gt;bindings&lt;/strong&gt;, it usually requires administrative cluster access.&lt;/p&gt;

&lt;h3&gt;
  
  
  11. Rolesum
&lt;/h3&gt;

&lt;p&gt;Link to &lt;a href="https://github.com/Ladicle/kubectl-rolesum" rel="noopener noreferrer"&gt;GitHub Repository&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The Rolesum kubectl plugin is a tool for generating a summary of the roles and permissions defined in a Kubernetes cluster. It allows you to see all of the roles and permissions that have been defined in a cluster, along with the users and groups that have been granted those roles. Summarize RBAC roles for the specified subject (ServiceAccount, User, and Group).&lt;/p&gt;

&lt;p&gt;You can install the &lt;strong&gt;rolesum&lt;/strong&gt; plugin with the below Krew command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl krew install rolesum
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One potential security benefit of using the Rolesum kubectl plugin is that it can help you identify and understand the roles and permissions that have been defined in a cluster. This can be useful for ensuring that appropriate access controls have been put in place, and for identifying potential vulnerabilities or misconfigurations.&lt;/p&gt;

&lt;p&gt;You can summarize roles bound to the "nigeldouglas" ServiceAccount.&lt;br&gt;&lt;br&gt;
By default, rolesum looks for serviceaccounts. There’s no need to specify any flag.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl rolesum nigeldouglas
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Another potential security benefit is that Rolesum can help you quickly identify users and groups that have been granted certain roles or permissions, which can be useful for troubleshooting issues or for performing security assessments.&lt;/p&gt;

&lt;p&gt;For example, you can summarize roles bound to the "staging" group.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl rolesum -k Group staging
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Overall, the Rolesum kubectl plugin can be a useful tool for improving the security of a Kubernetes cluster by helping you understand and manage the roles and permissions that have been defined in the cluster.&lt;/p&gt;

&lt;h3&gt;
  
  
  12. Cert-Manager
&lt;/h3&gt;

&lt;p&gt;Link to &lt;a href="https://github.com/cert-manager/cert-manager" rel="noopener noreferrer"&gt;GitHub Repository&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Cert-Manager is a Kubectl plugin that provides automatic management of Transport Layer Security (TLS) certificates within a cluster. It allows you to easily provision, manage, and renew TLS certificates for your applications without having to manually handle the certificate signing process.&lt;/p&gt;

&lt;p&gt;You can install the &lt;strong&gt;cert-manager&lt;/strong&gt; plugin with the below Krew command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl krew install cert-manager
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One potential security benefit of using cert-manager is that it can help you ensure that your applications are using valid, up-to-date TLS certificates. This can be important for protecting the confidentiality and integrity of communication between your applications and their users.&lt;/p&gt;

&lt;p&gt;Another potential security benefit is that cert-manager can help you automate the process of obtaining and renewing TLS certificates, which can reduce the risk of certificate expiration or mismanagement.&lt;/p&gt;

&lt;p&gt;Overall, the cert-manager kubectl plugin can be a useful tool for improving the security of a Kubernetes cluster by helping you to manage TLS certificates in a secure and automated manner. The cert-manager plugin is loosely based upon the work of kube-lego and has borrowed some wisdom from other similar projects, such as kube-cert-manager.&lt;/p&gt;

&lt;h3&gt;
  
  
  13. np-viewer
&lt;/h3&gt;

&lt;p&gt;Link to &lt;a href="https://github.com/runoncloud/kubectl-np-viewer" rel="noopener noreferrer"&gt;GitHub Repository&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The kubectl-np-viewer plugin is a tool for visualizing the network topology of a Kubernetes cluster. It allows you to view the connections between pods, services, and other resources within a cluster in a graphical format.&lt;/p&gt;

&lt;p&gt;You can install the &lt;strong&gt;np-viewer&lt;/strong&gt; plugin with the below Krew command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl krew install np-viewer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Unlike the Cilium plugin we mentioned earlier, the kubectl-np-viewer plugin helps users understand and visualize the communication patterns within a cluster regardless of the CNI plugin used. The Cilium plugin only helps manage Cilium resources, such as the Cilium network policy. By viewing the default Kubernetes network policies, teams who are starting off with Kubernetes networking benefit from useful visibility into potential vulnerabilities or misconfigurations, such as pods that are communicating with unintended resources or are exposed to the internet.&lt;/p&gt;

&lt;p&gt;The below command prints network policies rules affecting a specific pod in the current namespace:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl np-viewer -p pod-name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Similarly, a potential security benefit from the kubectl-np-viewer plugin is that it helps users troubleshoot network issues within a cluster. For example, if you are experiencing connectivity issues between pods or services, you can use the plugin to visualize the connections between those resources and identify the source of the problem across all network namespace.&lt;/p&gt;

&lt;p&gt;The below command prints all network policies rules for all namespaces:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl np-viewer --all-namespaces
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Overall, the kubectl-np-viewer plugin can be a useful tool for improving the security of a Kubernetes cluster by helping you to understand and monitor the network topology of the cluster. Not all businesses have moved to advanced network policy implementations, such as Calico and Cilium. While users are exploring the Kubernetes Network Policy implementation, they can better understand how their policies control potentially unwanted/malicious traffic within their cluster with this security plugin.&lt;/p&gt;

&lt;h3&gt;
  
  
  14. ksniff
&lt;/h3&gt;

&lt;p&gt;Link to &lt;a href="https://github.com/eldadru/ksniff" rel="noopener noreferrer"&gt;GitHub Repository&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The ksniff kubectl plugin is a tool for capturing and analyzing network traffic in a Kubernetes cluster. It can be used to troubleshoot network issues, monitor traffic patterns, and perform security assessments.&lt;/p&gt;

&lt;p&gt;You can install the &lt;strong&gt;ksniff&lt;/strong&gt; plugin with the below Krew command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl krew install ksniff
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One benefit of using ksniff is that it allows you to capture and analyze traffic without having to directly access the nodes in a cluster. This can be helpful in situations where you don't have direct access to the nodes, or where you want to minimize the potential impact of capturing traffic on the cluster.&lt;/p&gt;

&lt;p&gt;Another benefit is that ksniff can be used to capture traffic between pods and services, which can be useful for understanding how applications communicate within a cluster. This is helpful for troubleshooting issues, optimizing performance, and identifying potential security vulnerabilities.&lt;/p&gt;

&lt;p&gt;Overall, the ksniff kubectl plugin can be a useful tool for improving the security of a Kubernetes cluster by helping to identify and address network-related issues and vulnerabilities. It achieves this by sniffing on Kubernetes pods with existing technologies, such as TCPdump and WireShark.&lt;/p&gt;

&lt;h3&gt;
  
  
  15. Inspektor-Gadget
&lt;/h3&gt;

&lt;p&gt;Link to &lt;a href="https://github.com/inspektor-gadget/inspektor-gadget" rel="noopener noreferrer"&gt;GitHub Repository&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Inspektor-Gadget&lt;/strong&gt; is one of the most useful kubectl plugins. The plugin executes within the user's system and as a DaemonSet when deployed within the cluster. It is actually a collection of tools (or gadgets) to debug and inspect Kubernetes resources and applications.&lt;/p&gt;

&lt;p&gt;You can install the &lt;strong&gt;gadget&lt;/strong&gt; plugin with the belowKkrew command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl krew install gadget
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can deploy one or more gadgets. Example gadgets are categorized into:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Advice&lt;/strong&gt; (Generates &lt;a href="https://github.com/inspektor-gadget/inspektor-gadget/blob/main/docs/guides/advise/seccomp-profile.md" rel="noopener noreferrer"&gt;seccomp profiles&lt;/a&gt; and &lt;a href="https://github.com/inspektor-gadget/inspektor-gadget/blob/main/docs/guides/advise/network-policy.md" rel="noopener noreferrer"&gt;network policies&lt;/a&gt; for the cluster)&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Audit&lt;/strong&gt; (Traces the system calls that the &lt;a href="https://github.com/inspektor-gadget/inspektor-gadget/blob/main/docs/guides/audit/seccomp.md" rel="noopener noreferrer"&gt;seccomp profile&lt;/a&gt; sends to the audit log)&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Profile&lt;/strong&gt; (Analyzes &lt;a href="https://github.com/inspektor-gadget/inspektor-gadget/blob/main/docs/guides/profile/block-io.md" rel="noopener noreferrer"&gt;Block I/O&lt;/a&gt; through distributed latency and &lt;a href="https://github.com/inspektor-gadget/inspektor-gadget/blob/main/docs/guides/profile/cpu.md" rel="noopener noreferrer"&gt;CPU Perf&lt;/a&gt; by sampled stack traces)&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Snapshot&lt;/strong&gt; (Gather information about running &lt;a href="https://github.com/inspektor-gadget/inspektor-gadget/blob/main/docs/guides/snapshot/process.md" rel="noopener noreferrer"&gt;processes&lt;/a&gt; and TCP/UDP &lt;a href="https://github.com/inspektor-gadget/inspektor-gadget/blob/main/docs/guides/snapshot/socket.md" rel="noopener noreferrer"&gt;sockets&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Top&lt;/strong&gt; (Periodically report &lt;a href="https://github.com/inspektor-gadget/inspektor-gadget/blob/main/docs/guides/top/block-io.md" rel="noopener noreferrer"&gt;block device I/O&lt;/a&gt; activity, &lt;a href="https://github.com/inspektor-gadget/inspektor-gadget/blob/main/docs/guides/top/ebpf.md" rel="noopener noreferrer"&gt;eBPF&lt;/a&gt; runtime stats, and read/write activity by &lt;a href="https://github.com/inspektor-gadget/inspektor-gadget/blob/main/docs/guides/top/file.md" rel="noopener noreferrer"&gt;file&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Trace&lt;/strong&gt; (Trace almost all activity from &lt;a href="https://github.com/inspektor-gadget/inspektor-gadget/blob/main/docs/guides/trace/dns.md" rel="noopener noreferrer"&gt;DNS&lt;/a&gt; queries/responses to &lt;a href="https://github.com/inspektor-gadget/inspektor-gadget/blob/main/docs/guides/trace/oomkill.md" rel="noopener noreferrer"&gt;OOMkill&lt;/a&gt; triggering a process kill)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It manages the packaging, deployment, and execution of eBPF programs in a Kubernetes cluster, including many based on BPF Compiler Collection (BCC) tools, as well as some developed specifically for use in Inspektor Gadget. It automatically maps low-level kernel primitives to high-level Kubernetes resources, making it easier and quicker to find the relevant information.&lt;/p&gt;

&lt;p&gt;To “Advise” on a Kubernetes Network Policy based on network trace activity, run the below command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl gadget advise network-policy report --input ./networktrace.log &amp;gt; network-policy.yaml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To “Audit” a seccomp profile based on pods, namespaces, syscalls, and code, run the below command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl gadget audit seccomp -o custom-columns=namespace,pod,syscall,code
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  DIY kubectl plugins
&lt;/h2&gt;

&lt;p&gt;You can write a plugin in any programming language or script that allows you to write command-line commands. There is no plugin installation or pre-loading required, which makes compiling these plugins rather simple.&lt;/p&gt;

&lt;p&gt;Plugin executables receive the inherited environment from the kubectl binary. The plugin will then determine which command path it wishes to implement based on the name – for example, a plugin named &lt;strong&gt;kubectl-sysdig&lt;/strong&gt; provides a command &lt;strong&gt;kubectl sysdig&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;You must install the plugin executable somewhere in your &lt;strong&gt;PATH&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;A plugin script would look something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/bin/bash
# optional argument handling
if [[ "$1" == "version" ]]
then
    echo "1.0.0"
    exit 0
fi
# optional argument handling
if [[ "$1" == "config" ]]
then
    echo "$KUBECONFIG"
    exit 0
fi
echo "I am a plugin named kubectl-sysdig"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For a complete guide on building Kubectl plugins, check out the &lt;a href="https://kubernetes.io/docs/tasks/extend-kubectl/kubectl-plugins/#using-a-plugin" rel="noopener noreferrer"&gt;official Kubernetes documentation&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Final considerations on kubectl plugins
&lt;/h3&gt;

&lt;p&gt;At the time of writing this blog post, there were &lt;strong&gt;208* kubectl plugins&lt;/strong&gt; currently accessible on Krew. Those kubectl plugins are accessible to developers across all major platforms, like MacOS, Linux, and Windows. While these plugins often address clear limitations over the default kubectl utility for operational tasks and security auditing, they also open a bunch of new security gaps for your Kubernetes cluster.&lt;/p&gt;

&lt;p&gt;From a security standpoint, we discussed 15 of the most useful kubectl plugins for giving security teams better visibility for &lt;a href="https://sysdig.com/blog/guide-kubernetes-forensics-dfir/" rel="noopener noreferrer"&gt;incident response and forensics in Kubernetes&lt;/a&gt;. However, as we add more plugins into the environment, we are also adding additional un-audited binaries that could be compromised. Krew does not provide an obligation to audit these binaries for known vulnerabilities or insecure configurations.&lt;/p&gt;

&lt;p&gt;Some security implications of using kubectl plugins include:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; &lt;strong&gt;Plugin vulnerabilities:&lt;/strong&gt; If a kubectl plugin has a vulnerability, it can potentially be exploited by an attacker to gain access to your Kubernetes cluster.&lt;/li&gt;
&lt;li&gt; &lt;strong&gt;Insecure plugin installation:&lt;/strong&gt; If a plugin is installed from an untrusted source, it could contain malicious code that could compromise the security of your cluster.&lt;/li&gt;
&lt;li&gt; &lt;strong&gt;Privilege escalation&lt;/strong&gt;: kubectl plugins run with the same privileges as the kubectl command, so if a plugin is compromised, it could potentially be used to escalate privileges and gain access to sensitive resources in your cluster.&lt;/li&gt;
&lt;li&gt; &lt;strong&gt;Data leakage:&lt;/strong&gt; If a kubectl plugin is not properly secured, it could potentially leak sensitive data from your cluster.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;To mitigate these risks, it is important to only install kubectl plugins from trusted sources and to regularly update and patch any plugins you have installed. It is also a good idea to regularly review the plugins you have installed and remove any that are no longer needed.&lt;/p&gt;

&lt;p&gt;If you don’t feel like a specific plugin adds value to your cluster, it would be wise to remove it just in case.&lt;/p&gt;

</description>
      <category>kubernetes</category>
      <category>beginners</category>
      <category>devops</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Kubernetes Services: ClusterIP, Nodeport and LoadBalancer</title>
      <dc:creator>Javier Martínez</dc:creator>
      <pubDate>Fri, 09 Dec 2022 10:03:19 +0000</pubDate>
      <link>https://dev.to/sysdig/kubernetes-services-clusterip-nodeport-and-loadbalancer-1g3m</link>
      <guid>https://dev.to/sysdig/kubernetes-services-clusterip-nodeport-and-loadbalancer-1g3m</guid>
      <description>&lt;p&gt;Pods are ephemeral. And they are meant to be. They can be seamlessly destroyed and replaced if using a Deployment. Or they can be scaled at some point when using Horizontal Pod Autoscaling (HPA).&lt;/p&gt;

&lt;p&gt;This means we can’t rely on the Pod IP address to connect with applications running in our containers internally or externally, as the Pod might not be there in the future.&lt;/p&gt;

&lt;p&gt;You may have noticed that Kubernetes Pods get assigned an IP address:&lt;/p&gt;

&lt;pre&gt;stable-kube-state-metrics-758c964b95-6fnbl               1/1     Running   0          3d20h   100.96.2.5      ip-172-20-54-111.ec2.internal   &amp;lt;none&amp;gt;           &amp;lt;none&amp;gt;
stable-prometheus-node-exporter-4brgv                    1/1     Running   0          3d20h   172.20.60.26    ip-172-20-60-26.ec2.internal
&lt;/pre&gt;

&lt;p&gt;This is a unique and internal IP for this particular Pod, but there’s no guarantee that this IP will exist in the future, due to the Pod's nature.&lt;/p&gt;

&lt;h2&gt;Services&lt;/h2&gt;

&lt;p&gt;A &lt;strong&gt;Kubernetes Service&lt;/strong&gt; is a mechanism to &lt;strong&gt;expose applications both internally and externally&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Every service will create an everlasting IP address that can be used as a connector.&lt;/p&gt;

&lt;p&gt;Additionally, it will open a &lt;code&gt;port&lt;/code&gt; that will be linked with a &lt;code&gt;targetPort&lt;/code&gt;. Some services can create ports in every &lt;a href="https://sysdig.com/learn-cloud-native/kubernetes-101/what-is-a-kubernetes-node/" rel="noreferrer noopener"&gt;Node&lt;/a&gt;, and even external IPs to create connectors outside the cluster.&lt;/p&gt;

&lt;p&gt;With the combination of both IP and Port, we can create a way to uniquely identify an application.&lt;/p&gt;

&lt;h3&gt;Creating a service&lt;/h3&gt;

&lt;p&gt;Every service has a selector that filters that will link it with a set of Pods in your cluster.&lt;/p&gt;

&lt;pre&gt;spec:
  selector:
    app.kubernetes.io/name: myapp
&lt;/pre&gt;

&lt;p&gt;So all Pods with the label &lt;em&gt;myapp&lt;/em&gt; will be linked to this service.&lt;/p&gt;

&lt;p&gt;There are three port attributes involved in a Service configuration:&lt;/p&gt;

&lt;pre&gt;  ports:
  - port: 80
    targetPort: 8080
    nodePort: 30036
    protocol: TCP
&lt;/pre&gt;

&lt;ul&gt;
&lt;li&gt;port: the new service port that will be created to connect to the application.&lt;/li&gt;



&lt;li&gt;targetPort: application port that we want to target with the services requests.&lt;/li&gt;



&lt;li&gt;nodePort: this is a port in the range of 30000-32767 that will be open in each node. If left empty, Kubernetes selects a free one in that range.&lt;/li&gt;



&lt;li&gt;protocol: TCP is the default one, but you can use others like SCTP or UDP.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can review services created with:&lt;/p&gt;

&lt;pre&gt;kubectl get services
kubectl get svc
&lt;/pre&gt;

&lt;h3&gt;Types of services&lt;/h3&gt;

&lt;p&gt;Kubernetes allows the creation of these types of services:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;ClusterIP (default)&lt;/li&gt;



&lt;li&gt;Nodeport&lt;/li&gt;



&lt;li&gt;LoadBalancer&lt;/li&gt;



&lt;li&gt;ExternalName&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let’s see each of them in detail.&lt;/p&gt;

&lt;h2&gt;ClusterIP&lt;/h2&gt;

&lt;p&gt;This is the default type for service in Kubernetes.&lt;/p&gt;

&lt;p&gt;As indicated by its name, this is just an address that can be used inside the cluster.&lt;/p&gt;

&lt;p&gt;Take, for example, the initial helm installation for Prometheus Stack. It installs Pods, Deployments, and Services for the Prometheus and Grafana ecosystem.&lt;/p&gt;

&lt;pre&gt;NAME                                      TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)                      AGE
alertmanager-operated                     ClusterIP   None            &amp;lt;none&amp;gt;        9093/TCP,9094/TCP,9094/UDP   3m27s
kubernetes                                ClusterIP   100.64.0.1      &amp;lt;none&amp;gt;        443/TCP                      18h
prometheus-operated                       ClusterIP   None            &amp;lt;none&amp;gt;        9090/TCP                     3m27s
stable-grafana                            ClusterIP   100.66.46.251   &amp;lt;none&amp;gt;        80/TCP                       3m29s
stable-kube-prometheus-sta-alertmanager   ClusterIP   100.64.23.19    &amp;lt;none&amp;gt;        9093/TCP                     3m29s
stable-kube-prometheus-sta-operator       ClusterIP   100.69.14.239   &amp;lt;none&amp;gt;        443/TCP                      3m29s
stable-kube-prometheus-sta-prometheus     ClusterIP   100.70.168.92   &amp;lt;none&amp;gt;        9090/TCP                     3m29s
stable-kube-state-metrics                 ClusterIP   100.70.80.72    &amp;lt;none&amp;gt;        8080/TCP                     3m29s
stable-prometheus-node-exporter           ClusterIP   100.68.71.253   &amp;lt;none&amp;gt;        9100/TCP                     3m29s
&lt;br&gt;&lt;br&gt;&lt;/pre&gt;



&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--s4XVCH_6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://sysdig.com/wp-content/uploads/Kubernetes-services-01-1170x644.png" alt="Kubernetes Services ClusterIP" width="880" height="484"&gt;



&lt;p&gt;This creates a connection using an internal Cluster IP address and a Port.&lt;/p&gt;



&lt;p&gt;But, what if we need to use this connector from outside the Cluster? This IP is internal and won’t work outside.&lt;/p&gt;



&lt;p&gt;This is where the rest of the services come in…&lt;/p&gt;



&lt;h2&gt;NodePort&lt;/h2&gt;



&lt;p&gt;A NodePort differs from the ClusterIP in the sense that it exposes a port in each Node.&lt;/p&gt;



&lt;p&gt;When a NodePort is created, kube-proxy exposes a port in the range 30000-32767:&lt;/p&gt;



&lt;pre&gt;apiVersion: v1
kind: Service
metadata:
  name: myservice
spec:
  selector:
    app: myapp
  type: NodePort
  ports:
  - port: 80
    targetPort: 8080
    nodePort: 30036
    protocol: TCP&lt;/pre&gt;



&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0hrnbgS6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://sysdig.com/wp-content/uploads/Kubernetes-services-02-1170x644.png" alt="Kubernetes Services Nodeport" width="880" height="484"&gt;



&lt;p&gt;NodePort is the preferred element for non-HTTP communication.&lt;/p&gt;



&lt;p&gt;The problem with using a NodePort is that you still need to access each of the Nodes separately.&lt;/p&gt;



&lt;p&gt;So, let’s have a look at the next item on the list…&lt;/p&gt;



&lt;h2&gt;LoadBalancer&lt;/h2&gt;



&lt;p&gt;A LoadBalancer is a Kubernetes service that:&lt;/p&gt;



&lt;ul&gt;
&lt;li&gt;Creates a service like ClusterIP&lt;/li&gt;



&lt;li&gt;Opens a port in every node like NodePort&lt;/li&gt;



&lt;li&gt;Uses a LoadBalancer implementation from your cloud provider (your cloud provider needs to support this for LoadBalancers to work).&lt;/li&gt;
&lt;/ul&gt;



&lt;pre&gt;apiVersion: v1
kind: Service
metadata:
  name: myservice
spec:
  ports:
  - name: web
    port: 80
  selector:
    app: web
  type: LoadBalancer
my-service                                LoadBalancer   100.71.69.103   &amp;lt;pending&amp;gt;     80:32147/TCP                 12s
my-service                                LoadBalancer   100.71.69.103   a16038a91350f45bebb49af853ab6bd3-2079646983.us-east-1.elb.amazonaws.com   80:32147/TCP                 16m
&lt;/pre&gt;

&lt;p&gt;In this case, Amazon Web Service (AWS) was being used, so an external IP from AWS was created.&lt;/p&gt;

&lt;p&gt;Then, if you use &lt;code&gt;kubectl describe my-service&lt;/code&gt;, you will find that several new attributes were added:&lt;/p&gt;

&lt;pre&gt;Name:                     my-service
Namespace:                default
Labels:                   &amp;lt;none&amp;gt;
Annotations:              &amp;lt;none&amp;gt;
Selector:                 app.kubernetes.io/name=pegasus
Type:                     LoadBalancer
IP Family Policy:         SingleStack
IP Families:              IPv4
IP:                       100.71.69.103
IPs:                      100.71.69.103
LoadBalancer Ingress:     a16038a91350f45bebb49af853ab6bd3-2079646983.us-east-1.elb.amazonaws.com
Port:                     &amp;lt;unset&amp;gt;  80/TCP
TargetPort:               9376/TCP
NodePort:                 &amp;lt;unset&amp;gt;  32147/TCP
Endpoints:                &amp;lt;none&amp;gt;
Session Affinity:         None
External Traffic Policy:  Cluster
&lt;/pre&gt;

&lt;p&gt;The main difference with NodePort is that LoadBalancer can be accessed and will try to equally assign requests to Nodes.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--eGQ-V_pF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://sysdig.com/wp-content/uploads/Kubernetes-services-03-1170x644.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--eGQ-V_pF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://sysdig.com/wp-content/uploads/Kubernetes-services-03-1170x644.png" alt="Kubernetes Service LoadBalancer" width="880" height="484"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;ExternalName&lt;/h2&gt;

&lt;p&gt;The ExternalName service was introduced due to the need of connecting to an element outside of the Kubernetes cluster. Think of it not as a way to connect to an item within your cluster, but as a connector to an external element of the cluster.&lt;/p&gt;

&lt;p&gt;This serves two purposes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It creates a single endpoint for all communications to that element.&lt;/li&gt;



&lt;li&gt;In case that external service needs to be replaced, it’s easier to switch by just modifying the ExternalName, instead of all connections.&lt;/li&gt;
&lt;/ul&gt;

&lt;pre&gt;apiVersion: v1
kind: Service
metadata:
  name: myservice
spec:
  ports:
    - name: web
      port: 80
  selector:
    app: web
  type: ExternalName
  externalName: db.myexternalserver.com
&lt;/pre&gt;

&lt;h2&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;Services are a key aspect of Kubernetes, as they provide a way to expose internal endpoints inside and outside of the cluster.&lt;/p&gt;

&lt;p&gt;ClusterIP service just creates a connector for in-node communication. Use it only in case you have a specific application that needs to connect with others in your node.&lt;/p&gt;

&lt;p&gt;NodePort and LoadBalancer are used for external access to your applications. It’s preferred to use LoadBalancer to equally distribute requests in multi-pod implementations, but note that your vendor should implement load balancing for this to be available.&lt;/p&gt;

&lt;p&gt;Apart from these, Kubernetes provides Ingresses, a way to create an HTTP connection with load balancing for external use.&lt;/p&gt;








&lt;h2&gt;&lt;em&gt;Debug service golden signals with Sysdig Monitor&lt;/em&gt;&lt;/h2&gt;

&lt;p&gt;With Sysdig Monitor, you can quickly debug:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Error rate&lt;/li&gt;
&lt;li&gt;Saturation&lt;/li&gt;
&lt;li&gt;Traffic&lt;/li&gt;
&lt;li&gt;Latency&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And thanks to its Container Observability with eBPF, you can do this without adding any app or code instrumentation.

Sysdig Advisor accelerates mean time to resolution (MTTR) with live logs, performance data, and suggested remediation steps. It’s the easy button for Kubernetes troubleshooting!&lt;/p&gt;

&lt;p&gt;&lt;a&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--NpnA6y3k--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://sysdig.com/wp-content/uploads/image-3-1.png" alt="How to debug a crashloopbackoff with Sysdig Monitor Advisor" width="880" height="379"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Sign up now for a &lt;a href="https://sysdig.com/company/free-trial-monitor/" rel="noopener"&gt;free trial of Sysdig Monitor&lt;/a&gt;&lt;/p&gt;



</description>
      <category>kubernetes</category>
      <category>services</category>
    </item>
    <item>
      <title>How attackers use exposed Prometheus server to exploit Kubernetes clusters</title>
      <dc:creator>Miguel</dc:creator>
      <pubDate>Fri, 02 Dec 2022 11:53:43 +0000</pubDate>
      <link>https://dev.to/sysdig/how-attackers-use-exposed-prometheus-server-to-exploit-kubernetes-clusters-3lek</link>
      <guid>https://dev.to/sysdig/how-attackers-use-exposed-prometheus-server-to-exploit-kubernetes-clusters-3lek</guid>
      <description>&lt;p&gt;What is the main thing we want to explain in this article? It’s simple; &lt;strong&gt;don’t expose your metrics for free&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Sometimes we think about deep and complex defense methods and that’s fine. We don’t know why, but we always forget about the base. &lt;strong&gt;Don’t expose your data&lt;/strong&gt;. By default, your Prometheus server can allow anyone to make queries to get information from your Kubernetes Cluster.&lt;/p&gt;

&lt;p&gt;This is not something new. In 2018, &lt;a href="https://arstechnica.com/information-technology/2018/02/tesla-cloud-resources-are-hacked-to-run-cryptocurrency-mining-malware/" rel="noopener noreferrer"&gt;Tesla had a cryptocurrency mining application in their cloud account&lt;/a&gt;, and the initial access was an exposed Kubernetes Dashboard with credentials in the clear.&lt;/p&gt;

&lt;p&gt;Moreover, we are not the first to talk about (in) security in monitoring tools. Here are three good examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;a href="https://github.com/juice-shop/juice-shop/issues/1275" rel="noopener noreferrer"&gt;Exposed Prometheus metrics Endpoint&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://jfrog.com/blog/dont-let-prometheus-steal-your-fire/" rel="noopener noreferrer"&gt;Don’t let Prometheus Steal your Fire&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://www.cncf.io/online-programs/a-look-at-how-hackers-exploit-prometheus-grafana-fluentd-jaeger-more/" rel="noopener noreferrer"&gt;Hacking Monitoring for Fun and Profit&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;With this in mind, are exposed Prometheus servers a real attack surface?&lt;/p&gt;

&lt;h2&gt;
  
  
  Prometheus exposed in the wild
&lt;/h2&gt;

&lt;p&gt;One of the &lt;strong&gt;most important steps&lt;/strong&gt; in any pentest, ethical hacking, or real attack is &lt;strong&gt;gathering as much information you can get from the target&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The fastest way to check if something is exposed on the internet is to query Google. The specific queries to gather information are denominated &lt;a href="https://www.businessinsider.com/term-of-the-day-google-dorking-2014-8" rel="noopener noreferrer"&gt;Google Dorking&lt;/a&gt; and, in our case, is something trivial to get real exposed Prometheus.&lt;/p&gt;

&lt;p&gt;A cooler way to find exposed Prometheus servers is using search engines. We used the most common ones to check how many servers we could access:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Search Engine&lt;/td&gt;
&lt;td&gt;Number exposed Prometheus server&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a rel="noopener nofollow noreferrer" href="https://www.shodan.io/"&gt;Shodan&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;31,679&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a rel="noopener nofollow noreferrer" href="https://censys.io/"&gt;Censys&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;61,854&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a rel="noopener nofollow noreferrer" href="https://fofa.info/toLogin"&gt;Fofa&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;161,274&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;At this point, we would like to clarify a critical fact.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Disclaimer&lt;/strong&gt;: We have &lt;strong&gt;not used an actual exposed Prometheus server to consult or prepare for this talk&lt;/strong&gt;. We performed all testing in our demo environment and strongly recommend always following security best practices.&lt;/p&gt;

&lt;p&gt;After that, what can we do if we have access to a Prometheus server and have access to the fingerprint Kubernetes?&lt;/p&gt;

&lt;h2&gt;
  
  
  Prometheus’ exporters and fingerprint Kubernetes
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://prometheus.io/" rel="noopener noreferrer"&gt;Prometheus&lt;/a&gt; is the &lt;em&gt;de facto&lt;/em&gt; &lt;a href="https://sysdig.com/blog/monitoring-kubernetes/" rel="noopener noreferrer"&gt;monitoring standard in Kubernetes&lt;/a&gt;. All the Kubernetes components of the control plane generate Prometheus metrics out of the box, and many Kubernetes distributions come with Prometheus installed by default including a series of standard exporters, generally:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Node Exporter for infrastructure and host metrics.&lt;/li&gt;
&lt;li&gt;  KSM Exporter for Kubernetes objects state metrics.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;An exporter&lt;/strong&gt; is an application that &lt;strong&gt;generates metrics&lt;/strong&gt; from other applications or systems that &lt;strong&gt;do not expose Prometheus metrics natively&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Cloud provider, where are you?
&lt;/h3&gt;

&lt;p&gt;Imagine that you have a possible target in &lt;em&gt;&lt;a href="http://www.example.com" rel="noopener noreferrer"&gt;www.example.com&lt;/a&gt;&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;All you know is that this site is a web page with users and a little e-commerce section. Under that domain, you find an open exposed Prometheus. The first thing you can do is try to &lt;strong&gt;identify the cloud provider&lt;/strong&gt; where the site is hosted.&lt;/p&gt;

&lt;p&gt;You can use the metric &lt;code&gt;node_dmi_info&lt;/code&gt; from the Node Exporter. This metric is very interesting, as it gives information about each &lt;a href="https://sysdig.com/learn-cloud-native/kubernetes-101/what-is-a-kubernetes-node/" rel="noopener noreferrer"&gt;Kubernetes node&lt;/a&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;System vendor&lt;/strong&gt;: It exposes the cloud vendor’s name. Some example values could be “&lt;code&gt;Amazon EC2&lt;/code&gt;” or “&lt;code&gt;Tencent Cloud&lt;/code&gt;.”&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Product name&lt;/strong&gt;: Useful to identify both the cloud provider and the product used, as we can find some popular product names from the AWS EC2 catalog (like “&lt;code&gt;m5.xlarge&lt;/code&gt;“) or other vendors’ products.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;But the cloud provider, even if interesting, is still so vague. You can gather more information if you focus on networking. You can start with the &lt;code&gt;node_network_info&lt;/code&gt; metric from the &lt;strong&gt;Node Exporter&lt;/strong&gt;. And even more, you can narrow your search if you filter only the Ethernet interfaces.&lt;/p&gt;

&lt;p&gt;Why only Ethernet ones? Because usually, they are the ones that the host identifies as physical network connections and are used to connect the host with the outside world and other machines.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;node_network_info{device=~'eth.+'}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This query provides the following information:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  IP address of each host.&lt;/li&gt;
&lt;li&gt;  Device ID.&lt;/li&gt;
&lt;li&gt;  Availability zone of the cloud provider.&lt;/li&gt;
&lt;li&gt;  ID of the VPC (Virtual Private Cloud).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here is an example of some possible values:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    address="06:d5:XX:XX:XX:XX"
    broadcast="ff:ff:ff:ff:ff:ff"
    device="eth0"
    instance="172.31.XX.XX:9100"
    instance_az="us-west-2a"
    instance_id="i-XXXXX"
    instance_name="XXX-XXX"
    instance_type="c5.xlarge"
    instance_vpc="vpc-XXXXXXX"
    operstate="up"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also get more information, like the hostname of each node with the metric &lt;code&gt;kube_node_info&lt;/code&gt; from KSM.&lt;/p&gt;

&lt;h3&gt;
  
  
  The long and windy road to the pod
&lt;/h3&gt;

&lt;p&gt;This was all about physical info, but &lt;strong&gt;how can we get from outside the web page to a pod in the cluster?&lt;/strong&gt; The answer to this question is in the &lt;strong&gt;ingress&lt;/strong&gt; and the &lt;strong&gt;services&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;ingress controllers in Kubernetes&lt;/strong&gt; act as reverse proxies and allow redirecting different paths of the URL to different Kubernetes services. These services normally act as load balancers in front of a set of pods that expose a port for connections. The metric &lt;code&gt;kube_ingress_path&lt;/code&gt; from KSM will give you information about the URL paths and the associated services of the ingress controllers in your cluster.&lt;/p&gt;

&lt;p&gt;This way, you can know that the path &lt;code&gt;/api/users/login&lt;/code&gt; goes to the Kubernetes service &lt;code&gt;users-login&lt;/code&gt; of the namespace &lt;code&gt;api&lt;/code&gt;. Funny, right?&lt;/p&gt;

&lt;p&gt;Load balancer services are a special kind of Kubernetes service. Cloud providers use those load balancer services to expose the service to the outside world. As an example, when you create a load-balancer service in an AWS Kubernetes cluster, it creates an ELB (Elastic Load Balancer) instance bound to the service.&lt;/p&gt;

&lt;p&gt;This &lt;strong&gt;promQL&lt;/strong&gt; query will give you &lt;strong&gt;information about all the load-balancer services&lt;/strong&gt; in a Kubernetes cluster:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kube_service_info * on (service) group_left group by (service,type) (kube_service_spec_type{type="LoadBalancer"})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To guess what pods are behind each service, you have two options. You can check the metric &lt;code&gt;kube_pod_labels&lt;/code&gt; from KSM. These labels are the ones that the service usually uses to select the pods that will serve the requests, but unfortunately, there is not a direct way to get the association between pods and service in pure KSM.&lt;/p&gt;

&lt;p&gt;However, if you are lucky enough, the cluster will have installed the OpenCost exporter, a tool that helps infrastructure engineers understand the costs of their cloud usage. This exporter generates an interesting metric called &lt;code&gt;service_selector_labels&lt;/code&gt;, which directly gives you the association between the service and the labels that the pod needs to have to be part of that particular service.&lt;/p&gt;

&lt;p&gt;This &lt;strong&gt;promQL&lt;/strong&gt; query will give you the labels of each workload used for matching in services:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;avg by (namespace,label_app,owner_name)(kube_pod_labels{app="cost-model"} * on(namespace,pod) group_left(owner_name) kube_pod_owner{job="kube-state-metrics"})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;While this other one will give you the labels that each service uses to find the pods:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;avg by (namespace,label_app, service)(service_selector_labels)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Being a many-to-many association, there is not an easy way to collect all this info in a single &lt;strong&gt;promQL&lt;/strong&gt; query, but the info is there, and it’s easy to make a quick correlation between services and pods.&lt;/p&gt;

&lt;p&gt;This way, we have all the points of the path from the URL to the pods: the path of the URL (thanks to the ingress), and pods serving the requests (thanks to the services and labels of the pods).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://sysdig.com/wp-content/uploads/exposed-Prometheus-Kubernetes-02.png" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsysdig.com%2Fwp-content%2Fuploads%2Fexposed-Prometheus-Kubernetes-02.png" alt="Exposed Prometheus to gather Kubernetes network information"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Logical song of the cluster
&lt;/h3&gt;

&lt;p&gt;You used the metric &lt;code&gt;kube_node_info&lt;/code&gt; to get information on the nodes, but now, you are also interested in making a logical map of namespaces, workloads, and pods inside the Kubernetes cluster.&lt;/p&gt;

&lt;p&gt;This is easy by using the KSM metrics. The metric kube_namespace_status_phase gives you all the namespaces in the cluster. From there, you can go down with the following metrics for each of the different workload types:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;code&gt;kube_deployment_spec_replicas&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;kube_daemonset_status_desired_number_scheduled&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;kube_statefulset_replicas&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;kube_replicaset_spec_replicas&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;kube_cronjob_info&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;After that, you can get info on the pods using &lt;code&gt;kube_pod_info&lt;/code&gt;, and associating them with their workloads with &lt;code&gt;kube_pod_owner&lt;/code&gt; in the following &lt;strong&gt;promQL&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kube_pod_info * on(namespace,pod) group_left(owner_name) kube_pod_owner
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally, you can even get the container inside each pod with the metric &lt;code&gt;kube_pod_container_info&lt;/code&gt;. For example, a pod called &lt;code&gt;postgres-db&lt;/code&gt; can have two containers named &lt;code&gt;postgresql&lt;/code&gt; and &lt;code&gt;postgres-exporter&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;But there is more. You can not only know the namespace and workload of a pod, you can also discover the node where it is living thanks to the label &lt;code&gt;node&lt;/code&gt; of the metric &lt;code&gt;kube_pod_info&lt;/code&gt;. Why is this important? Keep reading.&lt;/p&gt;

&lt;h3&gt;
  
  
  The boulevard of broken nodes
&lt;/h3&gt;

&lt;p&gt;You used the metric kube_node_info before to get the hostname of each node, but this metric has more surprises to unfold.&lt;/p&gt;

&lt;p&gt;Two labels of this metric will give us full information about the Operative System image used to build the node and the detailed kernel version.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;code&gt;os_image&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;kernel_version&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A quick search on &lt;strong&gt;CVE&lt;/strong&gt; for “Ubuntu 18.04.4 LTS” or “Linux 3.10.0-1160.59.1.el7.x86_64” will give a possible attacker a &lt;strong&gt;good set of exploits&lt;/strong&gt; to use if they can get access to the machine.&lt;/p&gt;

&lt;h3&gt;
  
  
  Let’s talk about K8s
&lt;/h3&gt;

&lt;p&gt;You have done a good job gathering information about the cluster so far. Namespaces, pods, services, and more But what about Kubernetes itself? There is a set of processes in Kubernetes itself that are just there, and we don’t even think about them unless they start causing problems. We are talking about the Kubernetes control plane.&lt;/p&gt;

&lt;p&gt;What would you say if we tell you that there is a metric that specifies the specific version of each of the components of the control plane? While presenting Prometheus, we said that Kubernetes control plane components were exposing natively metrics. Well, one of those metrics is &lt;code&gt;kubernetes_build_info&lt;/code&gt;. This gives you information about, not only the full (major and minor) version of each component, but also the git commit and the build date.&lt;/p&gt;

&lt;p&gt;This is great if you want to know if a concrete vulnerability affects one of the control plane components of the cluster (among other things).&lt;/p&gt;

&lt;h3&gt;
  
  
  We have a secret…
&lt;/h3&gt;

&lt;p&gt;Everybody loves secrets, especially attackers. In KSM, there is a metric called &lt;code&gt;kube_secret_info&lt;/code&gt; that gives you information about the namespace, node, and name of the secrets of your cluster.&lt;/p&gt;

&lt;p&gt;But if you are interested in knowing the content of the secrets, you can use this query:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kube_secret_annotations{kubectl_kubernetes_io_last_applied_configuration != ""}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Why? Well, this is somehow embarrassing. In some older versions of &lt;code&gt;kubectl&lt;/code&gt;, it used to save &lt;a href="https://kubernetes.io/docs/tasks/manage-kubernetes-objects/declarative-config/" rel="noopener noreferrer"&gt;the last applied configuration in an annotation&lt;/a&gt;. This was being made for every object, including secrets. This had the effect that, even if the secret was only accessible by the service accounts and role bindings that you can imagine, Prometheus can expose the content of the secret in plain text in that metric.&lt;/p&gt;

&lt;h3&gt;
  
  
  On images and registries
&lt;/h3&gt;

&lt;p&gt;Do you think you had enough? There is one more interesting thing you can get from KSM. The metric &lt;code&gt;kube_pod_container_info&lt;/code&gt; has an interesting piece of information in these labels:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;code&gt;image&lt;/code&gt;: name and tag of the image of the container (for example &lt;code&gt;docker.io/library/cassandra:3.11.6&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;image_id&lt;/code&gt;: name, tag, and hash of the image of the container&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This gives you information about:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Application used.&lt;/li&gt;
&lt;li&gt;  Registry used to pull the image.&lt;/li&gt;
&lt;li&gt;  Image used.&lt;/li&gt;
&lt;li&gt;  Tag of the image.&lt;/li&gt;
&lt;li&gt;  Hash that identifies uniquely the image independently of its tag.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Summary Kubernetes fingerprint
&lt;/h3&gt;

&lt;p&gt;Let’s see what you’ve done so far. You gathered information about:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Cloud provider.&lt;/li&gt;
&lt;li&gt;  Kubernetes control plane components versions.&lt;/li&gt;
&lt;li&gt;  Network path from the outside to pods.&lt;/li&gt;
&lt;li&gt;  Nodes hostnames and IPs.&lt;/li&gt;
&lt;li&gt;  Operative system and kernel versions.&lt;/li&gt;
&lt;li&gt;  Logical structure of the cluster namespaces, workloads, and pods.&lt;/li&gt;
&lt;li&gt;  Images used for the containers, from the source repository to the image tag.&lt;/li&gt;
&lt;li&gt;  Annotations and names of the secrets of the cluster.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://sysdig.com/wp-content/uploads/exposed-Prometheus-Kubernetes-03.gif" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsysdig.com%2Fwp-content%2Fuploads%2Fexposed-Prometheus-Kubernetes-03.gif" alt="Exposed Prometheus fingerprinting Kubernetes CVEs"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;All this information is enough to make a good surface attack analysis of the cluster.&lt;/p&gt;

&lt;h3&gt;
  
  
  Ninja mode!
&lt;/h3&gt;

&lt;p&gt;Do you want to hear something funny? &lt;strong&gt;We gathered all this information and most likely, there is not a trace of all the queries that we did to get it&lt;/strong&gt;. Prometheus can &lt;strong&gt;register logs of the queries&lt;/strong&gt;, but that’s &lt;strong&gt;disabled by default&lt;/strong&gt;. You can even check if your activity is being logged with this metric:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;prometheus_engine_query_log_enabled
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Inside the attackers’ minds
&lt;/h2&gt;

&lt;p&gt;Now, attackers just need to know what their target is. In 99% of attacks, it’s money, but how to get the money from the victim, that’s the point where the attacker’s path is defined.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://sysdig.com/wp-content/uploads/exposed-Prometheus-Kubernetes-04.png" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsysdig.com%2Fwp-content%2Fuploads%2Fexposed-Prometheus-Kubernetes-04.png" alt="Three Kubernetes threats: leaks, crypto mining and ransomware"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the talk, we exposed three examples and in each of them, the tools and services exploited are different. The important thing is that we already know where the weaknesses are.&lt;/p&gt;

&lt;h3&gt;
  
  
  Leak sensitive data
&lt;/h3&gt;

&lt;p&gt;In the first scenario, the exposed application is running on a Kubernetes cluster and the attacker wants to access the data without authorization. The first thing the attacker could check is if the application can be exploited through normal pentesting techniques, for example, with &lt;a href="https://sqlmap.org/" rel="noopener noreferrer"&gt;SQLmap&lt;/a&gt; the attacker can try to gain access to the data.&lt;/p&gt;

&lt;p&gt;But if this does not work, what is the next step?&lt;/p&gt;

&lt;p&gt;The attacker can check if the container has vulnerable dependencies or if the image used could be exploited, then see if the components or the node itself are exploitable. But everything seems to be fine. There are no &lt;strong&gt;CVE&lt;/strong&gt; matches and no known exploits that could be used to gain initial access.&lt;/p&gt;

&lt;p&gt;What’s next? Well, Prometheus exposed the image and registry that the attacker accessed, but what about attacking the supply chain? In this case, we have two scenarios:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Official/private registration&lt;/strong&gt;: In this case, the attacker could use similar image names, such as &lt;a href="https://github.com/bbvanexttechnologies/deep-confusables-cli/" rel="noopener noreferrer"&gt;homographs&lt;/a&gt;, visually similar by using different Unicode groups, to trick the target. Another technique could be to abuse an insider to manually change the exposed image. In this case, it depends on the financial gain of the attacker.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Third-party registry&lt;/strong&gt;: In this case, one of the methods could be social engineering, using tools like &lt;a href="https://beefproject.com/" rel="noopener noreferrer"&gt;BeeF&lt;/a&gt; to create a specific phishing or fake page to get the login credentials and change the image to a new one with a known and exploitable vulnerability and wait for the deployment. One more thing is this is not magic or 100% successful. If the company scans the images in the deployment, it could be detected!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Cryptomining
&lt;/h3&gt;

&lt;p&gt;In this scenario, one of the most relevant in the last years with the era of cloud, the attacker would like to get access to the cloud account where the application or Kubernetes cluster are deployed. The attacker could take two paths. The long path was to identify one app exposed via Ingress-controller that has a known vulnerability easily exploited via HTTP and obtain a Remote Code Execution inside the container.&lt;/p&gt;

&lt;p&gt;The vulnerability exploited in this case will be the infamous &lt;a href="https://sysdig.com/blog/exploit-detect-mitigate-log4j-cve/" rel="noopener noreferrer"&gt;log4shell&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Once the attacker has access to the container, they don’t even need to gather more information about the cluster or the node because Prometheus exposed this information as well. From that, we could directly exploit another vulnerability to &lt;a href="https://sysdig.com/blog/container-escape-capabilities-falco-detection/" rel="noopener noreferrer"&gt;escape to the container&lt;/a&gt; and get full access to the node without using more tools or scanning, evading typical defense methods.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: This is not 100% successful. If &lt;a href="https://sysdig.com/products/secure/runtime-security/" rel="noopener noreferrer"&gt;runtime security&lt;/a&gt; is used and the shell within the container is detected as malicious behavior, the incident will be detected before impacting resources.&lt;/p&gt;

&lt;p&gt;Now that the attacker has full control of the node, they will be able to deploy containers to run cryptominers, or find cloud credentials in configuration files or env variables to gain initial access.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://sysdig.com/wp-content/uploads/exposed-Prometheus-Kubernetes-05.png" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsysdig.com%2Fwp-content%2Fuploads%2Fexposed-Prometheus-Kubernetes-05.png" alt="Attacker path exploit Kubernetes Cluster by exposed Prometheus server"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But this is a long way, what’s the short way? Well, it is possible for Prometheus to directly expose credentials to these cloud providers in the same way that the Kubernetes Dashboard did in the past. Therefore, the attacker only needs to query the information via query and get the API keys in clear text.&lt;/p&gt;

&lt;h3&gt;
  
  
  Ransomware
&lt;/h3&gt;

&lt;p&gt;Yes, ransomware in Kubernetes is not typical but not impossible. The scenario is similar to the previous one. We need to get write access and for that, we need to jump or move between namespaces.&lt;/p&gt;

&lt;p&gt;In this case, we find another application with a different vulnerability, &lt;a href="https://sysdig.com/blog/cve-2022-22963-spring-cloud/" rel="noopener noreferrer"&gt;Spring Cloud&lt;/a&gt;, but with the same purpose: to get a shell inside the container.&lt;/p&gt;

&lt;p&gt;Once inside, we know that a Kubernetes component is an old vulnerable version that we can exploit to get access to etcd, and with that, full access to the namespaces.&lt;/p&gt;

&lt;p&gt;The curious thing here is after the data is encrypted, the attacker needs to ask for a ransom through some channel. In a typical scenario, our PC would be locked and the screen would show instructions to pay via BTC or ETH, but inside the container. We hate to share ideas with the bad guys, but one option could be to deploy a container with a modified UI and force ingress to display this in front of the actual application.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;We might think that metrics are not important from a security perspective, but we demonstrated that’s not true. &lt;strong&gt;Kubernetes&lt;/strong&gt; and &lt;strong&gt;Prometheus&lt;/strong&gt; advise problems with exposing your data to the world, but regardless, these problems are still widespread.&lt;/p&gt;

&lt;p&gt;Following the &lt;strong&gt;security best practices&lt;/strong&gt; in every part of our chain leads to being safe from most security incidents. Otherwise, we will change the typical scenario with a long battle between attackers and defenders for a speedrun.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://sysdig.com/wp-content/uploads/exposed-Prometheus-Kubernetes-06.png" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsysdig.com%2Fwp-content%2Fuploads%2Fexposed-Prometheus-Kubernetes-06.png" alt="Kubernetes threats speedrun"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We will have to continue to fight with new vulnerabilities that impact our services and also a plan against insiders. But let’s at least make things difficult for them.&lt;/p&gt;

&lt;p&gt;If you want to see the talk:&lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/5cbbm_L6n7w"&gt;
&lt;/iframe&gt;
&lt;br&gt;
The slides are available &lt;a href="https://sched.co/ytmB" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>security</category>
      <category>monitoring</category>
      <category>kuberentes</category>
      <category>devops</category>
    </item>
    <item>
      <title>Kubernetes 1.26 What's new?</title>
      <dc:creator>Javier Martínez</dc:creator>
      <pubDate>Thu, 01 Dec 2022 09:19:05 +0000</pubDate>
      <link>https://dev.to/sysdig/kubernetes-126-whats-new-4736</link>
      <guid>https://dev.to/sysdig/kubernetes-126-whats-new-4736</guid>
      <description>&lt;p&gt;&lt;strong&gt;Kubernetes 1.26&lt;/strong&gt; is about to be released, and it comes packed with novelties! Where do we begin?&lt;/p&gt;

&lt;p&gt;This release brings 37 enhancements, on par with the &lt;a href="https://sysdig.com/blog/kubernetes-1-25-whats-new/" rel="noopener noreferrer"&gt;40 in Kubernetes 1.25&lt;/a&gt; and the &lt;a href="https://sysdig.com/blog/kubernetes-1-24-whats-new/" rel="noopener noreferrer"&gt;46 in Kubernetes 1.24&lt;/a&gt;. Of those 37 enhancements, 11 are graduating to Stable, 10 are existing features that keep improving, 16 are completely new, and one is a deprecated feature.&lt;/p&gt;

&lt;p&gt;Watch out for all the &lt;a href="http://sysdig.com/blog/kubernetes-1-26-whats-new/#deprecations" rel="noopener noreferrer"&gt;deprecations and removals in this version&lt;/a&gt;!&lt;/p&gt;

&lt;p&gt;Two new features stand out in this release that have the potential to &lt;strong&gt;change the way users interact with Kubernetes&lt;/strong&gt;: Being able to &lt;a href="http://sysdig.com/blog/kubernetes-1-26-whats-new/#3294" rel="noopener noreferrer"&gt;provisioning volumes with snapshots from other namespaces&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;There are also new features aimed at &lt;strong&gt;high performance workloads&lt;/strong&gt;, like science researching or machine learning: Better &lt;a href="http://sysdig.com/blog/kubernetes-1-26-whats-new/#3545" rel="noopener noreferrer"&gt;what physical CPU cores your workloads run on&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Also, other features will make life easier for cluster administrators, like &lt;a href="http://sysdig.com/blog/kubernetes-1-26-whats-new/#3515" rel="noopener noreferrer"&gt;support for OpenAPIv3&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;We are really hyped about this release!&lt;/p&gt;

&lt;p&gt;There is plenty to talk about, so let's get started with what’s new in Kubernetes 1.25.&lt;/p&gt;

&lt;h2 id="editors"&gt;Kubernetes 1.26 – Editor’s pick:&lt;/h2&gt;

&lt;p&gt;These are the features that look most exciting to us in this release (ymmv):&lt;/p&gt;

&lt;h3&gt;
&lt;a href="http://sysdig.com/blog/kubernetes-1-26-whats-new/#3294" rel="noopener noreferrer"&gt;#3294&lt;/a&gt; Provision volumes from cross-namespace snapshots&lt;/h3&gt;





&lt;p&gt;The &lt;em&gt;VolumeSnapshot&lt;/em&gt; feature allows Kubernetes users provision volumes from volume snapshots, providing great benefits for users and applications, like enabling database administrators to snapshot a database before any critical operation, or the ability to develop and implement backup solutions.&lt;/p&gt;





&lt;p&gt;Starting in Kubernetes 1.26 as an Alpha feature, users will be able to create a &lt;em&gt;PersistentVolumeClaim&lt;/em&gt; from a &lt;em&gt;VolumeSnapshot&lt;/em&gt; across namespaces, breaking the initial limitation of having both objects in the same namespace.&lt;/p&gt;





&lt;p&gt;This enhancement comes to eliminate the constraints that prevented users and applications from operating on fundamental tasks, like saving a database checkpoint when applications and services are in different namespaces.&lt;/p&gt;





&lt;p&gt;&lt;em&gt;&lt;a rel="noopener nofollow noreferrer" href="https://www.linkedin.com/in/v%C3%ADctor-hernando-martin-49836334/"&gt;Víctor Hernando&lt;/a&gt; - Sr. Technical Marketing Manager at Sysdig&lt;/em&gt;&lt;/p&gt;





&lt;h3&gt;
&lt;a href="http://sysdig.com/blog/kubernetes-1-26-whats-new/#3488" rel="noopener noreferrer"&gt;#3488&lt;/a&gt; CEL for admission control&lt;/h3&gt;





&lt;p&gt;Finally, a practical implementation of the validation expression language from Kubernetes 1.25!&lt;/p&gt;





&lt;p&gt;By defining rules for the admission controller as Kubernetes objects, we can start forgetting about managing webhooks, simplifying the setup of our clusters. Not only that, but implementing &lt;a href="https://sysdig.com/learn-cloud-native/kubernetes-security/kubernetes-security-101/" rel="noopener noreferrer"&gt;Kubernetes security&lt;/a&gt; is a bit easier now.&lt;/p&gt;





&lt;p&gt;We love to see these user-friendly improvements. They are the key to keep growing Kubernetes adoption.&lt;/p&gt;





&lt;p&gt;&lt;em&gt;&lt;a rel="noopener nofollow noreferrer" href="https://www.linkedin.com/in/victorjimenez/"&gt;Víctor Jiménez Cerrada&lt;/a&gt; - Content Engineering Manager at Sysdig&lt;/em&gt;&lt;/p&gt;





&lt;h3&gt;
&lt;a href="http://sysdig.com/blog/kubernetes-1-26-whats-new/#3466" rel="noopener noreferrer"&gt;#3466&lt;/a&gt; Kubernetes component health SLIs&lt;/h3&gt;





&lt;p&gt;Since Kubernetes 1.26, you can configure Service Level Indicator (SLI) metrics for the Kubernetes components binaries. Once you enable them, Kubernetes will expose the SLI metrics in the &lt;code&gt;/metrics/slis&lt;/code&gt; endpoint - so you won't need a Prometheus exporter. This can take &lt;a href="https://sysdig.com/blog/kubernetes-monitoring-prometheus/" rel="noopener noreferrer"&gt;Kubernetes monitoring&lt;/a&gt; to another level making it easier to create health dashboards and configure PromQL alerts to assure your cluster's stability.&lt;/p&gt;





&lt;p&gt;&lt;em&gt;&lt;a rel="noopener nofollow noreferrer" href="https://twitter.com/eckelon"&gt;Jesús Ángel Samitier&lt;/a&gt; - Integrations Engineer at Sysdig&lt;/em&gt;&lt;/p&gt;





&lt;h3&gt;
&lt;a href="http://sysdig.com/blog/kubernetes-1-26-whats-new/#2371" rel="noopener noreferrer"&gt;#2371&lt;/a&gt; cAdvisor-less, CRI-full container and &lt;em&gt;Pod&lt;/em&gt; stats&lt;/h3&gt;





&lt;p&gt;Currently, to gather metrics from containers, such as CPU or memory consumed, Kubernetes relies on cAdvisor. This feature presents an alternative, enriching the CRI API to provide all the metrics from the containers, allowing more flexibility and better accuracy. After all, it's the Container Runtime who best knows the behavior of the container.&lt;/p&gt;





&lt;p&gt;This feature represents one more step on the roadmap to remove cAdvisor from Kubernetes code. However, during this transition, cAdvisor will be modified not to generate the metrics added to the CRI API, avoiding duplicated metrics with possible different and incoherent values.&lt;/p&gt;





&lt;p&gt;&lt;em&gt;&lt;a rel="noopener nofollow noreferrer" href="https://twitter.com/maellyssa"&gt;David de Torres Huerta&lt;/a&gt; – Engineer Manager at Sysdig&lt;/em&gt;&lt;/p&gt;





&lt;h3&gt;
&lt;a href="http://sysdig.com/blog/kubernetes-1-26-whats-new/#3063" rel="noopener noreferrer"&gt;#3063&lt;/a&gt; Dynamic resource allocation&lt;/h3&gt;





&lt;p&gt;This new Kubernetes release introduces a new Alpha feature which will provide extended resource management for advanced hardware. As a cherry on top, it comes with a user-friendly API to describe resource requests. With the increasing demand to process different hardware components, like GPU or FPGA, and the need to set up initialization and cleanup, this new feature will speed up Kubernetes adoption in areas like scientific research or edge computing.&lt;/p&gt;





&lt;p&gt;&lt;em&gt;&lt;a rel="noopener nofollow noreferrer" href="https://www.linkedin.com/in/javier-martinez-2b2a955/"&gt;Javier Martínez&lt;/a&gt; - Devops Content Engineer at Sysdig&lt;/em&gt;&lt;/p&gt;





&lt;h3&gt;
&lt;a href="http://sysdig.com/blog/kubernetes-1-26-whats-new/#3545" rel="noopener noreferrer"&gt;#3545&lt;/a&gt; Improved multi-numa alignment in Topology Manager&lt;/h3&gt;





&lt;p&gt;This is yet another feature aimed at high performance workloads, like those involved in scientific computing. We are seeing the new CPU manager taking shape since Kubernetes 1.22 and 1.23, enabling developers to keep their workloads close to where their data is stored in memory, improving performance. Kubernetes 1.26 goes a step further, opening the door to further customizations for this feature. After all, not all workloads and CPU architectures are the same.&lt;/p&gt;





&lt;p&gt;The future of HPC on Kubernetes is looking quite promising, indeed.&lt;/p&gt;





&lt;p&gt;&lt;em&gt;&lt;a rel="noopener nofollow noreferrer" href="https://www.linkedin.com/in/vjjmiras/"&gt;Vicente J. Jiménez Miras&lt;/a&gt; – Security Content Engineer at Sysdig&lt;/em&gt;&lt;/p&gt;





&lt;h3&gt;
&lt;a href="http://sysdig.com/blog/kubernetes-1-26-whats-new/#3335" rel="noopener noreferrer"&gt;#3335&lt;/a&gt; Allow StatefulSet to control start replica ordinal numbering&lt;/h3&gt;





&lt;p&gt;&lt;em&gt;StatefulSets&lt;/em&gt; in Kubernetes often are critical backend services, like clustered databases or message queues.&lt;br&gt;This enhancement, seemingly a trivial numbering change, allows for greater flexibility and enables new techniques for rolling cross-namespace or even cross-cluster migrations of the replicas of the &lt;em&gt;StatefulSet&lt;/em&gt; &lt;strong&gt;without any downtime&lt;/strong&gt;. While the process might seem a bit clunky, involving careful definition of &lt;em&gt;PodDisruptionBudgets&lt;/em&gt; and the moving of resources relative to the migrating replica, we can surely envision tools (or existing operators enhancements) that automate these operations for &lt;strong&gt;seamless migrations&lt;/strong&gt;, in stark contrast with the cold-migration strategy (shutdown-backup-restore) that is currently possible.&lt;/p&gt;





&lt;p&gt;&lt;em&gt;&lt;a rel="noopener nofollow noreferrer" href="https://www.linkedin.com/in/danielsimionato/"&gt;Daniel Simionato&lt;/a&gt; - Security Content Engineer at Sysdig&lt;/em&gt;&lt;/p&gt;





&lt;h3&gt;
&lt;a href="http://sysdig.com/blog/kubernetes-1-26-whats-new/#3325" rel="noopener noreferrer"&gt;#3325&lt;/a&gt; Auth API to get self user attributes&lt;/h3&gt;





&lt;p&gt;This new feature coming to alpha will simplify cluster Administrator's work, especially when they are managing multiple clusters. It will also assist in complex authentication flows, as it lets users query their user information or permissions inside the cluster.&lt;/p&gt;





&lt;p&gt;Also, this includes whether you are using a proxy (Kubernetes API server fills in the &lt;code&gt;userInfo&lt;/code&gt; after all authentication mechanisms are applied) or impersonating (you receive the details and properties for the user that was impersonated), so you will have your user information in a very easy way.&lt;/p&gt;





&lt;p&gt;&lt;em&gt;&lt;a rel="noopener nofollow noreferrer" href="https://www.linkedin.com/in/miguelhzbz/"&gt;Miguel Hernández&lt;/a&gt; - Security Content Engineer at Sysdig&lt;/em&gt;&lt;/p&gt;





&lt;h3&gt;
&lt;a href="http://sysdig.com/blog/kubernetes-1-26-whats-new/#3352" rel="noopener noreferrer"&gt;#3352&lt;/a&gt; Aggregated Discovery&lt;/h3&gt;





&lt;p&gt;This is a tiny change for the users, but one step further on cleaning the Kubernetes internals and improving its performance. Reducing the number of API calls by aggregating them (or at least on the discovery part) is a nice solution to a growing problem. Hopefully, this will provide a small break to cluster administrators.&lt;/p&gt;





&lt;p&gt;&lt;em&gt;&lt;a rel="noopener nofollow noreferrer" href="https://www.linkedin.com/in/ddok/"&gt;Devid Dokash&lt;/a&gt; - Content Engineering Intern at Sysdig&lt;/em&gt;&lt;/p&gt;





&lt;h2 id="deprecations"&gt;Deprecations&lt;/h2&gt;





&lt;p&gt;A few beta APIs and features have been removed in Kubernetes 1.26, including:&lt;/p&gt;





&lt;p&gt;&lt;strong&gt;Deprecated &lt;a rel="noopener nofollow noreferrer" href="https://kubernetes.io/docs/reference/using-api/deprecation-guide/#v1-25"&gt;API versions&lt;/a&gt;&lt;/strong&gt; that are no longer served, and you should use a newer one:&lt;/p&gt;





&lt;ul&gt;
&lt;li&gt;CRI &lt;code&gt;v1alpha2&lt;/code&gt;, use &lt;code&gt;v1&lt;/code&gt; (&lt;em&gt;containerd&lt;/em&gt; version 1.5 and older are not supported).&lt;/li&gt;



&lt;li&gt;
&lt;code&gt;flowcontrol.apiserver.k8s.io/v1beta1&lt;/code&gt;, use &lt;code&gt;v1beta2&lt;/code&gt;.&lt;/li&gt;



&lt;li&gt;
&lt;code&gt;autoscaling/v2beta2&lt;/code&gt;, use &lt;code&gt;v2&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;





&lt;p&gt;&lt;strong&gt;Deprecated&lt;/strong&gt;. Implement an alternative before the next release goes out:&lt;/p&gt;





&lt;ul&gt;
&lt;li&gt;In-tree GlusterFS driver.&lt;/li&gt;



&lt;li&gt;
&lt;code&gt;kubectl --prune-whitelist&lt;/code&gt;, use &lt;code&gt;--prune-allowlist&lt;/code&gt; instead.&lt;/li&gt;



&lt;li&gt;
&lt;code&gt;kube-apiserver --master-service-namespace&lt;/code&gt;.&lt;/li&gt;



&lt;li&gt;Several unused options for &lt;code&gt;kubectl run&lt;/code&gt;: &lt;code&gt;--cascade&lt;/code&gt;, &lt;code&gt;--filename&lt;/code&gt;, &lt;code&gt;--force&lt;/code&gt;, &lt;code&gt;--grace-period&lt;/code&gt;, &lt;code&gt;--kustomize&lt;/code&gt;, &lt;code&gt;--recursive&lt;/code&gt;, &lt;code&gt;--timeout&lt;/code&gt;, &lt;code&gt;--wait&lt;/code&gt;.&lt;/li&gt;



&lt;li&gt;CLI flag &lt;code&gt;pod-eviction-timeout&lt;/code&gt;.&lt;/li&gt;



&lt;li&gt;The &lt;code&gt;apiserver_request_slo_duration_seconds&lt;/code&gt; metric, use &lt;code&gt;apiserver_request_sli_duration_seconds&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;





&lt;p&gt;&lt;strong&gt;Removed&lt;/strong&gt;. Implement an alternative before upgrading:&lt;/p&gt;





&lt;ul&gt;
&lt;li&gt;Legacy authentication for Azure and Google Cloud is deprecated.&lt;/li&gt;



&lt;li&gt;The &lt;code&gt;userspace&lt;/code&gt; proxy mode.&lt;/li&gt;



&lt;li&gt;Dynamic &lt;em&gt;kubelet&lt;/em&gt; configuration.&lt;/li&gt;



&lt;li&gt;Several &lt;a href="https://sysdig.com/blog/kubernetes-1-23-whats-new/#2845" rel="noopener noreferrer"&gt;command line arguments related to logging&lt;/a&gt;.&lt;/li&gt;



&lt;li&gt;in-tree OpenStack (&lt;code&gt;cinder&lt;/code&gt; volume type), use &lt;a rel="noopener nofollow noreferrer" href="https://github.com/kubernetes/cloud-provider-openstack"&gt;the CSI driver&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;





&lt;p&gt;&lt;strong&gt;Other changes&lt;/strong&gt; you should adapt your configs for:&lt;/p&gt;





&lt;ul&gt;
&lt;li&gt;Pod Security admission: the pod-security &lt;code&gt;warn&lt;/code&gt; level will now default to the &lt;code&gt;enforce&lt;/code&gt; level.&lt;/li&gt;



&lt;li&gt;kubelet: The default &lt;code&gt;cpuCFSQuotaPeriod&lt;/code&gt; value with the &lt;code&gt;cpuCFSQuotaPeriod&lt;/code&gt; flag enabled is now 100µs instead of 100ms.&lt;/li&gt;



&lt;li&gt;kubelet: The &lt;code&gt;--container-runtime-endpoint&lt;/code&gt; flag cannot be empty anymore.&lt;/li&gt;



&lt;li&gt;kube-apiserver: gzip compression switched from level 4 to level 1.&lt;/li&gt;



&lt;li&gt;Metrics: Changed &lt;code&gt;preemption_victims&lt;/code&gt; from &lt;code&gt;LinearBuckets&lt;/code&gt; to &lt;code&gt;ExponentialBuckets&lt;/code&gt;.&lt;/li&gt;



&lt;li&gt;Metrics: &lt;code&gt;etcd_db_total_size_in_bytes&lt;/code&gt; is renamed to &lt;code&gt;apiserver_storage_db_total_size_in_bytes&lt;/code&gt;.&lt;/li&gt;



&lt;li&gt;Metrics: &lt;code&gt;kubelet_kubelet_credential_provider_plugin_duration&lt;/code&gt; is renamed &lt;code&gt;kubelet_credential_provider_plugin_duration&lt;/code&gt;.&lt;/li&gt;



&lt;li&gt;Metrics: &lt;code&gt;kubelet_kubelet_credential_provider_plugin_errors&lt;/code&gt; is renamed &lt;code&gt;kubelet_credential_provider_plugin_errors&lt;/code&gt;.&lt;/li&gt;



&lt;li&gt;Removed Windows Server, Version 20H2 flavors from various container images.&lt;/li&gt;



&lt;li&gt;The e2e.test binary no longer emits JSON structs to document progress.&lt;/li&gt;
&lt;/ul&gt;





&lt;p&gt;You can check the full list of changes in the &lt;a rel="noopener nofollow noreferrer" href="https://github.com/kubernetes/kubernetes/blob/master/CHANGELOG/CHANGELOG-1.26.md"&gt;Kubernetes 1.26 release notes&lt;/a&gt;. Also, we recommend the &lt;a rel="noopener nofollow noreferrer" href="https://kubernetes.io/blog/2022/11/18/upcoming-changes-in-kubernetes-1-26/"&gt;Kubernetes Removals and Deprecations In 1.26&lt;/a&gt; article, as well as keeping the &lt;a rel="noopener nofollow noreferrer" href="https://kubernetes.io/docs/reference/using-api/deprecation-guide/"&gt;deprecated API migration guide&lt;/a&gt; close for the future.&lt;/p&gt;





&lt;h3 id="281"&gt;
&lt;a rel="noopener nofollow noreferrer" href="https://github.com/kubernetes/enhancements/issues/281"&gt;#281&lt;/a&gt; Dynamic Kubelet configuration&lt;/h3&gt;





&lt;p&gt;&lt;strong&gt;Feature group:&lt;/strong&gt; node&lt;/p&gt;





&lt;p&gt;After being in beta since Kubernetes 1.11, the Kubernetes team &lt;a rel="noopener nofollow noreferrer" href="https://github.com/kubernetes/kubernetes/issues/100799"&gt;has decided&lt;/a&gt; to deprecate &lt;code&gt;DynamicKubeletConfig&lt;/code&gt; instead of continuing its development.&lt;/p&gt;





&lt;p&gt;This feature was marked for deprecation in 1.21, then removed from the Kubelet in 1.24. Now in 1.26, it has been &lt;a rel="noopener nofollow noreferrer" href="https://github.com/kubernetes/enhancements/pull/3605/files#diff-138ec4a122ef9ea3b885191796faf63ca6511747e4be18840dd67ffa2a386d1d"&gt;completely removed from Kubernetes&lt;/a&gt;.&lt;/p&gt;





&lt;h2 id="api"&gt;Kubernetes 1.26 API&lt;/h2&gt;





&lt;h3 id="3352"&gt;
&lt;a rel="noopener nofollow noreferrer" href="https://github.com/kubernetes/enhancements/issues/3352"&gt;#3352&lt;/a&gt; Aggregated discovery&lt;/h3&gt;





&lt;p&gt;&lt;strong&gt;Stage:&lt;/strong&gt; Net new to Alpha&lt;br&gt;&lt;strong&gt;Feature group:&lt;/strong&gt; api-machinery&lt;br&gt;&lt;strong&gt;Feature gate:&lt;/strong&gt; &lt;code&gt;AggregatedDiscoveryEndpoint&lt;/code&gt; &lt;strong&gt;Default value:&lt;/strong&gt; &lt;code&gt;false&lt;/code&gt;&lt;/p&gt;





&lt;p&gt;Every Kubernetes client like &lt;code&gt;kubectl&lt;/code&gt; needs to discover what APIs and versions of those APIs are available in the &lt;code&gt;kubernetes-apiserver&lt;/code&gt;. For that, they need to make a request per each API and version, which causes a storm of requests.&lt;/p&gt;





&lt;p&gt;This enhancement aims to reduce all those calls to just two.&lt;/p&gt;





&lt;p&gt;Clients can include &lt;code&gt;as=APIGroupDiscoveryList&lt;/code&gt; to the &lt;code&gt;Accept&lt;/code&gt; field of their requests to the &lt;code&gt;/api&lt;/code&gt; and &lt;code&gt;/apis&lt;/code&gt; endpoints. Then, the server will return an aggregated document (&lt;code&gt;APIGroupDiscoveryList&lt;/code&gt;) with all the available APIs and their versions.&lt;/p&gt;





&lt;h3 id="3488"&gt;
&lt;a rel="noopener nofollow noreferrer" href="https://github.com/kubernetes/enhancements/issues/3488"&gt;#3488&lt;/a&gt; CEL for admission control&lt;/h3&gt;





&lt;p&gt;&lt;strong&gt;Stage:&lt;/strong&gt; Net new to Alpha&lt;br&gt;&lt;strong&gt;Feature group:&lt;/strong&gt; api-machinery&lt;/p&gt;





&lt;p&gt;&lt;strong&gt;Feature gate:&lt;/strong&gt; &lt;code&gt;ValidatingAdmissionPolicy&lt;/code&gt; &lt;strong&gt;Default value:&lt;/strong&gt; &lt;code&gt;false&lt;/code&gt;&lt;/p&gt;





&lt;p&gt;Building on &lt;a href="https://sysdig.com/blog/kubernetes-1-25-whats-new/#2876" rel="noopener noreferrer"&gt;#2876 CRD validation expression language&lt;/a&gt; from Kubernetes 1.25, this enhancement provides a new admission controller type (&lt;code&gt;ValidatingAdmissionPolicy&lt;/code&gt;) that allows implementing some validations without relying on webhooks.&lt;/p&gt;





&lt;p&gt;These new policies can be defined like:&lt;/p&gt;





&lt;pre&gt;&lt;code&gt; apiVersion: admissionregistration.k8s.io/v1alpha1
 kind: ValidatingAdmissionPolicy
 metadata:
   name: "demo-policy.example.com"
 Spec:
   failurePolicy: Fail
   matchConstraints:
     resourceRules:
     - apiGroups:   ["apps"]
       apiVersions: ["v1"]
       operations:  ["CREATE", "UPDATE"]
       resources:   ["deployments"]
   validations:
     - expression: "object.spec.replicas &amp;lt;= 5"
&lt;/code&gt;&lt;/pre&gt;





&lt;p&gt;This policy would deny requests for some deployments with &lt;code&gt;5&lt;/code&gt; replicas or less.&lt;/p&gt;





&lt;p&gt;Discover the full power of this feature &lt;a rel="noopener nofollow noreferrer" href="https://github.com/kubernetes/website/blob/9a8c421c1e18dd9485788f1ffc23944c41e91483/content/en/docs/reference/access-authn-authz/validating-admission-policy.md"&gt;in the docs&lt;/a&gt;.&lt;/p&gt;





&lt;h3 id="1965"&gt;
&lt;a rel="noopener nofollow noreferrer" href="https://github.com/kubernetes/enhancements/issues/1965"&gt;#1965&lt;/a&gt; &lt;em&gt;kube-apiserver&lt;/em&gt; identity&lt;/h3&gt;





&lt;p&gt;&lt;strong&gt;Stage:&lt;/strong&gt; Graduating to Beta&lt;br&gt;&lt;strong&gt;Feature group:&lt;/strong&gt; api-machinery&lt;br&gt;&lt;strong&gt;Feature gate:&lt;/strong&gt; &lt;code&gt;APIServerIdentity&lt;/code&gt; &lt;strong&gt;Default value:&lt;/strong&gt; &lt;code&gt;true&lt;/code&gt;&lt;/p&gt;





&lt;p&gt;In order to better control which &lt;em&gt;kube-apiservers&lt;/em&gt; are alive in a high availability cluster, a new lease / heartbeat system has been implemented.&lt;/p&gt;





&lt;p&gt;Read more in our "&lt;a href="https://sysdig.com/blog/whats-new-kubernetes-1-20/#1965" rel="noopener noreferrer"&gt;What's new in Kubernetes 1.20&lt;/a&gt;" article.&lt;/p&gt;





&lt;h2 id="apps"&gt;Apps in Kubernetes 1.26&lt;/h2&gt;





&lt;h3 id="3017"&gt;
&lt;a rel="noopener nofollow noreferrer" href="https://github.com/kubernetes/enhancements/issues/3017"&gt;#3017&lt;/a&gt; &lt;em&gt;PodHealthyPolicy&lt;/em&gt; for &lt;em&gt;PodDisruptionBudget&lt;/em&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Stage:&lt;/strong&gt; Net new to Alpha&lt;br&gt;&lt;strong&gt;Feature group:&lt;/strong&gt; apps&lt;br&gt;&lt;strong&gt;Feature gate:&lt;/strong&gt; &lt;code&gt;PDBUnhealthyPodEvictionPolicy&lt;/code&gt; &lt;strong&gt;Default value:&lt;/strong&gt; &lt;code&gt;false&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;A &lt;em&gt;&lt;a rel="noopener nofollow noreferrer" href="https://kubernetes.io/docs/tasks/run-application/configure-pdb/"&gt;PodDisruptionBudget&lt;/a&gt;&lt;/em&gt; allows you to communicate some minimums to your cluster administrator to make maintenance tasks easier, like "Do not destroy more than one of these" or "Keep at least two of these alive".&lt;/p&gt;

&lt;p&gt;However, this only takes into account if the pods are running, not if they are healthy. It may happen that your pods are Running but not Ready, and a &lt;em&gt;PodDisruptionBudget&lt;/em&gt; may be preventing its eviction.&lt;/p&gt;

&lt;p&gt;This enhancement expands these budget definitions with the &lt;code&gt;status.currentHealthy&lt;/code&gt;, &lt;code&gt;status.desiredHealthy&lt;/code&gt;, and &lt;code&gt;spec.unhealthyPodEvictionPolicy&lt;/code&gt; extra fields to help you define how to manage unhealthy pods.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ kubectl get poddisruptionbudgets example-pod
apiVersion: policy/v1
kind: PodDisruptionBudget
[...]
status:
  currentHealthy: 3
  desiredHealthy: 2
  disruptionsAllowed: 1
  expectedPods: 3
  observedGeneration: 1
  unhealthyPodEvictionPolicy: IfHealthyBudget
&lt;/code&gt;&lt;/pre&gt;

&lt;h3 id="3335"&gt;
&lt;a rel="noopener nofollow noreferrer" href="https://github.com/kubernetes/enhancements/issues/3335"&gt;#3335&lt;/a&gt; Allow &lt;em&gt;StatefulSet&lt;/em&gt; to control start replica ordinal numbering&lt;/h3&gt;





&lt;p&gt;&lt;strong&gt;Stage:&lt;/strong&gt; Net new to Alpha&lt;br&gt;&lt;strong&gt;Feature group:&lt;/strong&gt; apps&lt;br&gt;&lt;strong&gt;Feature gate:&lt;/strong&gt; &lt;code&gt;StatefulSetStartOrdinal&lt;/code&gt; &lt;strong&gt;Default value:&lt;/strong&gt; &lt;code&gt;false&lt;/code&gt;&lt;/p&gt;





&lt;p&gt;&lt;em&gt;StatefulSets&lt;/em&gt; in Kubernetes currently number their pods using ordinal numbers, with the first replica being &lt;code&gt;0&lt;/code&gt; and the last being &lt;code&gt;spec.replicas&lt;/code&gt;.&lt;/p&gt;





&lt;p&gt;This enhancement adds a new struct with a single field to the &lt;em&gt;StatefulSet&lt;/em&gt; manifest spec,&lt;code&gt; spec.ordinals.start&lt;/code&gt;, which allows to define the starting number for the replicas controlled by the &lt;em&gt;StatefulSet&lt;/em&gt;.&lt;/p&gt;





&lt;p&gt;This is useful, for example, in cross-namespace or cross-cluster migrations of &lt;em&gt;StatefulSet&lt;/em&gt;, where a clever use of &lt;em&gt;PodDistruptionBudgets&lt;/em&gt; (and multi-cluster services) can allow a controlled rolling migration of the replicas avoiding any downtime to the &lt;em&gt;StatefulSet&lt;/em&gt;.&lt;/p&gt;





&lt;h3 id="3329"&gt;
&lt;a rel="noopener nofollow noreferrer" href="https://github.com/kubernetes/enhancements/issues/3329"&gt;#3329&lt;/a&gt; Retriable and non-retriable &lt;em&gt;Pod&lt;/em&gt; failures for &lt;em&gt;Jobs&lt;/em&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Stage:&lt;/strong&gt; Graduating to Beta&lt;br&gt;&lt;strong&gt;Feature group:&lt;/strong&gt; apps&lt;br&gt;&lt;strong&gt;Feature gate:&lt;/strong&gt; &lt;code&gt;JobPodFailurePolicy&lt;/code&gt; &lt;strong&gt;Default value:&lt;/strong&gt; &lt;code&gt;true&lt;br&gt;&lt;strong&gt;Feature gate:&lt;/strong&gt;&lt;/code&gt; &lt;code&gt;PodDisruptionsCondition&lt;/code&gt; &lt;strong&gt;Default value:&lt;/strong&gt; &lt;code&gt;true&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This enhancement allows us to configure a &lt;code&gt;.spec.podFailurePolicy&lt;/code&gt; on the &lt;a rel="noopener nofollow noreferrer" href="https://kubernetes.io/docs/concepts/workloads/controllers/job/"&gt;Jobs&lt;/a&gt;'s spec that determines whether the Job should be retried or not in case of failure. This way, Kubernetes can terminate Jobs early, avoiding increasing the backoff time in case of infrastructure failures or application errors.&lt;/p&gt;

&lt;p&gt;Read more in our "&lt;a href="https://sysdig.com/blog/kubernetes-1-25-whats-new/#3329" rel="noopener noreferrer"&gt;What's new in Kubernetes 1.25&lt;/a&gt;" article.&lt;/p&gt;

&lt;h3 id="2307"&gt;
&lt;a rel="noopener nofollow noreferrer" href="https://github.com/kubernetes/enhancements/issues/2307"&gt;#2307&lt;/a&gt; &lt;em&gt;Job&lt;/em&gt; tracking without lingering &lt;em&gt;Pods&lt;/em&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Stage:&lt;/strong&gt; Graduating to Stable&lt;br&gt;&lt;strong&gt;Feature group:&lt;/strong&gt; apps&lt;br&gt;&lt;strong&gt;Feature gate:&lt;/strong&gt; &lt;code&gt;JobTrackingWithFinalizers&lt;/code&gt; &lt;strong&gt;Default value:&lt;/strong&gt; &lt;code&gt;true&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;With this enhancement, Jobs will be able to remove completed pods earlier, freeing resources in the cluster.&lt;/p&gt;

&lt;p&gt;Read more in our "&lt;a href="https://sysdig.com/blog/kubernetes-1-22-whats-new/#2307" rel="noopener noreferrer"&gt;Kubernetes 1.22 - What's new?&lt;/a&gt;" article.&lt;/p&gt;

&lt;h2 id="auth"&gt;Kubernetes 1.26 Auth&lt;/h2&gt;

&lt;h3 id="3325"&gt;
&lt;a rel="noopener nofollow noreferrer" href="https://github.com/kubernetes/enhancements/issues/3325"&gt;#3325&lt;/a&gt; Auth &lt;em&gt;API&lt;/em&gt; to get self user attributes&lt;/h3&gt;





&lt;p&gt;&lt;strong&gt;Stage:&lt;/strong&gt; Net new to Alpha&lt;br&gt;&lt;strong&gt;Feature group:&lt;/strong&gt; auth&lt;br&gt;&lt;strong&gt;Feature gate:&lt;/strong&gt; &lt;code&gt;APISelfSubjectAttributesReview&lt;/code&gt; &lt;strong&gt;Default value:&lt;/strong&gt; &lt;code&gt;false&lt;/code&gt;&lt;/p&gt;





&lt;p&gt;This new feature is extremely useful when a complicated authentication flow is used in a Kubernetes cluster, and you want to know all your &lt;code&gt;userInfo&lt;/code&gt;, after all authentication mechanisms are applied.&lt;/p&gt;





&lt;p&gt;Executing &lt;code&gt;kubectl alpha auth whoami&lt;/code&gt; will produce the following output:&lt;/p&gt;





&lt;pre&gt;&lt;code&gt;apiVersion: authentication.k8s.io/v1alpha1
kind: SelfSubjectReview
status:
  userInfo:
    username: jane.doe
    uid: b79dbf30-0c6a-11ed-861d-0242ac120002
    groups:
    - students
    - teachers
    - system:authenticated
    extra:
      skills:
      - reading
      - learning
      subjects:
      - math
      - sports
&lt;/code&gt;&lt;/pre&gt;





&lt;p&gt;In summary, we are now allowed to do a typical &lt;em&gt;/me&lt;/em&gt; to know our own permissions once we are authenticated in the cluster.&lt;/p&gt;





&lt;h3 id="2799"&gt;
&lt;a rel="noopener nofollow noreferrer" href="https://github.com/kubernetes/enhancements/issues/2799"&gt;#2799&lt;/a&gt; Reduction of secret-based service account tokens&lt;/h3&gt;





&lt;p&gt;&lt;strong&gt;Stage:&lt;/strong&gt; Graduating to Beta&lt;br&gt;&lt;strong&gt;Feature group:&lt;/strong&gt; auth&lt;br&gt;&lt;strong&gt;Feature gate:&lt;/strong&gt; &lt;code&gt;LegacyServiceAccountTokenNoAutoGeneration&lt;/code&gt; &lt;strong&gt;Default value:&lt;/strong&gt; &lt;code&gt;true&lt;/code&gt;&lt;/p&gt;





&lt;p&gt;API credentials are now obtained through the &lt;a rel="noopener nofollow noreferrer" href="https://kubernetes.io/docs/reference/kubernetes-api/authentication-resources/token-request-v1/"&gt;TokenRequest API&lt;/a&gt;, are stable since &lt;a href="https://sysdig.com/blog/kubernetes-1-22-whats-new/#542" rel="noopener noreferrer"&gt;Kubernetes 1.22&lt;/a&gt;, and are mounted into Pods using a projected volume. They will be automatically invalidated when their associated Pod is deleted.&lt;/p&gt;





&lt;p&gt;Read more in our "&lt;a href="https://sysdig.com/blog/kubernetes-1-24-whats-new/#2799" rel="noopener noreferrer"&gt;Kubernetes 1.24 - What's new?&lt;/a&gt;" article.&lt;/p&gt;





&lt;h2 id="network"&gt;Network in Kubernetes 1.26&lt;/h2&gt;





&lt;h3 id="3453"&gt;
&lt;a rel="noopener nofollow noreferrer" href="https://github.com/kubernetes/enhancements/issues/3453"&gt;#3453&lt;/a&gt; Minimizing &lt;em&gt;iptables-restore&lt;/em&gt; input size&lt;/h3&gt;





&lt;p&gt;&lt;strong&gt;Stage:&lt;/strong&gt; Net new to Alpha&lt;br&gt;&lt;strong&gt;Feature group:&lt;/strong&gt; network&lt;br&gt;&lt;strong&gt;Feature gate:&lt;/strong&gt; &lt;code&gt;MinimizeIPTablesRestore&lt;/code&gt; &lt;strong&gt;Default value:&lt;/strong&gt; &lt;code&gt;false&lt;/code&gt;&lt;/p&gt;





&lt;p&gt;This enhancement aims to improve the performance of &lt;code&gt;kube-proxy&lt;/code&gt;. It will do so by only sending the rules that have changed on the calls to &lt;code&gt;iptables-restore&lt;/code&gt;, instead of the whole set of rules.&lt;/p&gt;





&lt;h3 id="1669"&gt;
&lt;a rel="noopener nofollow noreferrer" href="https://github.com/kubernetes/enhancements/issues/1669"&gt;#1669&lt;/a&gt; &lt;em&gt;Proxy&lt;/em&gt; terminating endpoints&lt;/h3&gt;





&lt;p&gt;&lt;strong&gt;Stage:&lt;/strong&gt; Graduating to Beta&lt;br&gt;&lt;strong&gt;Feature group:&lt;/strong&gt; network&lt;br&gt;&lt;strong&gt;Feature gate:&lt;/strong&gt; &lt;code&gt;ProxyTerminatingEndpoints&lt;/code&gt; &lt;strong&gt;Default value:&lt;/strong&gt; &lt;code&gt;true&lt;/code&gt;&lt;/p&gt;





&lt;p&gt;This enhancement prevents traffic drops during rolling updates by sending all external traffic to both ready and not ready terminating endpoints (preferring the ready ones).&lt;/p&gt;





&lt;p&gt;Read more in our "&lt;a href="https://sysdig.com/blog/kubernetes-1-22-whats-new/#1669" rel="noopener noreferrer"&gt;Kubernetes 1.22 - What's new?&lt;/a&gt;" article.&lt;/p&gt;





&lt;h3 id="2595"&gt;
&lt;a rel="noopener nofollow noreferrer" href="https://github.com/kubernetes/enhancements/issues/2595"&gt;#2595&lt;/a&gt; Expanded DNS configuration&lt;/h3&gt;





&lt;p&gt;&lt;strong&gt;Stage:&lt;/strong&gt; Graduating to Beta&lt;br&gt;&lt;strong&gt;Feature group:&lt;/strong&gt; network&lt;br&gt;&lt;strong&gt;Feature gate:&lt;/strong&gt; &lt;code&gt;ExpandedDNSConfig&lt;/code&gt; &lt;strong&gt;Default value:&lt;/strong&gt; &lt;code&gt;true&lt;/code&gt;&lt;/p&gt;





&lt;p&gt;With this enhancement, Kubernetes allows up to 32 DNS in the search path, and an increased number of characters for the search path (up to 2048), to keep up with recent DNS resolvers.&lt;/p&gt;





&lt;p&gt;Read more in our "&lt;a href="https://sysdig.com/blog/kubernetes-1-22-whats-new/#2595" rel="noopener noreferrer"&gt;Kubernetes 1.22 - What's new?&lt;/a&gt;" article.&lt;/p&gt;





&lt;h3 id="1435"&gt;
&lt;a rel="noopener nofollow noreferrer" href="https://github.com/kubernetes/enhancements/issues/1435"&gt;#1435&lt;/a&gt; Support of mixed protocols in &lt;em&gt;Services&lt;/em&gt; with &lt;em&gt;type=LoadBalancer&lt;/em&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Stage:&lt;/strong&gt; Graduating to Stable&lt;br&gt;&lt;strong&gt;Feature group:&lt;/strong&gt; network&lt;br&gt;&lt;strong&gt;Feature gate:&lt;/strong&gt; &lt;code&gt;MixedProtocolLBService&lt;/code&gt; &lt;strong&gt;Default value:&lt;/strong&gt; &lt;code&gt;true&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This enhancement allows a LoadBalancer Service to serve different protocols under the same port (UDP, TCP). For example, serving both UDP and TCP requests for a DNS or SIP server on the same port.&lt;/p&gt;

&lt;p&gt;Read more in our "&lt;a href="https://sysdig.com/blog/whats-new-kubernetes-1-20/#1435" rel="noopener noreferrer"&gt;Kubernetes 1.20 - What's new?&lt;/a&gt;" article.&lt;/p&gt;

&lt;h3 id="2086"&gt;
&lt;a rel="noopener nofollow noreferrer" href="https://github.com/kubernetes/enhancements/issues/2086"&gt;#2086&lt;/a&gt; Service internal traffic policy&lt;/h3&gt;





&lt;p&gt;&lt;strong&gt;Stage:&lt;/strong&gt; Graduating to Stable&lt;br&gt;&lt;strong&gt;Feature group:&lt;/strong&gt; network&lt;br&gt;&lt;strong&gt;Feature gate:&lt;/strong&gt; &lt;code&gt;ServiceInternalTrafficPolicy&lt;/code&gt; &lt;strong&gt;Default value:&lt;/strong&gt; &lt;code&gt;true&lt;/code&gt;&lt;/p&gt;





&lt;p&gt;You can now set the &lt;code&gt;spec.trafficPolicy&lt;/code&gt; field on &lt;code&gt;Service&lt;/code&gt; objects to optimize your cluster traffic:&lt;/p&gt;





&lt;ul&gt;
&lt;li&gt;With &lt;code&gt;Cluster&lt;/code&gt;, the routing will behave as usual.&lt;/li&gt;



&lt;li&gt;When set to &lt;code&gt;Topology&lt;/code&gt;, it will use &lt;a href="https://sysdig.com/blog/kubernetes-1-21-whats-new/#2433" rel="noopener noreferrer"&gt;the topology-aware routing&lt;/a&gt;.&lt;/li&gt;



&lt;li&gt;With &lt;code&gt;PreferLocal&lt;/code&gt;, it will redirect traffic to services on the same node.&lt;/li&gt;



&lt;li&gt;With &lt;code&gt;Local&lt;/code&gt;, it will only send traffic to services on the same node.&lt;/li&gt;
&lt;/ul&gt;





&lt;p&gt;Read more in our "&lt;a href="https://sysdig.com/blog/kubernetes-1-21-whats-new/#2086" rel="noopener noreferrer"&gt;Kubernetes 1.21 - What's new?&lt;/a&gt;" article.&lt;/p&gt;





&lt;h3 id="3070"&gt;
&lt;a rel="noopener nofollow noreferrer" href="https://github.com/kubernetes/enhancements/issues/3070"&gt;#3070&lt;/a&gt; Reserve service IP ranges for dynamic and static IP allocation&lt;/h3&gt;





&lt;p&gt;&lt;strong&gt;Stage:&lt;/strong&gt; Graduating to Stable&lt;br&gt;&lt;strong&gt;Feature group:&lt;/strong&gt; network&lt;br&gt;&lt;strong&gt;Feature gate:&lt;/strong&gt; &lt;code&gt;ServiceIPStaticSubrange&lt;/code&gt; &lt;strong&gt;Default value:&lt;/strong&gt; &lt;code&gt;true&lt;/code&gt;&lt;/p&gt;





&lt;p&gt;This update to the &lt;code&gt;--service-cluster-ip-range&lt;/code&gt; flag will lower the risk of having IP conflicts between Services using static and dynamic IP allocation, and at the same time, keep the compatibility backwards.&lt;/p&gt;





&lt;p&gt;Read more in our "&lt;a href="https://sysdig.com/blog/kubernetes-1-24-whats-new/#3070" rel="noopener noreferrer"&gt;What's new in Kubernetes 1.24&lt;/a&gt;" article.&lt;/p&gt;





&lt;h2 id="nodes"&gt;Kubernetes 1.26 Nodes&lt;/h2&gt;





&lt;h3 id="2371"&gt;
&lt;a rel="noopener nofollow noreferrer" href="https://github.com/kubernetes/enhancements/issues/2371"&gt;#2371&lt;/a&gt; cAdvisor-less, CRI-full container and Pod stats&lt;/h3&gt;





&lt;p&gt;&lt;strong&gt;Stage:&lt;/strong&gt; Major change to Alpha&lt;br&gt;&lt;strong&gt;Feature group:&lt;/strong&gt; node&lt;br&gt;&lt;strong&gt;Feature gate:&lt;/strong&gt; &lt;code&gt;PodAndContainerStatsFromCRI &lt;strong&gt;Default value: &lt;/strong&gt;false&lt;/code&gt;&lt;/p&gt;





&lt;p&gt;This enhancement summarizes the efforts to retrieve all the stats about running containers and pods from the &lt;a rel="noopener nofollow noreferrer" href="https://kubernetes.io/blog/2016/12/container-runtime-interface-cri-in-kubernetes/"&gt;Container Runtime Interface (CRI)&lt;/a&gt;, removing the dependencies from cAdvisor.&lt;/p&gt;





&lt;p&gt;Starting with 1.26, the metrics on &lt;code&gt;/metrics/cadvisor&lt;/code&gt; are gathered by CRI instead of cAdvisor.&lt;/p&gt;





&lt;p&gt;Read more in our "&lt;a href="https://sysdig.com/blog/kubernetes-1-23-whats-new/#2371" rel="noopener noreferrer"&gt;Kubernetes 1.23 - What's new?&lt;/a&gt;" article.&lt;/p&gt;





&lt;h3 id="3063"&gt;
&lt;a rel="noopener nofollow noreferrer" href="https://github.com/kubernetes/enhancements/issues/3063"&gt;#3063&lt;/a&gt; Dynamic resource allocation&lt;/h3&gt;





&lt;p&gt;&lt;strong&gt;Stage:&lt;/strong&gt; Net new to Alpha&lt;br&gt;&lt;strong&gt;Feature group:&lt;/strong&gt; node&lt;br&gt;&lt;strong&gt;Feature gate:&lt;/strong&gt; &lt;code&gt;DynamicResourceAllocation&lt;/code&gt; &lt;strong&gt;Default value:&lt;/strong&gt; &lt;code&gt;false&lt;/code&gt;&lt;/p&gt;





&lt;p&gt;Traditionally, the Kubernetes scheduler could only take into account &lt;a href="https://sysdig.com/blog/kubernetes-limits-requests/" rel="noopener noreferrer"&gt;CPU and memory limits and requests&lt;/a&gt;. Later on, the scheduler was expanded to also take storage and other resources into account. However, this is limiting in many scenarios.&lt;/p&gt;





&lt;p&gt;For example, what if the device needs initialization and cleanup, like an FPGA; or what if you want to limit the access to the resource, like a shared GPU?&lt;/p&gt;





&lt;p&gt;This new API covers those scenarios of resource allocation and dynamic detection, using the new &lt;code&gt;ResourceClaimTemplate&lt;/code&gt; and &lt;code&gt;ResourceClass&lt;/code&gt; objects, and the new &lt;code&gt;resourceClaims&lt;/code&gt; field inside &lt;em&gt;Pods&lt;/em&gt;.&lt;/p&gt;





&lt;pre&gt;&lt;code&gt;apiVersion: v1
 kind: Pod
[...]
 spec:
   resourceClaims:
   - name: resource0
     source:
       resourceClaimTemplateName: resource-claim-template
   - name: resource1
     source:
       resourceClaimTemplateName: resource-claim-template
[...]
&lt;/code&gt;&lt;/pre&gt;





&lt;p&gt;The scheduler can keep track of these resource claims, and only schedule &lt;em&gt;Pods&lt;/em&gt; in those nodes with enough resources available.&lt;/p&gt;





&lt;h3 id="3386"&gt;
&lt;a rel="noopener nofollow noreferrer" href="https://github.com/kubernetes/enhancements/issues/3386"&gt;#3386&lt;/a&gt; Kubelet evented &lt;em&gt;PLEG&lt;/em&gt; for better performance&lt;/h3&gt;





&lt;p&gt;&lt;strong&gt;Stage:&lt;/strong&gt; Net new to Alpha&lt;br&gt;&lt;strong&gt;Feature group:&lt;/strong&gt; node&lt;br&gt;&lt;strong&gt;Feature gate:&lt;/strong&gt; &lt;code&gt;EventedPLEG&lt;/code&gt; &lt;strong&gt;Default value:&lt;/strong&gt; &lt;code&gt;false&lt;/code&gt;&lt;/p&gt;





&lt;p&gt;The aim of this enhancement is to reduce the CPU usage of the &lt;code&gt;kubelet&lt;/code&gt; when keeping track of all the pod states.&lt;/p&gt;





&lt;p&gt;It will partially reduce the periodic polling that the &lt;code&gt;kubelet&lt;/code&gt; performs, instead relying on notifications from the Container Runtime Interface (CRI) as much as possible.&lt;/p&gt;





&lt;p&gt;If you are interested in the implementation details, you may want to &lt;a rel="noopener nofollow noreferrer" href="https://github.com/kubernetes/enhancements/blob/master/keps/sig-node/3386-kubelet-evented-pleg/README.md"&gt;take a look at the KEP&lt;/a&gt;.&lt;/p&gt;





&lt;h3 id="3545"&gt;
&lt;a rel="noopener nofollow noreferrer" href="https://github.com/kubernetes/enhancements/issues/3545"&gt;#3545&lt;/a&gt; Improved &lt;em&gt;multi-NUMA&lt;/em&gt; alignment in topology manager&lt;/h3&gt;





&lt;p&gt;&lt;strong&gt;Stage:&lt;/strong&gt; Net new to Alpha&lt;br&gt;&lt;strong&gt;Feature group:&lt;/strong&gt; node&lt;br&gt;&lt;strong&gt;Feature gate:&lt;/strong&gt; &lt;code&gt;TopologyManagerPolicyOptions&lt;/code&gt; &lt;strong&gt;Default value:&lt;/strong&gt; &lt;code&gt;false&lt;br&gt;&lt;strong&gt;Feature gate:&lt;/strong&gt;&lt;/code&gt; &lt;code&gt;TopologyManagerPolicyBetaOptions&lt;/code&gt; &lt;strong&gt;Default value:&lt;/strong&gt; &lt;code&gt;false&lt;/code&gt;&lt;br&gt;&lt;strong&gt;Feature gate:&lt;/strong&gt; &lt;code&gt;TopologyManagerPolicyAlphaOptions&lt;/code&gt; &lt;strong&gt;Default value:&lt;/strong&gt; &lt;code&gt;false&lt;/code&gt;&lt;/p&gt;





&lt;p&gt;This is an improvement for &lt;em&gt;TopologyManager&lt;/em&gt; to better handle Non-Uniform Memory Access (&lt;a rel="noopener nofollow noreferrer" href="https://en.wikipedia.org/wiki/Non-uniform_memory_access"&gt;NUMA&lt;/a&gt;) nodes. For some high-performance workloads, it is very important to control in which physical CPU cores they run. You can significantly improve performance if you avoid memory jumping between the caches of the same chip, or between sockets.&lt;/p&gt;





&lt;p&gt;A new &lt;code&gt;topology-manager-policy-options&lt;/code&gt; flag for &lt;code&gt;kubelet&lt;/code&gt; will allow you to pass options and modify the behavior of a topology manager.&lt;/p&gt;





&lt;p&gt;Currently, only one alpha option is available:&lt;/p&gt;





&lt;ul&gt;
&lt;li&gt;When &lt;code&gt;prefer-closest-numa-nodes=true&lt;/code&gt; is passed along, the Topology Manager will align the resources on either a single NUMA node or the minimum number of NUMA nodes possible.&lt;/li&gt;
&lt;/ul&gt;





&lt;p&gt;As new options may be added in the future, several feature gates have been added so you can choose to focus only on the stable ones:&lt;/p&gt;





&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;TopologyManagerPolicyOptions&lt;/code&gt;: Will enable the &lt;code&gt;topology-manager-policy-options&lt;/code&gt; flag and the stable options.&lt;/li&gt;



&lt;li&gt;
&lt;code&gt;TopologyManagerPolicyBetaOptions&lt;/code&gt;: Will also enable the beta options.&lt;/li&gt;



&lt;li&gt;
&lt;code&gt;TopologyManagerPolicyAlphaOptions&lt;/code&gt;: Will also enable the alpha options.&lt;/li&gt;
&lt;/ul&gt;





&lt;p&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href="https://sysdig.com/blog/kubernetes-1-23-whats-new/#2902" rel="noopener noreferrer"&gt;#2902 CPUManager policy option to distribute CPUs across NUMA nodes in Kubernetes 1.23&lt;/a&gt;.&lt;br&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href="https://sysdig.com/blog/kubernetes-1-22-whats-new/#2625" rel="noopener noreferrer"&gt;#2625 New CPU Manager Policies in Kubernetes 1.22&lt;/a&gt;.&lt;/p&gt;





&lt;h3 id="2133"&gt;
&lt;a rel="noopener nofollow noreferrer" href="https://github.com/kubernetes/enhancements/issues/2133"&gt;#2133&lt;/a&gt; Kubelet credential provider&lt;/h3&gt;





&lt;p&gt;&lt;strong&gt;Stage:&lt;/strong&gt; Graduating to Stable&lt;br&gt;&lt;strong&gt;Feature group:&lt;/strong&gt; node&lt;br&gt;&lt;strong&gt;Feature gate:&lt;/strong&gt; &lt;code&gt;KubeletCredentialProviders&lt;/code&gt; &lt;strong&gt;Default value:&lt;/strong&gt; &lt;code&gt;true&lt;/code&gt;&lt;/p&gt;





&lt;p&gt;This enhancement replaces in-tree container image registry credential providers with a new mechanism that is external and pluggable.&lt;/p&gt;





&lt;p&gt;Read more in our "&lt;a href="https://sysdig.com/blog/whats-new-kubernetes-1-20/#2133" rel="noopener noreferrer"&gt;Kubernetes 1.20 - What's new?&lt;/a&gt;" article.&lt;/p&gt;





&lt;h3 id="3570"&gt;
&lt;a rel="noopener nofollow noreferrer" href="https://github.com/kubernetes/enhancements/issues/3570"&gt;#3570&lt;/a&gt; Graduate to &lt;em&gt;CPUManager&lt;/em&gt; to GA&lt;/h3&gt;





&lt;p&gt;&lt;strong&gt;Stage:&lt;/strong&gt; Graduating to Stable&lt;br&gt;&lt;strong&gt;Feature group:&lt;/strong&gt; node&lt;br&gt;&lt;strong&gt;Feature gate:&lt;/strong&gt; &lt;code&gt;CPUManager&lt;/code&gt; &lt;strong&gt;Default value:&lt;/strong&gt; &lt;code&gt;true&lt;/code&gt;&lt;/p&gt;





&lt;p&gt;The CPUManager is the Kubelet component responsible for assigning pod containers to sets of CPUs on the local node.&lt;/p&gt;





&lt;p&gt;It was introduced in Kubernetes 1.8, and graduated to beta in release 1.10. For 1.26, the core CPUManager has been deemed stable, while experimentation continues with the additional work on its policies.&lt;/p&gt;





&lt;p&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href="http://sysdig.com/blog/kubernetes-1-26-whats-new/#3545" rel="noopener noreferrer"&gt;#3545 Improved multi-numa alignment in Topology Manager in Kubernetes 1.26&lt;/a&gt;.&lt;br&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href="https://sysdig.com/blog/kubernetes-1-22-whats-new/#2625" rel="noopener noreferrer"&gt;#2625 New CPU Manager Policies in Kubernetes 1.22&lt;/a&gt;.&lt;/p&gt;





&lt;h3 id="3573"&gt;
&lt;a rel="noopener nofollow noreferrer" href="https://github.com/kubernetes/enhancements/issues/3573"&gt;#3573&lt;/a&gt; Graduate &lt;em&gt;DeviceManager&lt;/em&gt; to GA&lt;/h3&gt;





&lt;p&gt;&lt;strong&gt;Stage:&lt;/strong&gt; Graduating to Stable&lt;br&gt;&lt;strong&gt;Feature group:&lt;/strong&gt; node&lt;br&gt;&lt;strong&gt;Feature gate:&lt;/strong&gt; &lt;code&gt;DevicePlugins&lt;/code&gt; &lt;strong&gt;Default value:&lt;/strong&gt; &lt;code&gt;true&lt;/code&gt;&lt;/p&gt;





&lt;p&gt;The DeviceManager in the Kubelet is the component managing the interactions with the different Device Plugins.&lt;/p&gt;





&lt;p&gt;Initially introduced in Kubernetes 1.8 and moved to beta stage in release 1.10, the Device Plugin framework saw widespread adoption and is finally moving to GA in 1.26.&lt;/p&gt;





&lt;p&gt;This framework allows the use of external devices (e.g., &lt;a rel="noopener nofollow noreferrer" href="https://github.com/NVIDIA/k8s-device-plugin"&gt;NVIDIA GPUs&lt;/a&gt;, &lt;a rel="noopener nofollow noreferrer" href="https://github.com/RadeonOpenCompute/k8s-device-plugin"&gt;AMD GPUS&lt;/a&gt;, &lt;a rel="noopener nofollow noreferrer" href="https://github.com/k8snetworkplumbingwg/sriov-network-device-plugin"&gt;SR-IOV NICs&lt;/a&gt;) without modifying core Kubernetes components.&lt;/p&gt;





&lt;h2 id="scheduling"&gt;Scheduling in Kubernetes 1.26&lt;/h2&gt;





&lt;h3 id="3521"&gt;
&lt;a rel="noopener nofollow noreferrer" href="https://github.com/kubernetes/enhancements/issues/3521"&gt;#3521&lt;/a&gt; &lt;em&gt;Pod&lt;/em&gt; scheduling readiness&lt;/h3&gt;





&lt;p&gt;&lt;strong&gt;Stage:&lt;/strong&gt; Net new to Alpha&lt;br&gt;&lt;strong&gt;Feature group:&lt;/strong&gt; scheduling&lt;code&gt;&lt;br&gt;&lt;strong&gt;Feature gate:&lt;/strong&gt;&lt;/code&gt; &lt;code&gt;PodSchedulingReadiness&lt;/code&gt; &lt;strong&gt;Default value:&lt;/strong&gt; &lt;code&gt;false&lt;/code&gt;&lt;/p&gt;





&lt;p&gt;This enhancement aims to optimize scheduling by letting the Pods define when they are ready to be actually scheduled.&lt;/p&gt;





&lt;p&gt;Not all &lt;a href="https://sysdig.com/blog/kubernetes-pod-pending-problems/" rel="noopener noreferrer"&gt;pending Pods&lt;/a&gt; are ready to be scheduled. Some stay in a &lt;code&gt;miss-essential-resources&lt;/code&gt; state for some time, which causes extra work in the scheduler.&lt;/p&gt;





&lt;p&gt;The new &lt;code&gt;.spec.schedulingGates&lt;/code&gt; of a Pod allows to identify when they are ready for scheduling:&lt;/p&gt;





&lt;pre&gt;&lt;code&gt;apiVersion: v1
 kind: Pod
[...]
 spec:
   schedulingGates:
   - name: foo
   - name: bar
[...]
&lt;/code&gt;&lt;/pre&gt;





&lt;p&gt;When any scheduling gate is present, the Pod won't be scheduled.&lt;/p&gt;





&lt;p&gt;You can check the status with:&lt;/p&gt;





&lt;pre&gt;&lt;code&gt;$ kubectl get pod test-pod
 NAME       READY   STATUS            RESTARTS   AGE
 test-pod   0/1     SchedulingGated   0          7s
&lt;/code&gt;&lt;/pre&gt;





&lt;h3 id="3094"&gt;
&lt;a rel="noopener nofollow noreferrer" href="https://github.com/kubernetes/enhancements/issues/3094"&gt;#3094&lt;/a&gt; Take taints/tolerations into consideration when calculating &lt;em&gt;PodTopologySpread&lt;/em&gt; skew&lt;/h3&gt;





&lt;p&gt;&lt;strong&gt;Stage:&lt;/strong&gt; Graduating to Beta&lt;br&gt;&lt;strong&gt;Feature group:&lt;/strong&gt; scheduling&lt;br&gt;&lt;strong&gt;Feature gate:&lt;/strong&gt; &lt;code&gt;NodeInclusionPolicyInPodTopologySpread&lt;/code&gt; &lt;strong&gt;Default value:&lt;/strong&gt; &lt;code&gt;true&lt;/code&gt;&lt;/p&gt;





&lt;p&gt;As we discussed in our "&lt;a href="https://sysdig.com/blog/whats-new-kubernetes-1-16/#895" rel="noopener noreferrer"&gt;Kubernetes 1.16 - What's new?&lt;/a&gt;" article, the &lt;code&gt;topologySpreadConstraints&lt;/code&gt; fields, along with &lt;code&gt;maxSkew&lt;/code&gt;, allow you to spread your workloads across nodes. A new &lt;code&gt;NodeInclusionPolicies&lt;/code&gt; field allows taking into account &lt;code&gt;NodeAffinity&lt;/code&gt; and &lt;code&gt;NodeTaint&lt;/code&gt; when calculating this pod topology spread skew.&lt;/p&gt;





&lt;p&gt;Read more in our "&lt;a href="https://sysdig.com/blog/kubernetes-1-25-whats-new/#3094" rel="noopener noreferrer"&gt;What's new in Kubernetes 1.25&lt;/a&gt;" article.&lt;/p&gt;





&lt;h2 id="storage"&gt;Kubernetes 1.26 storage&lt;/h2&gt;





&lt;h3 id="3294"&gt;
&lt;a rel="noopener nofollow noreferrer" href="https://github.com/kubernetes/enhancements/issues/3294"&gt;#3294&lt;/a&gt; Provision volumes from cross-namespace snapshots&lt;/h3&gt;





&lt;p&gt;&lt;strong&gt;Stage:&lt;/strong&gt; Net new to Alpha&lt;br&gt;&lt;strong&gt;Feature group:&lt;/strong&gt; storage&lt;br&gt;&lt;strong&gt;Feature gate:&lt;/strong&gt; &lt;code&gt;CrossNamespaceVolumeDataSource&lt;/code&gt; &lt;strong&gt;Default value:&lt;/strong&gt; &lt;code&gt;false&lt;/code&gt;&lt;/p&gt;





&lt;p&gt;Prior to Kubernetes 1.26, users were able to provision volumes from snapshots thanks to the &lt;code&gt;VolumeSnapshot&lt;/code&gt; feature. While this is a great and super useful feature. it had some limitations, like the inability to bind a &lt;code&gt;PersistentVolumeClaim&lt;/code&gt; to &lt;code&gt;VolumeSnapshots&lt;/code&gt; from other namespaces.&lt;/p&gt;





&lt;p&gt;This enhancement breaks this limitation and allows Kubernetes users to provision volumes from snapshots across namespaces.&lt;/p&gt;





&lt;p&gt;If you want to use the cross-namespace VolumeSnapshot feature, you’ll have to first create a &lt;code&gt;ReferenceGrant&lt;/code&gt; object, and then a &lt;code&gt;PersistentVolumeClaim&lt;/code&gt; binding to the &lt;code&gt;VolumeSnapshot&lt;/code&gt;. Here, you’ll find a simple example of both objects for learning purposes.&lt;/p&gt;





&lt;pre&gt;&lt;code&gt;---
apiVersion: gateway.networking.k8s.io/v1alpha2
kind: ReferenceGrant
metadata:
  name: test
  namespace: default
spec:
  from:
  - group: ""
    kind: PersistentVolumeClaim
    namespace: nstest1
  to:
  - group: snapshot.storage.k8s.io
    kind: VolumeSnapshot
    name: testsnapshot
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: testvolumeclaim
  namespace: nstest1
spec:
  storageClassName: mystorageclass
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 2Gi
  dataSourceRef2:
    apiGroup: snapshot.storage.k8s.io
    kind: VolumeSnapshot
    name: testsnapshot
    namespace: default
  volumeMode: Filesystem
&lt;/code&gt;&lt;/pre&gt;





&lt;h3 id="2268"&gt;
&lt;a rel="noopener nofollow noreferrer" href="https://github.com/kubernetes/enhancements/issues/2268"&gt;#2268&lt;/a&gt; Non-graceful node shutdown&lt;/h3&gt;





&lt;p&gt;&lt;strong&gt;Stage:&lt;/strong&gt; Graduating to Beta&lt;br&gt;&lt;strong&gt;Feature group:&lt;/strong&gt; storage&lt;br&gt;&lt;strong&gt;Feature gate:&lt;/strong&gt; &lt;code&gt;NodeOutOfServiceVolumeDetach&lt;/code&gt; &lt;strong&gt;Default value:&lt;/strong&gt; &lt;code&gt;true&lt;/code&gt;&lt;/p&gt;





&lt;p&gt;This enhancement addresses node shutdown cases that are not detected properly, where the pods that are part of a &lt;em&gt;StatefulSet&lt;/em&gt; will be stuck in terminating status on the shutdown node and cannot be moved to a new running node.&lt;/p&gt;





&lt;p&gt;The pods will be forcefully deleted in this case, trigger the deletion of the &lt;em&gt;VolumeAttachments&lt;/em&gt;, and new pods will be created on a different running node so that application can continue to function.&lt;/p&gt;





&lt;p&gt;Read more in our "&lt;a href="https://sysdig.com/blog/kubernetes-1-24-whats-new/#2268" rel="noopener noreferrer"&gt;Kubernetes 1.24 - What's new?&lt;/a&gt;" article.&lt;/p&gt;





&lt;h3 id="3333"&gt;
&lt;a rel="noopener nofollow noreferrer" href="https://github.com/kubernetes/enhancements/issues/3333"&gt;#3333&lt;/a&gt; Retroactive default &lt;em&gt;StorageClass&lt;/em&gt; &lt;em&gt;assignement&lt;/em&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Stage:&lt;/strong&gt; Graduating to Beta&lt;br&gt;&lt;strong&gt;Feature group:&lt;/strong&gt; storage&lt;br&gt;&lt;strong&gt;Feature gate:&lt;/strong&gt; &lt;code&gt;RetroactiveDefaultStorageClass&lt;/code&gt; &lt;strong&gt;Default value:&lt;/strong&gt; &lt;code&gt;false&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This enhancement helps manage the case when cluster administrators change the default storage class. All &lt;em&gt;PVCs&lt;/em&gt; without &lt;em&gt;StorageClass&lt;/em&gt; that were created while the change took place will retroactively be set to the new default &lt;em&gt;StorageClass&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Read more in our "&lt;a href="https://sysdig.com/blog/kubernetes-1-25-whats-new/#3333" rel="noopener noreferrer"&gt;What's new in Kubernetes 1.25&lt;/a&gt;" article.&lt;/p&gt;

&lt;h3 id="1491"&gt;
&lt;a rel="noopener nofollow noreferrer" href="https://github.com/kubernetes/enhancements/issues/1491"&gt;#1491&lt;/a&gt; vSphere &lt;em&gt;in-tree&lt;/em&gt; to CSI driver migration&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Stage:&lt;/strong&gt; Graduating to Stable&lt;br&gt;&lt;strong&gt;Feature group:&lt;/strong&gt; storage&lt;br&gt;&lt;strong&gt;Feature gate:&lt;/strong&gt; &lt;code&gt;CSIMigrationvSphere&lt;/code&gt; &lt;strong&gt;Default value:&lt;/strong&gt; &lt;code&gt;false&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;As we covered in our "&lt;a href="https://sysdig.com/blog/kubernetes-1-23-whats-new/#1487" rel="noopener noreferrer"&gt;What's new in Kubernetes 1.19&lt;/a&gt;" article, the CSI driver for vSphere has been stable for some time. Now, all plugin operations for &lt;code&gt;vspherevolume&lt;/code&gt; are now redirected to &lt;a rel="noopener nofollow noreferrer" href="https://github.com/kubernetes-sigs/vsphere-csi-driver"&gt;the out-of-tree 'csi.vsphere.vmware.com' driver&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;This enhancement is part of the &lt;a href="https://sysdig.com/blog/kubernetes-1-25-whats-new/#625" rel="noopener noreferrer"&gt;#625 In-tree storage plugin to CSI Driver Migration&lt;/a&gt; effort.&lt;/p&gt;

&lt;h3 id="1885"&gt;
&lt;a rel="noopener nofollow noreferrer" href="https://github.com/kubernetes/enhancements/issues/1885"&gt;#1885&lt;/a&gt; Azure file &lt;em&gt;in-tree&lt;/em&gt; to CSI driver migration&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Stage:&lt;/strong&gt; Graduating to Stable&lt;br&gt;&lt;strong&gt;Feature group:&lt;/strong&gt; storage&lt;br&gt;&lt;strong&gt;Feature gate:&lt;/strong&gt; &lt;code&gt;InTreePluginAzureDiskUnregister&lt;/code&gt; &lt;strong&gt;Default value:&lt;/strong&gt; &lt;code&gt;true&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This enhancement summarizes &lt;a rel="noopener nofollow noreferrer" href="https://kubernetes.io/docs/concepts/storage/volumes/#azurefile"&gt;the work to move Azure File code&lt;/a&gt; out of the main Kubernetes binaries (out-of-tree).&lt;/p&gt;

&lt;p&gt;Read more in our "&lt;a href="https://sysdig.com/blog/kubernetes-1-21-whats-new/#1885" rel="noopener noreferrer"&gt;Kubernetes 1.21 - What's new?&lt;/a&gt;" article.&lt;/p&gt;

&lt;h3 id="2317"&gt;
&lt;a rel="noopener nofollow noreferrer" href="https://github.com/kubernetes/enhancements/issues/2317"&gt;#2317&lt;/a&gt; Allow Kubernetes to supply pod's &lt;em&gt;fsgroup&lt;/em&gt; to CSI driver on mount&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Stage:&lt;/strong&gt; Graduating to Stable&lt;br&gt;&lt;strong&gt;Feature group:&lt;/strong&gt; storage&lt;br&gt;&lt;strong&gt;Feature gate:&lt;/strong&gt; &lt;code&gt;DelegateFSGroupToCSIDriver &lt;strong&gt;Default value: &lt;/strong&gt;false&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This enhancement proposes providing the CSI driver with the &lt;em&gt;fsgroup&lt;/em&gt; of the pods as an explicit field, so the CSI driver can be the one applying this natively on mount time.&lt;/p&gt;

&lt;p&gt;Read more in our "&lt;a href="https://sysdig.com/blog/kubernetes-1-22-whats-new/#2317" rel="noopener noreferrer"&gt;Kubernetes 1.22 - What's new?&lt;/a&gt;" article.&lt;/p&gt;

&lt;h2 id="other"&gt;Other enhancements in Kubernetes 1.26&lt;/h2&gt;

&lt;h3 id="3466"&gt;
&lt;a rel="noopener nofollow noreferrer" href="https://github.com/kubernetes/enhancements/issues/3466"&gt;#3466&lt;/a&gt; Kubernetes component health SLIs&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Stage:&lt;/strong&gt; Net new to Alpha&lt;br&gt;&lt;strong&gt;Feature group:&lt;/strong&gt; instrumentation&lt;br&gt;&lt;strong&gt;Feature gate:&lt;/strong&gt; &lt;code&gt;ComponentSLIs&lt;/code&gt; &lt;strong&gt;Default value:&lt;/strong&gt; &lt;code&gt;false&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;There isn't a standard format to query the health data of Kubernetes components.&lt;/p&gt;

&lt;p&gt;Starting with Kubernetes 1.26, a new endpoint &lt;code&gt;/metrics/slis&lt;/code&gt; will be available on each component exposing their Service Level Indicator (SLI) metrics in Prometheus format.&lt;/p&gt;

&lt;p&gt;For each component, two metrics will be exposed:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A &lt;strong&gt;gauge&lt;/strong&gt;, representing the current state of the healthcheck.&lt;/li&gt;



&lt;li&gt;A &lt;strong&gt;counter&lt;/strong&gt;, recording the cumulative counts observed for each healthcheck state.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;With this information, you can check the overtime status for the Kubernetes internals, e.g.:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;kubernetes_healthcheck{name="etcd",type="readyz"}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And create an alert for when something's wrong, e.g.:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;kubernetes_healthchecks_total{name="etcd",status="error",type="readyz"} &amp;gt; 0&lt;/code&gt;&lt;/pre&gt;

&lt;h3 id="3498"&gt;
&lt;a rel="noopener nofollow noreferrer" href="https://github.com/kubernetes/enhancements/issues/3498"&gt;#3498&lt;/a&gt; Extend metrics stability&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Stage:&lt;/strong&gt; Net new to Alpha&lt;br&gt;&lt;strong&gt;Feature group:&lt;/strong&gt; instrumentation&lt;br&gt;&lt;strong&gt;Feature gate:&lt;/strong&gt; N/A&lt;/p&gt;

&lt;p&gt;Metrics in Kubernetes are classified as &lt;code&gt;alpha&lt;/code&gt; or &lt;code&gt;stable&lt;/code&gt;. The &lt;code&gt;stable&lt;/code&gt; ones are guaranteed to be maintained, providing you with the information to prepare your dashboards so they don't break unexpectedly when you upgrade your cluster.&lt;/p&gt;

&lt;p&gt;In Kubernetes 1.26, two new classes are added:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;beta&lt;/code&gt;: For metrics related to beta features. They may change or disappear, but they are in a more advanced development state than the alpha ones.&lt;/li&gt;



&lt;li&gt;
&lt;code&gt;internal&lt;/code&gt;: Metrics for internal usage that you shouldn't worry about, either because they don't provide useful information for cluster administrators, or because they may change without notice.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can check a full &lt;a rel="noopener nofollow noreferrer" href="https://kubernetes.io/docs/reference/instrumentation/metrics/"&gt;list of available metrics in the documentation&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href="https://sysdig.com/blog/kubernetes-1-21-whats-new/#1209" rel="noopener noreferrer"&gt;#1209 Metrics stability enhancement in Kubernetes 1.21&lt;/a&gt;.&lt;/p&gt;

&lt;h3 id="3515"&gt;
&lt;a rel="noopener nofollow noreferrer" href="https://github.com/kubernetes/enhancements/issues/3515"&gt;#3515&lt;/a&gt; OpenAPI v3 for &lt;em&gt;kubectl&lt;/em&gt; explain&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Stage:&lt;/strong&gt; Net new to Alpha&lt;br&gt;&lt;strong&gt;Feature group:&lt;/strong&gt; cli&lt;br&gt;&lt;strong&gt;Environment variable:&lt;/strong&gt; &lt;code&gt;KUBECTL_EXPLAIN_OPENAPIV3&lt;/code&gt; &lt;strong&gt;Default value:&lt;/strong&gt; &lt;code&gt;false&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This enhancement allows &lt;code&gt;kubectl explain&lt;/code&gt; to gather the data from OpenAPIv3 instead of v2.&lt;/p&gt;

&lt;p&gt;In OpenAPIv3, some data can be represented in a better way, like &lt;em&gt;CustomResourceDefinition&lt;/em&gt;s (CDRs).&lt;/p&gt;

&lt;p&gt;Internal work is also being made to improve how &lt;code&gt;kubectl explain&lt;/code&gt; prints the output.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href="https://sysdig.com/blog/kubernetes-1-24-whats-new/#2896" rel="noopener noreferrer"&gt;#2896 OpenAPI v3 in Kubernetes 1.24&lt;/a&gt;.&lt;/p&gt;

&lt;h3 id="1440"&gt;
&lt;a rel="noopener nofollow noreferrer" href="https://github.com/kubernetes/enhancements/issues/1440"&gt;#1440&lt;/a&gt; &lt;em&gt;kubectl&lt;/em&gt; events&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Stage:&lt;/strong&gt; Graduating to Beta&lt;br&gt;&lt;strong&gt;Feature group:&lt;/strong&gt; cli&lt;br&gt;&lt;strong&gt;Feature gate:&lt;/strong&gt; N/A&lt;/p&gt;

&lt;p&gt;A new &lt;code&gt;kubectl events&lt;/code&gt; command is available that will enhance the current functionality of &lt;code&gt;kubectl get events&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Read more in our "&lt;a href="https://sysdig.com/blog/kubernetes-1-23-whats-new/#1440" rel="noopener noreferrer"&gt;Kubernetes 1.23 - What's new?&lt;/a&gt;" article.&lt;/p&gt;

&lt;h3 id="3031"&gt;
&lt;a rel="noopener nofollow noreferrer" href="https://github.com/kubernetes/enhancements/issues/3031"&gt;#3031&lt;/a&gt; Signing release artifacts&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Stage:&lt;/strong&gt; Graduating to Beta&lt;br&gt;&lt;strong&gt;Feature group:&lt;/strong&gt; release&lt;br&gt;&lt;strong&gt;Feature gate:&lt;/strong&gt; N/A&lt;/p&gt;

&lt;p&gt;This enhancement introduces a unified way to sign artifacts in order to help avoid &lt;a href="https://sysdig.com/blog/software-supply-chain-security/" rel="noopener noreferrer"&gt;supply chain attacks&lt;/a&gt;. It relies on the &lt;a rel="noopener nofollow noreferrer" href="https://www.sigstore.dev/"&gt;sigstore&lt;/a&gt; project tools, and more specifically &lt;code&gt;&lt;a rel="noopener nofollow noreferrer" href="https://github.com/sigstore/cosign"&gt;cosign&lt;/a&gt;&lt;/code&gt;. Although it doesn’t add new functionality, it will surely help to keep our cluster more protected.&lt;/p&gt;

&lt;p&gt;Read more in our "&lt;a href="https://sysdig.com/blog/kubernetes-1-24-whats-new/#3031" rel="noopener noreferrer"&gt;Kubernetes 1.24 - What's new?&lt;/a&gt;" article.&lt;/p&gt;

&lt;h3 id="3503"&gt;
&lt;a rel="noopener nofollow noreferrer" href="https://github.com/kubernetes/enhancements/issues/3503"&gt;#3503&lt;/a&gt; Host network support for Windows pods&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Stage:&lt;/strong&gt; Net new to Alpha&lt;br&gt;&lt;strong&gt;Feature group:&lt;/strong&gt; windows&lt;br&gt;&lt;strong&gt;Feature gate:&lt;/strong&gt; &lt;code&gt;WindowsHostNetwork&lt;/code&gt; &lt;strong&gt;Default value:&lt;/strong&gt; &lt;code&gt;false&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;There is a weird situation in Windows pods where you can set &lt;code&gt;hostNetwork=true&lt;/code&gt; for them, but it doesn't change anything. There isn't any platform impediment, the implementation was just missing.&lt;/p&gt;

&lt;p&gt;Starting with Kubernetes 1.26, the &lt;code&gt;kubelet&lt;/code&gt; can now request that Windows pods use the host's network namespace instead of creating a new pod network namespace.&lt;/p&gt;

&lt;p&gt;This will come handy to avoid port exhaustion where there's large amounts of services.&lt;/p&gt;

&lt;h3 id="1981"&gt;
&lt;a rel="noopener nofollow noreferrer" href="https://github.com/kubernetes/enhancements/issues/1981"&gt;#1981&lt;/a&gt; Support for Windows privileged containers&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Stage:&lt;/strong&gt; Graduating to Stable&lt;br&gt;&lt;strong&gt;Feature group:&lt;/strong&gt; windows&lt;br&gt;&lt;strong&gt;Feature gate:&lt;/strong&gt; &lt;code&gt;WindowsHostProcessContainers &lt;strong&gt;Default value: &lt;/strong&gt;true&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This enhancement brings the &lt;a rel="noopener nofollow noreferrer" href="https://kubernetes.io/docs/concepts/workloads/pods/#privileged-mode-for-containers"&gt;privileged containers&lt;/a&gt; feature available in Linux to Windows hosts.&lt;/p&gt;

&lt;p&gt;Privileged containers have access to the host, as if they were running directly on it. Although they are not recommended for most of the workloads, they are quite useful for administration, security, and monitoring purposes.&lt;/p&gt;

&lt;p&gt;Read more in our "&lt;a href="https://sysdig.com/blog/kubernetes-1-22-whats-new/#1981" rel="noopener noreferrer"&gt;Kubernetes 1.22 - What's new?&lt;/a&gt;" article.&lt;/p&gt;








&lt;p&gt;That’s all for Kubernetes 1.26, folks! Exciting as always; get ready to upgrade your clusters if you are intending to use any of these features.&lt;/p&gt;

&lt;p&gt;If you liked this, you might want to check out our previous ‘What’s new in Kubernetes’ editions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://sysdig.com/blog/kubernetes-1-26-whats-new/" rel="noopener noreferrer"&gt;Kubernetes 1.26 - What's new?&lt;/a&gt;&lt;/li&gt;



&lt;li&gt;&lt;a href="https://sysdig.com/blog/kubernetes-1-25-whats-new/" rel="noopener noreferrer"&gt;Kubernetes 1.25 - What's new?&lt;/a&gt;&lt;/li&gt;



&lt;li&gt;&lt;a href="https://sysdig.com/blog/kubernetes-1-24-whats-new/" rel="noopener noreferrer"&gt;Kubernetes 1.24 - What's new?&lt;/a&gt;&lt;/li&gt;



&lt;li&gt;&lt;a href="https://sysdig.com/blog/kubernetes-1-23-whats-new/" rel="noopener noreferrer"&gt;Kubernetes 1.23 - What's new?&lt;/a&gt;&lt;/li&gt;



&lt;li&gt;&lt;a href="https://sysdig.com/blog/kubernetes-1-22-whats-new/" rel="noopener noreferrer"&gt;Kubernetes 1.22 - What's new?&lt;/a&gt;&lt;/li&gt;



&lt;li&gt;&lt;a href="https://sysdig.com/blog/kubernetes-1-21-whats-new/" rel="noopener noreferrer"&gt;Kubernetes 1.21 - What's new?&lt;/a&gt;&lt;/li&gt;



&lt;li&gt;&lt;a href="https://sysdig.com/blog/whats-new-kubernetes-1-20/" rel="noopener noreferrer"&gt;Kubernetes 1.20 - What's new?&lt;/a&gt;&lt;/li&gt;



&lt;li&gt;&lt;a href="https://sysdig.com/blog/whats-new-kubernetes-1-19/" rel="noopener noreferrer"&gt;Kubernetes 1.19 - What's new?&lt;/a&gt;&lt;/li&gt;



&lt;li&gt;&lt;a href="https://sysdig.com/blog/whats-new-kubernetes-1-18/" rel="noopener noreferrer"&gt;Kubernetes 1.18 - What's new?&lt;/a&gt;&lt;/li&gt;



&lt;li&gt;&lt;a href="https://sysdig.com/blog/whats-new-kubernetes-1-17/" rel="noopener noreferrer"&gt;Kubernetes 1.17 - What's new?&lt;/a&gt;&lt;/li&gt;



&lt;li&gt;&lt;a href="https://sysdig.com/blog/whats-new-kubernetes-1-16/" rel="noopener noreferrer"&gt;Kubernetes 1.16 - What's new?&lt;/a&gt;&lt;/li&gt;



&lt;li&gt;&lt;a href="https://sysdig.com/blog/whats-new-kubernetes-1-15/" rel="noopener noreferrer"&gt;Kubernetes 1.15 - What's new?&lt;/a&gt;&lt;/li&gt;



&lt;li&gt;&lt;a href="https://sysdig.com/blog/whats-new-kubernetes-1-14/" rel="noopener noreferrer"&gt;Kubernetes 1.14 - What's new?&lt;/a&gt;&lt;/li&gt;



&lt;li&gt;&lt;a href="https://sysdig.com/blog/whats-new-in-kubernetes-1-13" rel="noopener noreferrer"&gt;Kubernetes 1.13 - What's new?&lt;/a&gt;&lt;/li&gt;



&lt;li&gt;&lt;a href="https://sysdig.com/blog/whats-new-in-kubernetes-1-12" rel="noopener noreferrer"&gt;Kubernetes 1.12 - What's new?&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Get involved in the Kubernetes community:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Visit &lt;a rel="noopener nofollow noreferrer" href="https://kubernetes.io"&gt;the project homepage&lt;/a&gt;.&lt;/li&gt;



&lt;li&gt;Check out &lt;a rel="noopener nofollow noreferrer" href="https://github.com/kubernetes/"&gt;the Kubernetes project on GitHub&lt;/a&gt;.&lt;/li&gt;



&lt;li&gt;Get involved &lt;a rel="noopener nofollow noreferrer" href="https://kubernetes.io/community/"&gt;with the Kubernetes community&lt;/a&gt;.&lt;/li&gt;



&lt;li&gt;Meet the maintainers &lt;a rel="noopener nofollow noreferrer" href="https://slack.k8s.io"&gt;on the Kubernetes Slack&lt;/a&gt;.&lt;/li&gt;



&lt;li&gt;Follow &lt;a rel="noopener nofollow noreferrer" href="https://twitter.com/kubernetesio"&gt;@KubernetesIO on Twitter&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And if you enjoy keeping up to date with the Kubernetes ecosystem, &lt;a href="https://go.sysdig.com/container-newsletter-signup.html" rel="noopener noreferrer"&gt;subscribe to our container newsletter&lt;/a&gt;, a monthly email with the coolest stuff happening in the cloud-native ecosystem.&lt;/p&gt;

</description>
      <category>kubernetes</category>
      <category>devops</category>
      <category>docker</category>
    </item>
    <item>
      <title>Understanding Kubernetes Limits and Requests</title>
      <dc:creator>Javier Martínez</dc:creator>
      <pubDate>Mon, 21 Nov 2022 08:43:18 +0000</pubDate>
      <link>https://dev.to/sysdig/understanding-kubernetes-limits-and-requests-5m1</link>
      <guid>https://dev.to/sysdig/understanding-kubernetes-limits-and-requests-5m1</guid>
      <description>&lt;p&gt;When working with containers in Kubernetes, it’s important to know what are the resources involved and how they are needed. Some processes will require more CPU or memory than others. Some are critical and should never be starved. &lt;/p&gt;

&lt;p&gt;Knowing that, we should configure our containers and Pods properly in order to get the best of both.&lt;/p&gt;

&lt;p&gt;In this article, we will see:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Introduction to Kubernetes Limits and Requests&lt;/li&gt;



&lt;li&gt;Hands-on example&lt;/li&gt;



&lt;li&gt;Kubernetes Requests&lt;/li&gt;



&lt;li&gt;Kubernetes Limits&lt;/li&gt;



&lt;li&gt;CPU particularities&lt;/li&gt;



&lt;li&gt;Memory particularities&lt;/li&gt;



&lt;li&gt;Namespace ResourceQuota&lt;/li&gt;



&lt;li&gt;Namespace LimitRange&lt;/li&gt;



&lt;li&gt;Conclusion&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id="introduction"&gt;Introduction to Kubernetes Limits and Requests&lt;/h2&gt;

&lt;p&gt;Limits and Requests are important settings when working with Kubernetes. This article will focus on the two most important ones: CPU and memory.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Kubernetes defines Limits as the&lt;/strong&gt; &lt;strong&gt;maximum amount of a resource&lt;/strong&gt; to be used by a container. This means that the container can never consume more than the memory amount or CPU amount indicated. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Requests, on the other hand, are the minimum guaranteed amount of a resource&lt;/strong&gt; that is reserved for a container.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsysdig.com%2Fwp-content%2Fuploads%2FKubernetes-Limits-and-Request-04-1-1170x585.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsysdig.com%2Fwp-content%2Fuploads%2FKubernetes-Limits-and-Request-04-1-1170x585.png" alt="" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2 id="handson"&gt;Hands-on example&lt;/h2&gt;

&lt;p&gt;Let’s have a look at this deployment, where we are setting up limits and requests for two different containers on both CPU and memory.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;kind: Deployment
apiVersion: extensions/v1beta1
…
template:
  spec:
    containers:
      - name: redis
        image: redis:5.0.3-alpine
        resources:
&lt;strong&gt;limits&lt;/strong&gt;:
            memory: 600Mi
            cpu: 1
&lt;strong&gt;requests&lt;/strong&gt;:
            memory: 300Mi
            cpu: 500m
      - name: busybox
        image: busybox:1.28
        resources:
&lt;strong&gt;limits&lt;/strong&gt;:
            memory: 200Mi
            cpu: 300m
&lt;strong&gt;requests&lt;/strong&gt;:
            memory: 100Mi
            cpu: 100m&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Let’s say we are running a cluster with, for example, 4 cores and 16GB RAM nodes. We can extract a lot of information:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://sysdig.com/wp-content/uploads/Kubernetes-Limits-and-Request-05.png" rel="noopener noreferrer"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsysdig.com%2Fwp-content%2Fuploads%2FKubernetes-Limits-and-Request-05-1170x828.png" alt="Kubernetes Limits and Requests practical example" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Pod effective request&lt;/strong&gt; is 400 MiB of memory and 600 millicores of CPU. You need a node with enough free allocatable space to schedule the pod.&lt;/li&gt;



&lt;li&gt;
&lt;strong&gt;CPU shares&lt;/strong&gt; for the redis container will be 512, and 102 for the busybox container. Kubernetes always assign 1024 shares to every core, so redis: 1024 * 0.5 cores ≅ 512 and busybox: 1024 * 0.1cores ≅ 102&lt;/li&gt;



&lt;li&gt;Redis container will be &lt;strong&gt;OOM killed&lt;/strong&gt; if it tries to allocate more than 600MB of RAM, most likely making the pod fail.&lt;/li&gt;



&lt;li&gt;Redis will suffer &lt;strong&gt;CPU throttle&lt;/strong&gt; if it tries to use more than 100ms of CPU in every 100ms, (since we have 4 cores, available time would be 400ms every 100ms) causing performance degradation.&lt;/li&gt;



&lt;li&gt;Busybox container will be &lt;strong&gt;OOM killed&lt;/strong&gt; if it tries to allocate more than 200MB of RAM, resulting in a failed pod.&lt;/li&gt;



&lt;li&gt;Busybox will suffer &lt;strong&gt;CPU throttle&lt;/strong&gt; if it tries to use more than 30ms of CPU every 100ms, causing performance degradation.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id="kubernetesrequests"&gt;Kubernetes Requests&lt;/h2&gt;

&lt;p&gt;Kubernetes defines requests as a &lt;strong&gt;guaranteed minimum amount of a resource&lt;/strong&gt; to be used by a container.&lt;/p&gt;

&lt;p&gt;Basically, it will set the minimum amount of the resource for the container to consume.&lt;/p&gt;

&lt;p&gt;When a Pod is scheduled, kube-scheduler will check the Kubernetes requests in order to allocate it to a particular Node that can satisfy at least that amount for all containers in the Pod. If the requested amount is higher than the available resource, the Pod will not be scheduled and remain in Pending status.&lt;/p&gt;

&lt;p&gt;For more information about Pending status, check &lt;a href="https://sysdig.com/blog/kubernetes-pod-pending-problems/" rel="noreferrer noopener"&gt;Understanding Kubernetes Pod pending problems&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In this example, in the container definition we set a request for 100m cores of CPU and 4Mi of memory:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;resources:
   requests:
        cpu: 0.1
        memory: 4Mi&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Requests are used:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;When allocating Pods to a Node, so the indicated requests by the containers in the Pod are satisfied.&lt;/li&gt;



&lt;li&gt;At runtime, the indicated amount of requests will be guaranteed as a minimum for the containers in that Pod.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsysdig.com%2Fwp-content%2Fuploads%2Fimage4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsysdig.com%2Fwp-content%2Fuploads%2Fimage4.png" alt="How to set good CPU requests" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2 id="kuberneteslimits"&gt;Kubernetes Limits&lt;/h2&gt;

&lt;p&gt;Kubernetes defines &lt;strong&gt;limits&lt;/strong&gt; as a &lt;strong&gt;maximum amount of a resource&lt;/strong&gt; to be used by a container.&lt;/p&gt;

&lt;p&gt;This means that the container can never consume more than the memory amount or CPU amount indicated.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;    resources:
      limits:
        cpu: 0.5
        memory: 100Mi
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Limits are used:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;When allocating Pods to a Node. If no requests are set, by default, Kubernetes will assign requests = limits.&lt;/li&gt;



&lt;li&gt;At runtime, Kubernetes will check that the containers in the Pod are not consuming a higher amount of resources than indicated in the limit.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsysdig.com%2Fwp-content%2Fuploads%2Fimage6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsysdig.com%2Fwp-content%2Fuploads%2Fimage6.png" alt="Setting good Limits in Kubernetes" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2 id="cpuparticularities"&gt;CPU particularities&lt;/h2&gt;

&lt;p&gt;CPU is a &lt;strong&gt;compressible resource&lt;/strong&gt;, meaning that it can be stretched in order to satisfy all the demand. In case that the processes request too much CPU, some of them will be throttled.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CPU&lt;/strong&gt; represents &lt;strong&gt;computing processing time&lt;/strong&gt;, measured in cores. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You can use millicores (m) to represent smaller amounts than a core (e.g., 500m would be half a core)&lt;/li&gt;



&lt;li&gt;The minimum amount is 1m&lt;/li&gt;



&lt;li&gt;A Node might have more than one core available, so requesting CPU &amp;gt; 1 is possible&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsysdig.com%2Fwp-content%2Fuploads%2FKubernetes-Limits-and-Requests-1-1170x644.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsysdig.com%2Fwp-content%2Fuploads%2FKubernetes-Limits-and-Requests-1-1170x644.png" alt="Kubernetes requests for CPU image" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2 id="memoryparticularities"&gt;Memory particularities&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Memory&lt;/strong&gt; is a &lt;strong&gt;non-compressible&lt;/strong&gt; resource, meaning that it can’t be stretched in the same manner as CPU. If a process doesn’t get enough memory to work, the process is killed.&lt;/p&gt;

&lt;p&gt;Memory is measured in Kubernetes in &lt;strong&gt;bytes&lt;/strong&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You can use, E, P, T, G, M, k to represent Exabyte, Petabyte, Terabyte, Gigabyte, Megabyte and kilobyte, although only the last four are commonly used. (e.g., 500M, 4G)&lt;/li&gt;



&lt;li&gt;Warning: don’t use lowercase m for memory (this represents Millibytes, which is ridiculously low)&lt;/li&gt;



&lt;li&gt;You can define Mebibytes using Mi, as well as the rest as Ei, Pi, Ti (e.g., 500Mi)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;span&gt;&lt;em&gt;A Mebibyte (and their analogues Kibibyte, Gibibyte,...) is 2 to the power of 20 bytes. It was created to avoid the confusion with the Kilo, Mega definitions of the metric system. You should be using this notation, as it's the canonical definition for bytes, while Kilo and Mega are multiples of 1000&lt;/em&gt;&lt;br&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsysdig.com%2Fwp-content%2Fuploads%2FKubernetes-Limits-and-Requests-2-1170x644.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsysdig.com%2Fwp-content%2Fuploads%2FKubernetes-Limits-and-Requests-2-1170x644.png" alt="Kubernetes Limits for memory image" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2 id="bestpractices"&gt;Best practices&lt;/h2&gt;

&lt;p&gt;In very few cases should you be using limits to control your resources usage in Kubernetes. This is because if you want to avoid starvation (ensure that every important process gets its share), you should be using requests in the first place. &lt;/p&gt;

&lt;p&gt;By setting up limits, you are only preventing a process from retrieving additional resources in exceptional cases, causing an OOM kill in the event of memory, and Throttling in the event of CPU (process will need to wait until the CPU can be used again).&lt;/p&gt;

&lt;p&gt;For more information, check the &lt;a href="https://sysdig.com/blog/troubleshoot-kubernetes-oom/" rel="noopener noreferrer"&gt;article about OOM and Throttling&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If you’re setting a request value equal to the limit in all containers of a Pod, that Pod will get the Guaranteed Quality of Service. &lt;/p&gt;

&lt;p&gt;Note as well, that Pods that have a resource usage higher than the requests are more likely to be evicted, so setting up very low requests cause more harm than good.For more information, check the article about &lt;a href="https://docs.google.com/document/u/0/d/1NvedVZgcPdtiSIFZH_-q5-C43xt12nfMWERA6Mk5dOc/edit" rel="noopener noreferrer"&gt;Pod eviction and Quality of Service&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id="namespaceresourcequota"&gt;Namespace ResourceQuota&lt;/h2&gt;

&lt;p&gt;Thanks to namespaces, we can isolate Kubernetes resources into different groups, also called tenants.&lt;/p&gt;

&lt;p&gt;With &lt;strong&gt;ResourceQuotas&lt;/strong&gt;, you can &lt;strong&gt;set a memory or CPU limit to the entire namespace&lt;/strong&gt;, ensuring that entities in it can’t consume more from that amount.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;apiVersion: v1
kind: ResourceQuota
metadata:
  name: mem-cpu-demo
spec:
  hard:
    requests.cpu: 2
    requests.memory: 1Gi
    limits.cpu: 3
    limits.memory: 2Gi

&lt;/code&gt;&lt;/pre&gt;

&lt;ul&gt;
&lt;li&gt;requests.cpu: the maximum amount of CPU for the sum of all requests in this namespace&lt;/li&gt;



&lt;li&gt;requests.memory: the maximum amount of Memory for the sum of all requests in this namespace&lt;/li&gt;



&lt;li&gt;limits.cpu: the maximum amount of CPU for the sum of all limits in this namespace&lt;/li&gt;



&lt;li&gt;limits.memory: the maximum amount of memory for the sum of all limits in this namespace&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Then, apply it to your namespace:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;kubectl apply -f resourcequota.yaml --namespace=mynamespace
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;You can list the current ResourceQuota for a namespace with:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;kubectl get resourcequota -n mynamespace
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Note that if you set up ResourceQuota for a given resource in a namespace, you then need to specify limits or requests accordingly for every Pod in that namespace. If not, Kubernetes will return a “failed quota” error:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Error from server (Forbidden): error when creating "mypod.yaml": pods "mypod" is forbidden: failed quota: mem-cpu-demo: must specify limits.cpu,limits.memory,requests.cpu,requests.memory
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;In case you try to add a new Pod with container limits or requests that exceed the current ResourceQuota, Kubernetes will return an “exceeded quota” error:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Error from server (Forbidden): error when creating "mypod.yaml": pods "mypod" is forbidden: exceeded quota: mem-cpu-demo, requested: limits.memory=2Gi,requests.memory=2Gi, used: limits.memory=1Gi,requests.memory=1Gi, limited: limits.memory=2Gi,requests.memory=1Gi
&lt;/code&gt;&lt;/pre&gt;

&lt;h2 id="namespacelimitrange"&gt;Namespace LimitRange&lt;/h2&gt;

&lt;p&gt;ResourceQuotas are useful if we want to restrict the total amount of a resource allocatable for a namespace. But what happens if we want to give default values to the elements inside?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;LimitRanges&lt;/strong&gt; are a Kubernetes policy that &lt;strong&gt;restricts the resource settings for each entity&lt;/strong&gt; in a namespace.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;apiVersion: v1
kind: LimitRange
metadata:
  name: cpu-resource-constraint
spec:
  limits:
  - default:
      cpu: 500m
    defaultRequest:
      cpu: 500m
    min:
      cpu: 100m
    max:
      cpu: "1"
    type: Container
&lt;/code&gt;&lt;/pre&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;default&lt;/code&gt;: Containers created will have this value if none is specified.&lt;/li&gt;



&lt;li&gt;
&lt;code&gt;min&lt;/code&gt;: Containers created can’t have limits or requests smaller than this.&lt;/li&gt;



&lt;li&gt;
&lt;code&gt;max&lt;/code&gt;: Containers created can’t have limits or requests bigger than this.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Later, if you create a new Pod with no requests or limits set, LimitRange will automatically set these values to all its containers:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;    Limits:
      cpu:  500m
    Requests:
      cpu:  100m
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now, imagine that you add a new Pod with 1200M as limit. You will receive the following error:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Error from server (Forbidden): error when creating "pods/mypod.yaml": pods "mypod" is forbidden: maximum cpu usage per Container is 1, but limit is 1200m
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Note that by default, all containers in Pod will effectively have a request of 100m CPU, even with no LimitRanges set.&lt;/p&gt;

&lt;h2 id="conclusion"&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;Choosing the optimal limits for our Kubernetes cluster is key in order to get the best of both energy consumption and costs.&lt;/p&gt;

&lt;p&gt;Oversizing or dedicating too many resources for our Pods may lead to costs skyrocketing.&lt;/p&gt;

&lt;p&gt;Undersizing or dedicating very few CPU or Memory will lead to applications not performing correctly, or even Pods being evicted.&lt;/p&gt;

&lt;p&gt;As mentioned, Kubernetes limits shouldn’t be used, except in very specific situations, as they may cause more harm than good. There’s a chance that a Container is killed in case of Out of Memory, or throttled in case of Out of CPU.&lt;/p&gt;

&lt;p&gt;For requests, use them when you need to ensure a process gets a guaranteed share of a resource.&lt;/p&gt;








&lt;h2&gt;Rightsize your Kubernetes resources with Sysdig Monitor&lt;/h2&gt;





&lt;p&gt;With Sysdig Monitor new feature, cost advisor, you can optimize your Kubernetes costs&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Memory requests&lt;/li&gt;



&lt;li&gt;CPU requests&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Sysdig Advisor accelerates mean time to resolution (MTTR) with live logs, performance data, and suggested remediation steps. It’s the easy button for Kubernetes troubleshooting!&lt;/p&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsysdig.com%2Fwp-content%2Fuploads%2FKubernetes-Limits-and-Request-06-1170x1063.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsysdig.com%2Fwp-content%2Fuploads%2FKubernetes-Limits-and-Request-06-1170x1063.png" alt="" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://sysdig.com/company/free-trial-monitor/" rel="noopener noreferrer"&gt;Try it free for 30 days!&lt;/a&gt;&lt;/p&gt;

</description>
      <category>kubernetes</category>
      <category>monitoring</category>
      <category>cpu</category>
      <category>memory</category>
    </item>
    <item>
      <title>The four Golden Signals of Kubernetes monitoring</title>
      <dc:creator>Javier Martínez</dc:creator>
      <pubDate>Fri, 28 Oct 2022 09:20:10 +0000</pubDate>
      <link>https://dev.to/sysdig/the-four-golden-signals-of-kubernetes-monitoring-b7d</link>
      <guid>https://dev.to/sysdig/the-four-golden-signals-of-kubernetes-monitoring-b7d</guid>
      <description>&lt;p&gt;&lt;strong&gt;Golden Signals&lt;/strong&gt; are a reduced set of metrics that offer a wide view of a service from a user or consumer perspective: Latency, Traffic, Errors and Saturation. By focusing on these, you can be quicker at detecting potential problems that might be directly affecting the behavior of the application.&lt;/p&gt;

&lt;p&gt;Google introduced the term "Golden Signals" to refer to the essential metrics that you need to measure in your applications. They are the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
Errors - rate of requests that fail.&lt;/li&gt;



&lt;li&gt;
Saturation - consumption of your system resources.&lt;/li&gt;



&lt;li&gt;
Traffic - amount of use of your service per time unit.&lt;/li&gt;



&lt;li&gt;
Latency - the time it takes to serve a request.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://sysdig.com/wp-content/uploads/image9-10.png" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsysdig.com%2Fwp-content%2Fuploads%2Fimage9-10-1170x644.png" alt="The four Golden Signals of Kubernetes monitoring"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://sysdig.com/wp-content/uploads/BlogImages-GHAminer-featured-1.png" rel="noopener noreferrer"&gt;&lt;br&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is just a set of essential signals to start monitoring in your system. In other words, if you’re wondering which signals to monitor, you will need to look at these four first.&lt;/p&gt;

&lt;p&gt;Enter: Goldilocks and the four Monitoring Signals&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Once upon a time, there was a little girl called Goldilocks, who lived at the other side of the wood and had been sent on an errand by her mother, passed by the house, and looked in at the window…&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id="errors"&gt;Errors&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Goldilocks then tried the little chair, which belonged to the Little Bear, and found it just right, but she sat in it so hard that she broke it.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://sysdig.com/wp-content/uploads/image4-19.png" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsysdig.com%2Fwp-content%2Fuploads%2Fimage4-19-1170x644.png" alt="The four Golden Signals of Kubernetes monitoring"&gt;&lt;/a&gt;The error rate for the chairs is ⅓&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;Errors&lt;/strong&gt; golden signal measures the rate of requests that fail.&lt;/p&gt;

&lt;p&gt;Note that measuring the bulk amount of errors might not be the best course of action. If your application has a sudden peak of requests, then logically the amount of failed requests may increase.&lt;/p&gt;

&lt;p&gt;That’s why usually monitoring systems focus on the error rate, calculated as the percent of calls that are failing from the total.&lt;/p&gt;

&lt;p&gt;If you’re managing a web application, typically you will discriminate between those calls returning HTTP status in the 400-499 range (client errors) and 500-599 (server errors).&lt;/p&gt;

&lt;h3&gt;Measuring errors in Kubernetes&lt;/h3&gt;

&lt;p&gt;One thermometer for the errors happening in Kubernetes is the Kubelet. You can use several Kubernetes State Metrics in Prometheus to measure the amount of errors.&lt;/p&gt;

&lt;p&gt;The most important one is &lt;code&gt;kubelet_runtime_operations_errors_total&lt;/code&gt;, which indicates low level issues in the node, like problems with container runtime.&lt;/p&gt;

&lt;p&gt;If you want to visualize errors per operation, you can use &lt;code&gt;kubelet_runtime_operations_total&lt;/code&gt; to divide.&lt;/p&gt;

&lt;h3&gt;Errors example&lt;/h3&gt;

&lt;p&gt;Here's the Kubelet Prometheus metric for error rate in a Kubernetes cluster:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;sum(rate(kubelet_runtime_operations_errors_total{cluster="",
job="kubelet", metrics_path="/metrics"}[$__rate_interval])) 
by (instance, operation_type)
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;a href="https://sysdig.com/wp-content/uploads/image16-2-1170x445.png" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsysdig.com%2Fwp-content%2Fuploads%2Fimage16-2-1170x445.png" alt="The four Golden Signals of Kubernetes monitoring"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2 id="saturation"&gt;Saturation&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Goldilocks tasted the porridge in the dear little bowl, and it was just right, and it tasted so good that she tasted and tasted, and tasted and tasted until she was full.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://sysdig.com/wp-content/uploads/image17-2-1170x644.png" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsysdig.com%2Fwp-content%2Fuploads%2Fimage17-2-1170x644.png" alt="The four Golden Signals of Kubernetes monitoring"&gt;&lt;/a&gt;After eating one small bowl, Goldilocks is unable to eat more. That’s saturation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Saturation&lt;/strong&gt; measures the consumption of your system resources, usually as a percentage of the maximum capacity. Examples include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;CPU usage&lt;/li&gt;



&lt;li&gt;Disk space&lt;/li&gt;



&lt;li&gt;Memory usage&lt;/li&gt;



&lt;li&gt;Network bandwidth&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In the end, cloud applications run on machines, which have a limited amount of these resources.&lt;/p&gt;

&lt;p&gt;In order to correctly measure, you should be aware of the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What are the consequences if the resource is depleted? It could be that your entire system is unusable because this space has run out. Or maybe further requests are throttled until the system is less saturated.&lt;/li&gt;



&lt;li&gt;Saturation is not always about resources about to be depleted. It’s also about over-resourcing, or allocating a higher quantity of resources than what is needed. This one is crucial for cost savings.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;Measuring saturation in Kubernetes&lt;/h3&gt;

&lt;p&gt;Since saturation depends on the resource being observed, you can use different metrics for Kubernetes entities:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;node_cpu_seconds_total&lt;/code&gt; to measure machine CPU utilization.&lt;/li&gt;



&lt;li&gt;
&lt;code&gt;container_memory_usage_bytes&lt;/code&gt; to measure the memory utilization at container level (paired with &lt;code&gt;container_memory_max_usage_bytes&lt;/code&gt;).&lt;/li&gt;



&lt;li&gt;The amount of Pods that a &lt;a href="https://sysdig.com/learn-cloud-native/kubernetes-101/what-is-a-kubernetes-node/" rel="noopener noreferrer"&gt;Node&lt;/a&gt; can contain is also a Kubernetes resource.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;Saturation example&lt;/h3&gt;

&lt;p&gt;Here’s a PromQL example of a Saturation signal, measuring CPU usage percent in a Kubernetes node.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;100 - (avg by (instance) (rate(node_cpu_seconds_total{}[5m])) * 100)
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;a href="https://sysdig.com/wp-content/uploads/image13-8-1170x410.png" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsysdig.com%2Fwp-content%2Fuploads%2Fimage13-8-1170x410.png" alt="The four Golden Signals of Kubernetes monitoring"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2 id="traffic"&gt;Traffic&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;And the Middle-sized Bear said:&lt;br&gt;“Somebody has been tumbling my bed!”&lt;br&gt;And the Little bear piped:&lt;br&gt;“Somebody has been tumbling my bed, and here she is!”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://sysdig.com/wp-content/uploads/image12-7-1170x644.png" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsysdig.com%2Fwp-content%2Fuploads%2Fimage12-7-1170x644.png" alt="The four Golden Signals of Kubernetes monitoring"&gt;&lt;/a&gt;One of the beds is being used, but none should be being used instead. That’s an unusual traffic.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Traffic&lt;/strong&gt; measures the amount of use of your service per time unit.&lt;/p&gt;

&lt;p&gt;In essence, this will represent the usage of your current service. This is important not only for business reasons, but also to detect anomalies.&lt;/p&gt;

&lt;p&gt;Is the amount of requests too high? This could be due to a peak of users or because of a misconfiguration causing retries.&lt;/p&gt;

&lt;p&gt;Is the amount of requests too low? That may reflect that one of your systems is failing.&lt;/p&gt;

&lt;p&gt;Still, traffic signals should always be measured with a time reference. As an example, this blog receives more visits from Tuesday to Thursday.&lt;/p&gt;

&lt;p&gt;Depending on your application, you could be measuring traffic by:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Requests per minute for a web application&lt;/li&gt;



&lt;li&gt;Queries per minute for a database application&lt;/li&gt;



&lt;li&gt;Endpoint requests per minute for an API&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;Traffic example&lt;/h3&gt;

&lt;p&gt;Here’s a Google Analytics chart displaying traffic distributed by hour:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://sysdig.com/wp-content/uploads/image3-23.png" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsysdig.com%2Fwp-content%2Fuploads%2Fimage3-23.png" alt="The four Golden Signals of Kubernetes monitoring"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2 id="latency"&gt;Latency&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;At that, Goldilocks woke in a fright, and jumped out of the window and ran away as fast as her legs could carry her, and never went near the Three Bears’ snug little house again.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://sysdig.com/wp-content/uploads/image11-6-1170x644.png" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsysdig.com%2Fwp-content%2Fuploads%2Fimage11-6-1170x644.png" alt="The four Golden Signals of Kubernetes monitoring"&gt;&lt;/a&gt;Goldilocks ran down the stairs in just two seconds. That’s a very low latency.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Latency&lt;/strong&gt; is defined as the time it takes to serve a request.&lt;/p&gt;

&lt;h3&gt;Average latency&lt;/h3&gt;

&lt;p&gt;When working with latencies, your first impulse may be to measure average latency, but depending on your system that might not be the best idea. There may be very fast or very slow requests distorting the results.&lt;/p&gt;

&lt;p&gt;Instead, consider using a percentile, like p99, p95, and p50 (also known as median) to measure how the fastest 99%, 95%, or 50% of requests, respectively, took to complete.&lt;/p&gt;

&lt;h3&gt;Failed vs. successful&lt;/h3&gt;

&lt;p&gt;When measuring latency, it’s also important to discriminate between failed and successful requests, as failed ones might take sensibly less time than the correct ones.&lt;/p&gt;

&lt;h3&gt;Apdex Score&lt;/h3&gt;

&lt;p&gt;As described above, latency information may not be informative enough:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Some users might perceive applications as slower, depending on the action they are performing.&lt;/li&gt;



&lt;li&gt;Some users might perceive applications as slower, based on the default latencies of the industry.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is where the Apdex (Application Performance Index) comes in. It’s defined as:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://sysdig.com/wp-content/uploads/image1-37.png" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsysdig.com%2Fwp-content%2Fuploads%2Fimage1-37.png" alt="The four Golden Signals of Kubernetes monitoring"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Where t is the target latency that we consider as reasonable.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Satisfied will represent the amount of users with requests under the target latency.&lt;/li&gt;



&lt;li&gt;Tolerant will represent the amount of non-satisfied users with requests below four times the target latency.&lt;/li&gt;



&lt;li&gt;Frustrated will represent the amount of users with requests above the tolerant latency.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The output for the formula will be an index from 0 to 1, indicating how performant our system is in terms of latency.&lt;/p&gt;

&lt;h3&gt;Measuring latency in Kubernetes&lt;/h3&gt;

&lt;p&gt;In order to measure the latency in your Kubernetes cluster, you can use metrics like &lt;code&gt;http_request_duration_seconds_sum&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;You can also measure the latency for the api-server by using Prometheus metrics like &lt;code&gt;apiserver_request_duration_seconds&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;Latency example&lt;/h3&gt;

&lt;p&gt;Here’s an example of a Latency PromQL query for the 95% best performing HTTP requests in Prometheus:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;histogram_quantile(0.95, sum(rate(prometheus_http_request_duration_seconds_bucket[5m]))
by (le))
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;a href="https://sysdig.com/wp-content/uploads/image10-10-1170x408.png" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsysdig.com%2Fwp-content%2Fuploads%2Fimage10-10-1170x408.png" alt="The four Golden Signals of Kubernetes monitoring"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2 id="red-method"&gt;RED Method&lt;/h2&gt;

&lt;p&gt;The &lt;strong&gt;RED Method&lt;/strong&gt; was created by Tom Wilkie, from Weaveworks. It is heavily inspired by the Golden Signals and it’s focused on microservices architectures.&lt;/p&gt;

&lt;p&gt;RED stands for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Rate&lt;/li&gt;



&lt;li&gt;Error&lt;/li&gt;



&lt;li&gt;Duration&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Rate&lt;/strong&gt; measures the number of requests per second (equivalent to Traffic in the Golden Signals).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Error&lt;/strong&gt; measures the number of failed requests (similar to the one in Golden Signals).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Duration&lt;/strong&gt; measures the amount of time to process a request (similar to Latency in Golden Signals).&lt;/p&gt;

&lt;h2 id="use-method"&gt;USE Method&lt;/h2&gt;

&lt;p&gt;The &lt;strong&gt;USE Method&lt;/strong&gt; was created by Brendan Gregg and it’s used to measure infrastructure.&lt;/p&gt;

&lt;p&gt;USE stands for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Utilization&lt;/li&gt;



&lt;li&gt;Saturation&lt;/li&gt;



&lt;li&gt;Errors&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That means for every resource in your system (CPU, disk, etc.), you need to check the three elements above.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Utilization&lt;/strong&gt; is defined as the percentage of usage for that resource.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Saturation&lt;/strong&gt; is defined as the queue for requests in the system.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Errors&lt;/strong&gt; is defined as the number of errors happening in the system.&lt;/p&gt;

&lt;p&gt;While it may not be intuitive, Saturation in Golden Signals is not similar to the Saturation in USE, but rather Utilization.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://sysdig.com/wp-content/uploads/image8-12-1170x439.png" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsysdig.com%2Fwp-content%2Fuploads%2Fimage8-12-1170x439.png" alt="The four Golden Signals of Kubernetes monitoring"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2 id="practical-example"&gt;A practical example of Golden signals in Kubernetes&lt;/h2&gt;

&lt;p&gt;As an example to illustrate the use of Golden Signals, here’s a simple go application example with Prometheus instrumentation. This application will apply a random delay between 0 and 12 seconds in order to give usable information of latency. Traffic will be generated with curl, with several infinite loops.&lt;/p&gt;

&lt;p&gt;An &lt;a rel="noopener nofollow noreferrer" href="https://prometheus.io/docs/practices/histograms/"&gt;histogram&lt;/a&gt; was included to collect metrics related to latency and requests. These metrics will help us obtain the initial three Golden Signals: latency, request rate and error rate. To obtain saturation directly with Prometheus and node-exporter, use percentage of CPU in the nodes.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;
File: main.go
-------------
package main
import (
    "fmt"
    "log"
    "math/rand"
    "net/http"
    "time"
    "github.com/gorilla/mux"
    "github.com/prometheus/client_golang/prometheus/promhttp"
)
func main() {
    //Prometheus: Histogram to collect required metrics
    histogram := prometheus.NewHistogramVec(prometheus.HistogramOpts{
        Name:    "greeting_seconds",
        Help:    "Time take to greet someone",
        Buckets: []float64{1, 2, 5, 6, 10}, //Defining small buckets as this app should not take more than 1 sec to respond
    }, []string{"code"}) //This will be partitioned by the HTTP code.
    router := mux.NewRouter()
    router.Handle("/sayhello/{name}", Sayhello(histogram))
    router.Handle("/metrics", promhttp.Handler()) //Metrics endpoint for scrapping
    router.Handle("/{anything}", Sayhello(histogram))
    router.Handle("/", Sayhello(histogram))
    //Registering the defined metric with Prometheus
    prometheus.Register(histogram)
    log.Fatal(http.ListenAndServe(":8080", router))
}
func Sayhello(histogram *prometheus.HistogramVec) http.HandlerFunc {
    return func(w http.ResponseWriter, r *http.Request) {
        //Monitoring how long it takes to respond
        start := time.Now()
        defer r.Body.Close()
        code := 500
        defer func() {
            httpDuration := time.Since(start)
            histogram.WithLabelValues(fmt.Sprintf("%d", code)).Observe(httpDuration.Seconds())
        }()
        if r.Method == "GET" {
            vars := mux.Vars(r)
            code = http.StatusOK
            if _, ok := vars["anything"]; ok {
                //Sleep random seconds
                rand.Seed(time.Now().UnixNano())
                n := rand.Intn(2) // n will be between 0 and 3
                time.Sleep(time.Duration(n) * time.Second)
                code = http.StatusNotFound
                w.WriteHeader(code)
            }
            //Sleep random seconds
            rand.Seed(time.Now().UnixNano())
            n := rand.Intn(12) //n will be between 0 and 12
            time.Sleep(time.Duration(n) * time.Second)
            name := vars["name"]
            greet := fmt.Sprintf("Hello %s \n", name)
            w.Write([]byte(greet))
        } else {
            code = http.StatusBadRequest
            w.WriteHeader(code)
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The application was deployed in a Kubernetes cluster with Prometheus and Grafana, and generated a dashboard with Golden Signals. In order to obtain the data for the dashboards, these are the PromQL queries:&lt;/p&gt;

&lt;h3&gt;Latency:&lt;/h3&gt;

&lt;pre&gt;&lt;code&gt;sum(greeting_seconds_sum)/sum(greeting_seconds_count)  //Average
histogram_quantile(0.95, sum(rate(greeting_seconds_bucket[5m])) by (le)) //Percentile p95&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;Request rate:&lt;/h3&gt;

&lt;pre&gt;&lt;code&gt;sum(rate(greeting_seconds_count{}[2m]))  //Including errors
rate(greeting_seconds_count{code="200"}[2m])  //Only 200 OK requests&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;Errors per second:&lt;/h3&gt;

&lt;pre&gt;&lt;code&gt;sum(rate(greeting_seconds_count{code!="200"}[2m]))&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;Saturation:&lt;/h3&gt;

&lt;pre&gt;&lt;code&gt;100 - (avg by (instance) (irate(node_cpu_seconds_total{}[5m])) * 100)&lt;/code&gt;&lt;/pre&gt;

&lt;h2 id="conclusion"&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;Golden Signals, RED, and USE are just guidelines on what you should be focusing on when looking at your systems. But these are just the bare minimum on what to measure.&lt;/p&gt;

&lt;p&gt;Understand the &lt;strong&gt;errors&lt;/strong&gt; in your system. They will be a thermometer of all the other metrics, as they will point to any unusual behavior. And remember that you need to correctly mark requests as erroneous, but only the ones that should be exceptionally incorrect. Otherwise, your system will be prone to false positives or false negatives.&lt;/p&gt;

&lt;p&gt;Measure &lt;strong&gt;latency&lt;/strong&gt; of your requests. Try to understand your bottlenecks and what the negative experiences are when latency is higher than expected.&lt;/p&gt;

&lt;p&gt;Visualize &lt;strong&gt;saturation&lt;/strong&gt; and understand the resources involved in your solution. What are the consequences if a resource gets depleted?&lt;/p&gt;

&lt;p&gt;Measure &lt;strong&gt;traffic&lt;/strong&gt; to understand your usage curves. You will be able to find the best time to take down your system for an update, or you could be alerted when there’s an unexpected amount of users.&lt;/p&gt;

&lt;p&gt;Once metrics are in place, it’s important to set up alerts, which will notify you in case any of these metrics reach a certain threshold.&lt;/p&gt;









&lt;h2&gt;Track golden signals easily with Sysdig Monitor&lt;/h2&gt;
&lt;p&gt;With Sysdig Monitor, you can quickly review the golden signals in your system, out of the box.&lt;/p&gt;

&lt;p&gt;Review easily the Latency, Errors, Saturation and Traffic for the Pods in your cluster. And thanks to its Container Observability with eBPF, you can do this without adding any app or code instrumentation.&lt;/p&gt;

&lt;p&gt;Sysdig Advisor accelerates mean time to resolution (MTTR) with live logs, performance data, and suggested remediation steps. It’s the easy button for Kubernetes troubleshooting!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://sysdig.com/wp-content/uploads/GoldenSignals-11.png" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsysdig.com%2Fwp-content%2Fuploads%2FGoldenSignals-11.png" alt="Sysdig Monitor Golden Signals"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://sysdig.com/company/free-trial-monitor/" rel="noopener noreferrer"&gt;Try it free for 30 days!&lt;/a&gt;&lt;/p&gt;

</description>
      <category>kubernetes</category>
      <category>monitoring</category>
      <category>prometheus</category>
    </item>
  </channel>
</rss>
