<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Maxime Guilbert on Medium]]></title>
        <description><![CDATA[Stories by Maxime Guilbert on Medium]]></description>
        <link>https://medium.com/@max.g?source=rss-8ee640b430b2------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*0qqcjnn5kShenMhVOU9jjg.jpeg</url>
            <title>Stories by Maxime Guilbert on Medium</title>
            <link>https://medium.com/@max.g?source=rss-8ee640b430b2------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 17:59:19 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@max.g/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Check user RBAC rights]]></title>
            <link>https://medium.com/@max.g/check-user-rbac-rights-68722ec3b2a7?source=rss-8ee640b430b2------2</link>
            <guid isPermaLink="false">https://medium.com/p/68722ec3b2a7</guid>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[rbac]]></category>
            <dc:creator><![CDATA[Maxime Guilbert]]></dc:creator>
            <pubDate>Mon, 04 Sep 2023 13:12:25 GMT</pubDate>
            <atom:updated>2023-09-04T13:12:25.935Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eg--iOaNzPCxPX7JBO809A.png" /></figure><p>When we work with a Kubernetes cluster, it happends that we don’t remember if a user or service account has a specific right.</p><p>So, to help us to not search in all the RBAC definition file, we can use the kubectl auth can-i command.</p><h3>Command details</h3><h3>Current user</h3><pre>kubectl auth can-i [action] [resource]</pre><p>With this template, you can check if <strong>the current user is able to the action noted in the command on the resource type noted in the command.</strong></p><p><em>Example to check if the current user can create a pod :</em></p><pre>kubectl auth can-i create pod</pre><p>The result will be yes if you have the permissions, or no if you haven&#39;t.</p><h3>Define namespace</h3><p>The current command will ask for the permissions for cluster-scoped resources or for namespaced-scoped resources in the default namespace.</p><p>If you want to ask the rights in a particular namespace, you just have to add the option --namespace [name of the namespace].</p><h3>Impersonnate another user</h3><p>If you want to check the permissions for another user, you can impersonnate it by adding the option --as at the end of the command, followed by the name of the user.</p><p><em>Example to check if toto can list deployments:</em></p><pre>kubectl auth can-i list deployment --as toto</pre><h3>Impersonnate a service account</h3><p>To impersonnate a service account, use the same --as option but with the following template : system:serviceaccount:[namespace]:[nom service account].</p><p><em>Example to check if the service account titi in the test namespace can delete configmap :</em></p><pre>kubectl auth can-i delete configmap --as system:serviceaccount:test:titi</pre><h3>References</h3><ul><li><a href="https://kubernetes.io/docs/reference/access-authn-authz/authorization/#checking-api-access">Documentation Kubernetes — Commande auth can-i</a></li><li><a href="https://www.mankier.com/1/kubectl-auth-can-i">Man — Kubectl auth can-i</a></li></ul><p>And that’s it! Really easy to use and can same some time!</p><p>I hope it will help you and if you have any questions <em>(there are not dumb questions)</em> or some points are not clear for you, don’t hesitate to add your question in the comments or to contact me directly on <a href="https://www.linkedin.com/in/maxime-guilbert-14b6a5128/">LinkedIn</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=68722ec3b2a7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Monitor an operator]]></title>
            <link>https://medium.com/@max.g/monitor-an-operator-1004e9a79242?source=rss-8ee640b430b2------2</link>
            <guid isPermaLink="false">https://medium.com/p/1004e9a79242</guid>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[monitoring]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Maxime Guilbert]]></dc:creator>
            <pubDate>Mon, 28 Aug 2023 14:12:37 GMT</pubDate>
            <atom:updated>2023-08-28T14:12:37.425Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nDbIFFh4P8odUruj6jlepw.png" /></figure><p>Having an Kubernetes operator is quite cool, but if everything goes well. To track this and potentially adding alerts on it, we must have metrics.</p><p>And that’s good, by default with the Golang Operator SDK, we already have a couple of metrics which are available.</p><h3>Available metrics</h3><p>The following list is an overview of all the metrics available. To see the full list, please check the <a href="https://book.kubebuilder.io/reference/metrics-reference.html">Kubebuilder reference</a>.</p><ul><li>controller_runtime_reconcile_total : Counter - Total number of reconciliations per controller.</li><li>controller_runtime_reconcile_errors_total : Counter - Total number of reconciliation errors per controller.</li><li>controller_runtime_reconcile_time_seconds : Histogram - Length of time per reconciliation per controller.</li><li>controller_runtime_webhook_requests_total : Counter - Total number of admission requests by HTTP status code.</li></ul><h3>Add metrics</h3><p>Even if the generic metrics from Kubebuilder are useful, they may not be enough for your use cases.</p><p>For this, there is something to do to easily add more metrics. With the package github.com/prometheus/client_golang/prometheus, create all the metrics you may need</p><pre>import ( <br>    &quot;github.com/prometheus/client_golang/prometheus&quot; <br>)<br><br>var ( <br>    goobers = prometheus.NewCounter( <br>        prometheus.CounterOpts{ <br>            Name: &quot;goobers_total&quot;, <br>            Help: &quot;Number of goobers proccessed&quot;, <br>        }, <br>    ) <br>    gooberFailures = prometheus.NewCounterVec( <br>        prometheus.CounterOpts{ <br>            Name: &quot;goober_failures_total&quot;,<br>            Help: &quot;Number of failed goobers&quot;, <br>        }, []string{&quot;label_1&quot;}<br>    )<br>)</pre><p>Then register them in the metric registry of the operator</p><pre>import ( <br>    &quot;sigs.k8s.io/controller-runtime/pkg/metrics&quot; <br>)<br><br>func init() { <br>    metrics.Registry.MustRegister(goobers, gooberFailures) <br></pre><p>Once it’s done, congrats! You can use these metrics wherever you want!</p><pre>goobers.Inc()<br>goobers.Add(2)<br><br>gooberFailures.WithLabelValues(&quot;toto&quot;).Inc()<br>gooberFailures.WithLabelValues(&quot;titi&quot;).Add(2)</pre><blockquote><em>Metrics with labels</em></blockquote><blockquote><em>As you can see in the previous example, if you want to create a metric with labels, you can use </em><em>New...Vec. It will ask you to give a list of labels name, and then will ask you to use </em><em>WithLabelValues to fill the value for each label when you will want to update a metric value. Quite useful if you always have the same labels.</em></blockquote><blockquote><em>Otherwise, you can use </em><em>.With() to add all the labels you want when updating a metric value.</em></blockquote><blockquote><em>ex: </em><em>.With(map[string]string{&quot;toto&quot;: &quot;titi&quot;}).Inc()</em></blockquote><p>At the end, an operator is a service like all the others and should be monitored to be sure that everything is going well in your stack. Like a lot of other things, Operator SDK and Kubebuilder help us a lot by simplifying all this process.</p><p>I hope it will help you and if you have any questions <em>(there are not dumb questions)</em> or some points are not clear for you, don’t hesitate to add your question in the comments or to contact me directly on <a href="https://www.linkedin.com/in/maxime-guilbert-14b6a5128/">LinkedIn</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1004e9a79242" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Questions to ask before starting to dev]]></title>
            <link>https://medium.com/@max.g/questions-to-ask-before-starting-to-dev-d8dc30773d9b?source=rss-8ee640b430b2------2</link>
            <guid isPermaLink="false">https://medium.com/p/d8dc30773d9b</guid>
            <category><![CDATA[thinking]]></category>
            <category><![CDATA[tech]]></category>
            <dc:creator><![CDATA[Maxime Guilbert]]></dc:creator>
            <pubDate>Mon, 21 Aug 2023 14:06:02 GMT</pubDate>
            <atom:updated>2023-08-21T14:06:02.222Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EnVmCJLkQGWOSq_U83S_2w.png" /></figure><p>In a world where everything goes quick, a lot of people and companies tries to go further quickly as possible to be the first one to have a new feature or product. However this speed brings a certain precipitation which can add some trouble to your project, which can bring some feature redevelopment, being late on schedules or an instability in production.</p><p>Between what I lived, everything I red and what I’ve learned from other people in IT, I saw that it happens frequently, too much frenquently. It doesn’t mean that the people/teams/companies will fail in their project. A lot of them succeeded since and some of these products are still used.</p><p>But at this point some questions can be asked :</p><ul><li>What was the cost of this ?</li><li>How much time did they took to redirect their solution ?</li><li>Do they keep the confidence and satisfaction from their clients?</li></ul><p>Without talking about the direct impact of the time and money lost to redevelop the product, it can have an indirect impact from your customers because some of them will stop to use your product or will lose their confidence in your solution. May be they won’t directly leave, but they may check if is there something else to replace your product.<br><em>(For sure this is not something which can be easily mesurable as a lot external things can lead to this too.)</em></p><p>And that’s why we will talk about some questions that will help you to be sure of the direction you will take with your project.</p><h3>What are the prerequisites for my product?</h3><blockquote><em>Start with the Customer Experience, then work back to the technology<br></em><a href="https://serviceinindustry.com/2019/08/19/steve-jobs-on-starting-with-the-customer-experience-then-work-back-to-technology/"><em>Citation Steve Jobs</em></a></blockquote><p>This question should be ask to think first at what we want to offer to the client. Which features? Do we want to be fast? secure? …</p><p>Having a precise idea of this is really important, and it’s a major cause of rewriting projects. And it happens everywhere. For example if you decide to add after a year of development a duration requirement to have all the processes done in less than a second and you don’t have any similar requirements before.</p><p>If your project is very large and containts a lot of features, be focused on <strong>features with the most contraints and/or the one with particular needs</strong>. Indeed if you have one crucial feature and all the other are only managing data in a database without any contraints, they won’t need to be a priority because they will fit any context.</p><h3>In which context are you building this solution ?</h3><p>Here we want to know which kind of architecture, tools, technologies we want to use.</p><p>For example :</p><ul><li>Doing microservices for a small todo app won’t be interesting</li><li>Having a huge system with multiple shops in a monolith knowing that you will have to increase and decrease the number of shops regularly won’t be interesting too</li></ul><p>Also you must check the context of your company. If all the dev masterize Java, it won’t be interesting to take something else if perfomances are correct for your requirements.</p><p>BUT you must check that it matches with your requirements. Indeed it’s easier to take the same technologies and architectures from all the other projects of your company. But doing this can be a huge trap as it won’t fit at all your needs. In that case it can happen that you will only see it too late.</p><h3>What is the long term vision for the product?</h3><p>This question is really important as it can prepare the product for futur features. The idea is not to analyze the future features but thinking about what can be asked later and see if some things can be done or prepared now.</p><p>For example :</p><ul><li>Is there some features which will be reused? If yes, which ones? How they will be shared? <em>(package, microservice…)</em></li><li>Do we expect a huge usage increase in the future ?</li><li>Do some criterias will be more strict in the future? <em>(like the latency)</em></li></ul><h3>Are we going into the right way ?</h3><p>A simple question which can challenge you to check if everything is correctly defined and if you are sure about the architecture and the tools to use.</p><p>If you are not completly sure, you can :</p><ul><li><strong>ask an expert in the domain</strong></li><li><strong>do some Proofs of Concepts on the points you are not sure</strong></li></ul><p>It can take a bit of time but at the end will reassure you about your choices.</p><p>At the end, we saw that there is no miracle receipe to create a project. But we saw that we can prepare and check a lot of things to build great things without losing time by recreating thing.</p><p>I hope it will help you and if you have any questions <em>(there are not dumb questions)</em> or some points are not clear for you, don’t hesitate to add your question in the comments or to contact me directly on <a href="https://www.linkedin.com/in/maxime-guilbert-14b6a5128/">LinkedIn</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d8dc30773d9b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why everyone should have a blog ?]]></title>
            <link>https://medium.com/@max.g/why-everyone-should-have-a-blog-9f85ede45f5d?source=rss-8ee640b430b2------2</link>
            <guid isPermaLink="false">https://medium.com/p/9f85ede45f5d</guid>
            <category><![CDATA[writing]]></category>
            <category><![CDATA[blog]]></category>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[blogging]]></category>
            <dc:creator><![CDATA[Maxime Guilbert]]></dc:creator>
            <pubDate>Mon, 14 Aug 2023 14:06:01 GMT</pubDate>
            <atom:updated>2023-08-14T14:06:01.879Z</atom:updated>
            <content:encoded><![CDATA[<h3>Why everyone should have a blog ?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hszTbPYR7U--xH2gAoEnYw.png" /></figure><p>With the explosion of internet in our lifes and platforms to share informations, a lot of people are publishing posts on differents subjects. In the IT industry, these posts can be about a concept, technologies or tools. And we read a lot of them.</p><h3>Why these posts are so importants?</h3><p>These posts are importants because it will often help us to understand how to use something, how can we improve our skills… or resolve an issue that someone else has already encountered.</p><p>Often more accessible than documentations, they have a playful way to teach things that helps to understand complexe notions notably with examples and/or schemas.</p><h3>Why everyone should have a blog ?</h3><p>In this IT world, we search informations online everyday, so having a blog will let you share what you’ve experienced, what you’ve discovered, some tips, how to resolve particular issues…</p><p>Don’t you ever wondering why there’s no posts on a particular subject or on a particular error?</p><p>If yes, you will understand why it can be important to share this kind of informations.</p><p>Also a lot of tools are in niches which are not easy to find and/or understand. So having posts about it will help to expose it and having more informations for anyone which want to use it and understand how it works.</p><h3>Winnings to have a blog</h3><p>Without talking about money or other things like that, having a blog can have huge payoffs for you.</p><h3>Subject mastering</h3><p>A principe of education says that if someone wants to memorize easily something or to start to master a subject, they must be able to explain with their own words the subject. May be in a easier way with examples.</p><p>It doesn’t make you think about something?</p><p>Earlier we said that articles that are posted online are often simple explainations about more complexe concepts. For sure some people don’t need to write these posts to memorize and master the subject, but a lot of people like me are writing posts to help them to see if they are able to explain and summarize all the informations they learned about a subject.</p><p>From my experience, I garantee you that it helps me to memorize a lot of things. The work to find a way to explain the subject with your own words is really powerful. Because as you already know the words you are using, you don’t have to remember the definition of a lot of new words. And naturally the information will be easier to remember.</p><h3>Improve writing skills</h3><p>By writing posts you will improve your writing skills. Being able to explain things requires to be a bit organized. So writing will help you with this.</p><p>Also it will help you to figure out what is the most important informations to share in a few lines.</p><h3>Improve in a foreign language</h3><p>It doesn’t concern everyone, but it’s something that help me a lot : improve my skills in another language.</p><p>To be able to share my posts to a lot of people, I write my posts in english. Even it’s the language used is almost all the technical documentations, being able to explain something in english requires more vocabulary at least and helps to improve our communication skill in this language.</p><h3>Conclusion</h3><p>For all these reasons, that’s why I think everyone should have a blog. For sure it’s a huge time investment for may be nothing. <em>(I wrote technical posts for the last 3 years and I didn’t earn anything)</em> But it’s still interesting to do it and I encourage anyone to give a try.</p><p>I hope it will help you and if you have any questions <em>(there are not dumb questions)</em> or some points are not clear for you, don’t hesitate to add your question in the comments or to contact me directly on <a href="https://www.linkedin.com/in/maxime-guilbert-14b6a5128/">LinkedIn</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9f85ede45f5d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[K8s operator — Synchronize resources outside Kubernetes cluster]]></title>
            <link>https://blog.devgenius.io/k8s-operator-synchronize-resources-outside-kubernetes-cluster-880a3be56018?source=rss-8ee640b430b2------2</link>
            <guid isPermaLink="false">https://medium.com/p/880a3be56018</guid>
            <category><![CDATA[sre]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[operators]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Maxime Guilbert]]></dc:creator>
            <pubDate>Mon, 07 Aug 2023 13:11:47 GMT</pubDate>
            <atom:updated>2023-08-08T12:20:36.717Z</atom:updated>
            <content:encoded><![CDATA[<h3>K8s operator — Synchronize resources outside Kubernetes cluster</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vfCSw3YzrLYbfNxDL-1_vg.jpeg" /></figure><p>When we automate tasks/resources in a Kubernetes Cluster, we first think about managing Kubernetes resources. But we must not forget that we are not limited to what is presented to us.</p><p>Like every post since the begining of this serie, we will talk about the Operator SDK, the Go framework to create operators. And who says Go, says that we can :</p><ul><li><strong>read into a database</strong></li><li><strong>call an API</strong></li><li><strong>write a message in a queue</strong></li><li>…</li></ul><p>Indeed, <strong>everything which is possible in Go is possible in your operator</strong>.</p><blockquote>Why it is interesting?</blockquote><p>For a simple reason, <strong>you are not limited to your Kubernetes cluster context to automate tasks and resources management.</strong></p><p>Here is a simple example: You manage Prometheus and/or Thanos instances in your cluster with your operator, but you have a single Grafana instance for all these Prometheus/Thanos instances and it’s outside of your cluster. In this case, if you want to manage the datasource in Grafana, you must do it through the API.<br>And here the operator power skyrockets because you can use any API or service which manage resources. You don’t need to implement something particular or migrate it into your Kubernetes cluster.</p><p>For sure, it won’t be useful for everyone but think about the following example :<br>You are in a compagny which offer several services to your clients, including :</p><ul><li>a metric collector with Promtheus</li><li>a Grafana instance to monitor all the metrics The issue is that each element is managed by a dedicated operator on a dedicated Kubernetes cluster. How can you automate the management of a customer stack ?</li></ul><p>Answer : <strong>With APIs !</strong></p><p>With dedicated APIs to manage your resources <em>(by using the </em><a href="https://learning.oreilly.com/home/"><em>Python Kubernetes</em></a><em> library for example)</em> or by using the <a href="https://kubernetes.io/docs/reference/using-api/api-concepts/">Kubernetes API</a>, you can have an operator which can manage all the stack by calling all the other operators with these APIs.<br>From this, all the spread stack can be automated!</p><p>I hope it will help you and if you have any questions <em>(there are not dumb questions)</em> or some points are not clear for you, don’t hesitate to add your question in the comments or to contact me directly on <a href="https://www.linkedin.com/in/maxime-guilbert-14b6a5128/">LinkedIn</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=880a3be56018" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/k8s-operator-synchronize-resources-outside-kubernetes-cluster-880a3be56018">K8s operator — Synchronize resources outside Kubernetes cluster</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to minimize your carbon footprint with Kube-Green?]]></title>
            <link>https://blog.devgenius.io/how-to-minimize-your-carbon-footprint-with-kube-green-1bb38d574f1?source=rss-8ee640b430b2------2</link>
            <guid isPermaLink="false">https://medium.com/p/1bb38d574f1</guid>
            <category><![CDATA[operators]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[sre]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Maxime Guilbert]]></dc:creator>
            <pubDate>Mon, 31 Jul 2023 13:22:28 GMT</pubDate>
            <atom:updated>2023-08-01T13:17:31.356Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jH-jn4X7QrvR0oQsyUlk7A.png" /></figure><p>We are in an era where digital solutions are more and more present in our everyday life, but all this digital world <em>(especially all the tooling behind)</em> is a source of pollution.</p><p>As you can sort you waste or reuse a lot of things, we will see how you can reduce your carbon print <em>(and your cloud provider billing)</em> with your Kubernetes cluster!</p><h3>Kube-Green</h3><p><strong>Kube-Green</strong> is an operator that can <strong>scale down your deployments to 0</strong> and <strong>avoid your CronJobs to be triggered outside your “working days”</strong>.</p><p>The objective is simple, shutdown your pods and jobs that can run during the night or during weekends, before restarting them in the morning of your working days. So a lot of process are not running “for nothing”, generating CO2 and it can scale down the number of nodes of your cluster if you are on AWS. <em>(The money saving part)</em></p><h3>When can I use it?</h3><p>For sure, if you have a 24/7 service in your production, you should not use it in this environment. If your production is only used during particular time frames, it can be used in this case.</p><p>In general this operator is more oriented for dev and/or tests environments, which are generally always up for no reasons.</p><h3>Is it possible to exclude some processes?</h3><p>It’s a good question because you may need to keep particular jobs or pods even in a dev environment. So <strong>it’s possible</strong> and we will see later how we can do it.</p><h3>Serup</h3><blockquote><em>All the following informations about the setup is coming from the </em><a href="https://kube-green.dev/docs/install/"><em>KubeGreen documentation</em></a><em>. So don’t hesitate to check it there directly to have the latest version of the setup documentation.</em></blockquote><h3>Prerequirements</h3><p>On this day <em>(early june 2023)</em> KubeGreen works with <strong>Kubernetes 1.19 to 1.26</strong> and <strong>OpenShift v4</strong>.</p><p>Also you need to have <a href="https://cert-manager.io/docs/installation/"><strong>cert-manager</strong></a> to be installed on your cluster.</p><h3>Installation</h3><p>Several ways are offered by KubeGreen, but we will only use <strong>kubectl apply</strong> in this post.</p><p>If you want the latest version of KubeGreen, use the following command</p><pre>kubectl apply -f https://github.com/kube-green/kube-green/releases/latest/download/kube-green.yaml</pre><p>But if you want a precise version of KubeGreen, use the following command and replace ${RELEASE_TAG} by the version number you want.</p><pre>kubectl apply -f https://github.com/kube-green/kube-green/releases/download/${RELEASE_TAG}/kube-green.yaml</pre><blockquote><em>*</em>/!\ Warning : If you want to use it in the cloud /!\*<em><br>The </em><a href="https://kube-green.dev/docs/install/#cloud-compatibility"><em>documentation</em></a><em> says that you can encounter several issues if you are using KubeGreen in GKE or AWS. So if you are in this case, go check the documentation before going forward.</em></blockquote><h3>Configuration</h3><p>Once the operator deployed, you can create a SleepInfo instance that will define which resources must be stopped, when they should be stopped and when they must be restarted.</p><p>You must know that SleepInfo <strong>only act in the namespace where it&#39;s deployed</strong>. It means that you <strong>must deploy a instance of </strong><strong>SleepInfo in each namespace you want to use KubeGreen</strong>. <em>(It will avoid to shutdown necessary deployments for the proper functionning of the cluster)</em></p><pre>apiVersion: kube-green.com/v1alpha1  <br>kind: SleepInfo  <br>metadata:  <br>    name: working-hours  <br>spec:  <br>    weekdays: &quot;1-5&quot;  <br>    sleepAt: &quot;20:00&quot;  <br>    wakeUpAt: &quot;08:00&quot;  <br>    timeZone: &quot;Europe/Rome&quot;</pre><p>In this example, which is the simplest use case of KubeGreen, all the deployment in the namespace will be shutdown at 20:00 <em>(Rome timezone)</em> from monday to friday, and they will be restarted from monday to friday at 08:00 <em>(Rome timezone)</em>.</p><p>To have a better understanding about SleepInfo, we will check every field and then see differents use cases.</p><h3>SleepInfo : Fields</h3><p>weekdays : Define week days where the operator must act.</p><ul><li>1 is for monday</li><li>1-5 is from monday to friday</li><li>2-6 is from tuesday to saturday</li><li>* is for everyday</li></ul><p>sleepAt : Define with the HH:mm pattern, it will define the time when resources must be stopped. <em>(ex: 19:00, 08:53: 23:45)</em></p><p>wakeUpAt : [Optionnal] Define with the HH:mm pattern, it will define the time when resources must be restarted. <em>(ex: 19:00, 08:53: 23:45)</em></p><p>timeZone : [Optionnal] Define the timezone related to times defined previously</p><ul><li>This value must match <strong>a timezone name listed in the IANA specification</strong>. <em>(TZ identifier column in </em><a href="https://en.wikipedia.org/wiki/List_of_tz_database_time_zones"><em>Wikipedia — Timezones</em></a><em>)</em></li><li>Default value is UTC.</li></ul><p>suspendDeployments : [Optionnal] Boolean to let the operator knows if it must shutdown deployments in this namespace.</p><ul><li>Default value is true.</li></ul><p>suspendCronJobs : [Optionnal] Boolean to let the operator knows if it must shutdown cronjobs in this namespace.</p><ul><li>Default value is false</li></ul><p>excludeRef : [Optionnal] Object array containing references to deployments and/or cronjobs to exclude.</p><ul><li>apiVersion : Resource version to exclude. Actually supported : apps/v1, batch/v1beta1 and batch/v1 <em>(don&#39;t use this property if you are using </em><em>matchLabels)</em></li><li>kind : Kind of resource to exclude. Actually supported : Deployment and CronJob <em>(don&#39;t use this property if you are using </em><em>matchLabels)</em></li><li>name : Name of the resource to exclude <em>(don&#39;t use this property if you are using </em><em>matchLabels)</em></li><li>matchLabels : Label list to identify resources to exclude <em>(don&#39;t use this property if you are using </em><em>name, </em><em>apiVersion and </em><em>kind)</em></li></ul><h3>Use cases</h3><h4>Stop everything except api-gateway deployment</h4><pre>apiVersion: kube-green.com/v1alpha1<br>kind: SleepInfo<br>metadata:<br>  name: working-hours<br>spec:<br>  weekdays: &quot;1-5&quot;<br>  sleepAt: &quot;20:00&quot;<br>  wakeUpAt: &quot;08:00&quot;<br>  timeZone: &quot;Europe/Rome&quot;<br>  suspendCronJobs: true<br>  excludeRef:<br>    - apiVersion: &quot;apps/v1&quot;<br>      kind:       Deployment<br>      name:       api-gateway</pre><p>In this example, we can see that we want to shutdown everything <em>(deployments &amp; cronjobs)</em> at 20:00 from monday to friday and restart them at 08:00 from monday to friday, <strong>except “api-gateway” deployment</strong>.</p><p>Useful if you only have few resources to exclude.</p><h4>Shutdown everything except the one with a particular label</h4><pre>apiVersion: kube-green.com/v1alpha1<br>kind: SleepInfo<br>metadata:<br>  name: working-hours<br>spec:<br>  weekdays: &quot;1-5&quot;<br>  sleepAt: &quot;20:00&quot;<br>  wakeUpAt: &quot;08:00&quot;<br>  timeZone: &quot;Europe/Rome&quot;<br>  suspendCronJobs: true<br>  excludeRef:<br>    - matchLabels: <br>        kube-green.dev/exclude: true</pre><p>In this example, we can see that everything will be shutdown except resources with the label kube-green.dev/exclude: true.</p><p>You must use it if you have a lot of resources to exclude.</p><h4>Only stop CronJobs</h4><pre>apiVersion: kube-green.com/v1alpha1<br>kind: SleepInfo<br>metadata:<br>  name: working-hours<br>spec:<br>  weekdays: &quot;*&quot;<br>  sleepAt: &quot;20:00&quot;<br>  wakeUpAt: &quot;08:00&quot;<br>  suspendCronJobs: true<br>  suspendDeployments: false</pre><p>To stop only all the CronJobs, you must set suspendCronJobs to true and suspendDeployments to false.</p><h4>Without restart</h4><pre>apiVersion: kube-green.com/v1alpha1<br>kind: SleepInfo<br>metadata:<br>  name: working-hours<br>spec:<br>  weekdays: &quot;1-5&quot;<br>  sleepAt: &quot;20:00&quot;<br>  timeZone: &quot;Europe/Rome&quot;<br>  suspendCronJobs: true<br>  excludeRef:<br>    - apiVersion: &quot;apps/v1&quot;<br>      kind:       Deployment<br>      name:       api-gateway</pre><p>This example is useful to let us know that defining the wakeUpAt value is mendatory. You can ask in which case it can be useful, and there are a simple case : test environments.</p><p>Depending on your context, you can have a testing and/or load testing environment which is used once in a month or less. In this case, restarting the environment during weeks without tests is useless. And you will still be able to update the SleepInfo instance to restart all the pods when needed.</p><h3>Links</h3><ul><li><a href="https://kube-green.dev/">Kube-Green Website</a></li><li><a href="https://github.com/kube-green/kube-green">Kube-Green — Github project</a></li></ul><h3>Conclusion</h3><p>KubeGreen is a promising project which, I hope, will help us to have less impact on our planet. I think about stopping useless daemonsets, interact with other operators <em>(like Crossplane to shutdown resources in the cloud)</em>…</p><p>May be it seems nothing, but like everything else, if we are all doing little efforts here and there, it will make something big!</p><p>I hope it will help you and if you have any questions <em>(there are not dumb questions)</em> or some points are not clear for you, don’t hesitate to add your question in the comments or to contact me directly on <a href="https://www.linkedin.com/in/maxime-guilbert-14b6a5128/">LinkedIn</a>.</p><p>You want to support me ? <a href="https://www.buymeacoffee.com/mxguilbert7.">Buy me a coffee</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1bb38d574f1" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/how-to-minimize-your-carbon-footprint-with-kube-green-1bb38d574f1">How to minimize your carbon footprint with Kube-Green?</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[K8s Operator — Index with name … does not exist]]></title>
            <link>https://blog.devgenius.io/k8s-operator-index-with-name-does-not-exist-b48bb72566bc?source=rss-8ee640b430b2------2</link>
            <guid isPermaLink="false">https://medium.com/p/b48bb72566bc</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[sre]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Maxime Guilbert]]></dc:creator>
            <pubDate>Mon, 24 Jul 2023 13:01:49 GMT</pubDate>
            <atom:updated>2023-07-24T16:00:48.611Z</atom:updated>
            <content:encoded><![CDATA[<h3>K8s Operator — Index with name … does not exist</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pvouClnL2tEIxXyAfnao_A.png" /></figure><p>During development on a Kubernetes operators, you may have this error while trying to get a list of objects filtering by a specific field.</p><pre>can not retrieve list of objects using index : Index with name [field path] does not exist</pre><h3>What generates this issue?</h3><p>From what I’ve seen, by default only fields which are constantly defined are indexed. <em>(like mandatory fields in your spec)</em></p><p>So if you try to filter on another field, there are high chances that you will have the error.</p><h3>How to resolve this issue?</h3><p>To resolve this issue, you can declare a new index to your manager instance and your context.</p><p>You will need :</p><ul><li><strong>the kind of object</strong> which will have the new index</li><li>the <strong>name of the new index</strong> <em>(generally corresponding to the path to the desired field)</em></li><li>the <strong>function which will return the value associated to the index</strong></li></ul><p><em>Example</em></p><pre>package main<br><br>import (<br>    &quot;context&quot;<br>    k8sruntime &quot;k8s.io/apimachinery/pkg/runtime&quot;<br>    &quot;example.com/example-operator/pkg/apis/example/v1alpha1&quot;  <br>    &quot;sigs.k8s.io/controller-runtime/pkg/client&quot;<br>    // ...<br>)<br>function main() {<br>    // ...<br>    cache := mgr.GetCache()<br>    indexFunc := func(obj client.Object) []string {<br>        return []string{obj.(*v1alpha1.Example).Spec.SomeField}<br>    }<br>    if err := cache.IndexField(ctx, &amp;v1alpha1.Example{}, &quot;spec.someField&quot;, indexFunc); err != nil {<br>        panic(err)<br>    }<br>    // ...<br>}</pre><p>As a result, even if it is generally used to index another field from an objecct, you can <strong>create an index which will return a dynamic value</strong>. Something which can be really useful in a lot of cases. <em>(ex: Return true if the object contains some specific value in multiple fields)</em></p><p>I hope it will help you and if you have any questions <em>(there are not dumb questions)</em> or some points are not clear for you, don’t hesitate to add your question in the comments or to contact me directly on <a href="https://www.linkedin.com/in/maxime-guilbert-14b6a5128/">LinkedIn</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b48bb72566bc" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/k8s-operator-index-with-name-does-not-exist-b48bb72566bc">K8s Operator — Index with name … does not exist</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Crossplane VS Terraform]]></title>
            <link>https://medium.com/@max.g/crossplane-vs-terraform-6ca8e497b9b5?source=rss-8ee640b430b2------2</link>
            <guid isPermaLink="false">https://medium.com/p/6ca8e497b9b5</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[sre]]></category>
            <dc:creator><![CDATA[Maxime Guilbert]]></dc:creator>
            <pubDate>Mon, 17 Jul 2023 13:02:29 GMT</pubDate>
            <atom:updated>2023-07-17T13:02:29.379Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bdmxVz13hECBLsS-liRPBA.png" /></figure><p>In the last post, we talked about Crossplane and the fact that it can create resources for us in the cloud. Should it replace Terraform? In which case should I use one of them?</p><h3>Automation</h3><p>One strength of Crossplane is <strong>that it’s an operator deployed in a Kubernetes cluster</strong>, so it is always up, checking its resources.</p><p>For example, <strong>if you update some parameters in AWS of a resource managed by Crossplane, Crossplane will update the resource with the parameter values it has</strong>. If you <strong>delete</strong> this resource in AWS, <strong>Crossplane will recreate it</strong>.</p><p>So it’s really helpful to avoid some manual changes or to be sure if some resources are always here.</p><p>The biggest strength of Crossplane is that you can create dynamic resources. As evoked in other posts, with an operator <strong>you can deploy a complete stack with AWS and your Kubernetes cluster by only applying one resource instance!</strong></p><h3>Automation overkill</h3><p>So doing all of this is really cool but <strong>do you really need it?</strong> Having something like this can make your infrastructure very complex!</p><p>If you want to use Crossplane, you <strong>must have a Kubernetes cluster</strong>, so if you haven’t one, may be you should pass this option. Maintaining a Kubernetes cluster can be hard and take a lot of time. Especially if you can do the same automation stuff with <strong>Ansible</strong>.</p><p>Also if you want to use it to create only a resource once and never touch it, it’s also overkill. As it’s an OpenSource project and <strong>it’s still under developments</strong> every features are not available for the moment, especially for High Availability or Disaster Recovery. Things which are possible through Terraform.</p><h3>When use Terraform or Crossplane?</h3><p>Generally it’s recommanded to use Terraform <strong>to generate resources which are here to stay</strong> <em>(a database, a Kubernetes cluster…)</em> or <strong>if you haven’t a Kubernetes cluster</strong>.</p><p>Having a Kubernetes cluster in the cloud can be expensive, so it’s another reason to avoid it just to use Crossplane.</p><p>About Crossplane, it’s better to use it <strong>for dynamic resources</strong> <em>(dynamic deployment of a stack)</em> or <strong>temporary resources</strong>.</p><p>Of course, it’s just recommandations and there’s not only one solution. All depends on your context. But I hope these recommandations will help you to think about what you should use or not.</p><h3>Summary</h3><p>Until now we did saw a lot of things from the concepts to advanced topics. As you can see, Kubernetes operators are a huge subject which <em>(at least)</em> must be known for automation purposes. But don’t fall into something overkill.</p><p>That’s why I wrote this post. Often when posts are made, it’s only to expose a new tool, explain why it’s cool to use it. And there are right, there are a lot of tools which are really good and can do a lot of things for you. But generally, all these tools ask to have some prerequisites which can add more complexity overall. So using good tools is nice, but knowing in which case/context you want to use a tool or another, is better. <em>(It’s only my point of view)</em></p><p>I hope it will help you and if you have any questions <em>(there are not dumb questions)</em> or some points are not clear for you, don’t hesitate to add your question in the comments or to contact me directly on <a href="https://www.linkedin.com/in/maxime-guilbert-14b6a5128/">LinkedIn</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6ca8e497b9b5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Crossplane and operators interactions]]></title>
            <link>https://blog.devgenius.io/crossplane-and-operators-interactions-a5921369f153?source=rss-8ee640b430b2------2</link>
            <guid isPermaLink="false">https://medium.com/p/a5921369f153</guid>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[sre]]></category>
            <dc:creator><![CDATA[Maxime Guilbert]]></dc:creator>
            <pubDate>Mon, 10 Jul 2023 13:02:19 GMT</pubDate>
            <atom:updated>2023-07-11T11:17:46.808Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GcrWUdJZccNYRW39CWz3Vw.png" /></figure><p>In this new post about Kubernetes operators, we will talk about an operator which already exist : <strong>Crossplane</strong>.</p><h3>What is Crossplane?</h3><blockquote><em>Crossplane is a Kubernetes operator which allows you to manage cloud resources from Kubernetes. These cloud resources can come from differents cloud providers like AWS, GCP…</em></blockquote><p>It means that <strong>from your Kubernetes cluster, you can dynamically create resources in a cloud</strong>.</p><p>The following example will create a <strong>S3 bucket in AWS</strong>.</p><pre>apiVersion: s3.aws.upbound.io/v1beta1 <br>kind: Bucket <br>metadata: <br>    generateName: crossplane-bucket- <br>    labels:<br>        docs.crossplane.io/example: provider-aws <br>spec: <br>    forProvider:<br>        region: us-east-2 <br>    providerConfigRef: <br>        name: default</pre><p>This is crazy, isn’t it?</p><h3>How to install Crossplane?</h3><p>If you are interested by using Crossplane on your cluster and using it, you can check the following links where everything is well explained for each cloud provider:</p><ul><li><a href="https://docs.crossplane.io/v1.11/getting-started/provider-aws/"><strong>Setup for AWS</strong></a></li><li><a href="https://docs.crossplane.io/v1.11/getting-started/provider-azure/"><strong>Setup for Azure</strong></a></li><li><a href="https://docs.crossplane.io/v1.11/getting-started/provider-gcp/"><strong>Setup for GCP</strong></a></li></ul><h3>Using Crossplane from another operator!?</h3><p>As we installed Crossplane in our Kubernetes cluster, all its custom resources are now available in the cluster. So <strong>our operator can use them to manage new resource instances</strong>.</p><p>In previous posts of this serie, we mentionned that we can use an operator to manage Grafana, Prometheus, Postgres and OpenTelemetry deployments. With our new context, as the 3 first are available in AWS, it means that <strong>our operator can dynamically create these resources in AWS!</strong></p><blockquote><em>*Note: For all the following examples, I will only talk about AWS but it will be similar for other cloud providers.</em></blockquote><h3>Download libraries</h3><p>The first thing to do in our operator is to <strong>download crossplane librairies</strong>.</p><pre>go install github.com/crossplane-contrib/provider-aws <br>go install github.com/crossplane/crossplane-runtime</pre><p>They will allow us to access to <strong>all the common Crossplane resources</strong> and <strong>all the specific resources for AWS</strong>.</p><h3>Manage schemas</h3><p>In the main.go file, there is a init function that we ignore until now.</p><pre>func init() {  <br>   utilruntime.Must(clientgoscheme.AddToScheme(scheme))  <br>}</pre><p>Declared like this, <strong>it will give access to the operator to all the basic Kubernetes resources</strong> with the method AddToScheme.</p><p>So if we want to be able to use custom resources from Crossplane, we <strong>must add another declaration</strong>.</p><pre>import (<br>    crossplane &quot;github.com/crossplane-contrib/provider-aws/apis&quot;<br>)<br><br>func init() {  <br>    utilruntime.Must(clientgoscheme.AddToScheme(scheme))    <br>    utilruntime.Must(crossplane.AddToScheme(scheme))<br>}</pre><p>Always working with the same pattern, you need to <strong>import the </strong><strong>AddToScheme function of the librairie containing all the resources you want to work with, and all it in the </strong><strong>init function.</strong></p><h3>RBAC</h3><p>It’s something really important to not forget! <strong>Go add all the annotations you need to give the correct rights to your operator on the new resources.</strong></p><h3>Using new resources</h3><p>Now that we have everything setup to be able to use the Crossplane resources from our operator, <strong>we can use them in our Reconcile method!</strong></p><p><em>Example</em></p><pre>import (<br>    &quot;github.com/crossplane-contrib/provider-aws/apis/s3/v1beta1&quot;<br>)<br><br>...<br>myBucket := &amp;v1beta1.Bucket{} // Refers to an AWS S3 Bucket<br>err := r.Get(ctx, req.NamespacedName, myBucket)<br>...</pre><h3>Summary</h3><p>We discovered Crossplane in this post and saw that it’s possible to make interactions between operators.<br>And there are a LOT of operators! <a href="https://operatorhub.io/operator/datadog-operator"><strong>Datadog</strong></a>, <a href="https://operatorhub.io/operator/grafana-operator"><strong>Grafana</strong></a>, <a href="https://operatorhub.io/operator/kong"><strong>Kong</strong></a> or <a href="https://operatorhub.io/operator/litmuschaos"><strong>Litmus Chaos</strong></a> for example.</p><p>Check <a href="https://operatorhub.io/"><strong>Operatorhub.io</strong></a> if you want to find a list of operators.</p><p>Also, with what we saw today, we are now able to create operators like microservices, with each of them have a focused scope and make things easier to develop and scale. So think about all the things which can be done in full automation!</p><p>Talking about automation, in the next post of this serie, we will talk about <strong>Crossplane vs Terraform</strong>.</p><p>I hope it will help you and if you have any questions <em>(there are not dumb questions)</em> or some points are not clear for you, don’t hesitate to add your question in the comments or to contact me directly on <a href="https://www.linkedin.com/in/maxime-guilbert-14b6a5128/">LinkedIn</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a5921369f153" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/crossplane-and-operators-interactions-a5921369f153">Crossplane and operators interactions</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[K8s Operator — Annotations]]></title>
            <link>https://blog.devgenius.io/k8s-operator-annotations-a12c657ebd36?source=rss-8ee640b430b2------2</link>
            <guid isPermaLink="false">https://medium.com/p/a12c657ebd36</guid>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[sre]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Maxime Guilbert]]></dc:creator>
            <pubDate>Mon, 03 Jul 2023 13:02:15 GMT</pubDate>
            <atom:updated>2023-07-04T12:03:32.065Z</atom:updated>
            <content:encoded><![CDATA[<h3>K8s Operator — Annotations</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m4gqrpOhDXAxlMkTUi3q4g.png" /></figure><p>Now that we know how to manage resources status and conditions, it’s time to see <strong>annotations</strong>.</p><p>All the annotations comes from <a href="https://book.kubebuilder.io/"><strong>Kubebuilder</strong></a>.</p><p>There are a lot of different annotations, and we already saw some of them because we defined <strong>RBAC rights for our operator</strong> with annotations.</p><pre>// +kubebuilder:rbac:groups=apps,resources=deployments,verbs=get;list;watch;create;update;patch;delete  <br>// +kubebuilder:rbac:groups=core,resources=services,verbs=get;list;watch;create;update;patch;delete</pre><p>Today, we will see 4 annotations which will help us to be more efficient when using custom resources and/or to debug them.</p><h3>1. Resource</h3><p>This annotation must be <strong>above the resource struct definition</strong>. <em>(in api/…/xxx_types.go)</em></p><p>Composed with 3 major parts, they are used to :</p><ul><li><strong>Define the operator “scope”</strong> <em>(if the operator is Namespace-scope or Cluster-scope)</em></li><li><strong>Define the list of alternate names</strong> that can be used to access the resource <em>(When you do </em><em>kubectl get ...)</em>. Each name must be separated by ;</li><li><strong>Define the singular for the resource name</strong> <em>(Also to use it when you do </em><em>kubectl get ...)</em></li></ul><pre>//+kubebuilder:resource:scope=Cluster,shortName=myproxies;mp,singular=myproxy<br>type MyProxy struct {  <br>   metav1.TypeMeta   `json:&quot;,inline&quot;`  <br>   metav1.ObjectMeta `json:&quot;metadata,omitempty&quot;`  <br>   Spec   MyProxySpec   `json:&quot;spec,omitempty&quot;`  <br>   Status MyProxyStatus `json:&quot;status,omitempty&quot;`  <br>}</pre><h3>2. Printcolumn</h3><p>Having custom resources is good, but being able to display important informations with kubectl get is better!</p><p>Still <strong>above the resource struct definition</strong> <em>(in api/…/xxx_types.go)</em>, you can define custom columns with the following pattern</p><pre>// +kubebuilder:printcolumn:name=&quot;NAME&quot;,type=TYPE,JSONPath=JSONPATH</pre><p><strong>NAME</strong> : The name of the custom column.</p><p><strong>TYPE</strong> : To define the type of data you want to display. <em>(ex: String, number…)</em><br>Check the <a href="https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#data-types"><strong>OpenAPI Specification</strong></a> to know which type can be used.</p><p><strong>JSONPATH</strong> : To define the <strong>JSONPath</strong> to use to access the information <strong>in the custom resource</strong>. If the information isn’t available in the resource, you won’t be able to display it.<br>Check the <a href="https://kubernetes.io/docs/reference/kubectl/jsonpath/"><strong>Kubernetes documentation</strong></a> to know how to write a JSONPath value.</p><p><em>Example</em></p><pre>// +kubebuilder:printcolumn:name=&quot;Name&quot;,type=string,JSONPath=`.spec.name`</pre><p>Here are 3 more specific cases about this annotation!</p><h3>2.1. Priority</h3><p>When we want to get the information of a resource, we can use the option -o wide to get more informations than default.</p><p>To do it with the operator, you just need to add ,priority=10 <em>(or any value strictly greater than 0)</em> in the printcolumn definition of the value you only want to display with the option -o wide.</p><p><em>Example</em></p><pre>// +kubebuilder:printcolumn:name=&quot;Name&quot;,type=string,JSONPath=`.spec.name`,priority=10</pre><h3>2.2. Age</h3><p>By default when you do kubectl get ... on your custom resource, their <strong>age is shown</strong>. But once you&#39;ve <strong>added one printcolumn, the information isn&#39;t displayed anymore</strong>.</p><p>So if you want to keep the information, here is the annotation you must add.</p><pre>// +kubebuilder:printcolumn:name=&quot;Age&quot;,type=date,JSONPath=.metadata.creationTimestamp</pre><h3>2.3. Ready</h3><p>Previously in this serie, we talked about conditions and we said that it can be useful to know if everything goes well. With the following column, we will be able to easily see if everything goes well or not.</p><pre>// +kubebuilder:printcolumn:name=&quot;Ready&quot;,type=string,JSONPath=`.status.conditions[?(@.type==&quot;Ready&quot;)].status`</pre><h3>3. Validation</h3><p>The following annotation simply add <strong>validations on your spec fields</strong>.</p><p>Here are a bunch of them :</p><ul><li><strong>Make mandatory a field</strong> : //+kubebuilder:validation:Required</li><li><strong>Make a field optional</strong> : // +kubebuilder:validation:Optional</li><li><strong>Define the minimum length of a string</strong> : //+kubebuilder:validation:MinLength=8</li><li><strong>Define the maximum length of a string</strong> : //+kubebuilder:validation:MaxLength=20</li><li><strong>Check if the value is contain in a Enum list</strong> : // +kubebuilder:validation:Enum=earth;wind;fire</li><li><strong>Define the minimum number of elements in an array</strong> : //+kubebuilder:validation:MinItems=2</li><li>For a number, <strong>check if the value is a multiple of a particular value</strong> : //+kubebuilder:validation:MultipleOf=15</li></ul><p>There are a lot more, and if you are interested, go check <a href="https://book.kubebuilder.io/reference/markers/crd-validation.html"><strong>the KubeBuilder documentation</strong></a>. But with all these examples, you have a great idea about what can be done or not.</p><h3>4. Default</h3><p>The last annotation we will see today is the one which <strong>defines a default value for a spec field</strong>.</p><p>It can be really useful in case of an optional field..</p><p><em>Examples</em></p><pre>// +kubebuilder:default:=test<br>// +kubebuilder:default:=0</pre><p>Now that you know all of these annotations, you will be able to easily do a lot more with your operator.</p><p>In the next part of this serie, we will leave the tutorial part to talk about an operator which already exists : <strong>Crossplane</strong>!</p><p>I hope it will help you and if you have any questions <em>(there are not dumb questions)</em> or some points are not clear for you, don’t hesitate to add your question in the comments or to contact me directly on <a href="https://www.linkedin.com/in/maxime-guilbert-14b6a5128/">LinkedIn</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a12c657ebd36" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/k8s-operator-annotations-a12c657ebd36">K8s Operator — Annotations</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>