<?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: Alex Robson</title>
    <description>The latest articles on DEV Community by Alex Robson (@arobson).</description>
    <link>https://dev.to/arobson</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%2Fuser%2Fprofile_image%2F1006603%2F44d9dd0e-a518-4164-bb2d-8c9522a098c8.jpeg</url>
      <title>DEV Community: Alex Robson</title>
      <link>https://dev.to/arobson</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/arobson"/>
    <language>en</language>
    <item>
      <title>Local Kubernetes - Adding An Ingress Controller</title>
      <dc:creator>Alex Robson</dc:creator>
      <pubDate>Tue, 17 Jan 2023 09:25:31 +0000</pubDate>
      <link>https://dev.to/arobson/local-kubernetes-adding-an-ingress-controller-4hj0</link>
      <guid>https://dev.to/arobson/local-kubernetes-adding-an-ingress-controller-4hj0</guid>
      <description>&lt;h2&gt;
  
  
  Previous Posts in This Series
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://dev.to/arobson/installing-a-local-kubernetes-2igp"&gt;Installing A Local Kubernetes&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/arobson/local-kubernetes-rbac-dashboard-setup-1keh"&gt;Local Kubernetes RBAC &amp;amp; Dashboard Setup&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  A Brief Explanation of Kubernetes Networking
&lt;/h2&gt;

&lt;p&gt;Unlike running Docker containers with ports bound to a host port, Kubernetes does not expose container ports or assign them an IP address. Kubernetes has a &lt;code&gt;service&lt;/code&gt; resource that exposes ports in a POD to a named endpoint and port.&lt;/p&gt;

&lt;p&gt;A service provides a predictable way to access containers via the internal cluster network. The container will only be reachable from within the cluster through the service.&lt;/p&gt;

&lt;p&gt;In the last post, we used &lt;code&gt;m8s dashboard-proxy&lt;/code&gt; to make the &lt;code&gt;kubernetes-dashboard&lt;/code&gt; service accessible outside the cluster.&lt;/p&gt;

&lt;p&gt;To see the manifest of the &lt;code&gt;kubernetes-dashboard&lt;/code&gt; service, issue the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;k8s get service &lt;span class="nt"&gt;-n&lt;/span&gt; kube-system kubernetes-dashboard &lt;span class="nt"&gt;-o&lt;/span&gt; yaml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Note: The service binds the &lt;code&gt;port&lt;/code&gt; for this named service to the &lt;code&gt;targetPort&lt;/code&gt; on the Pod. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;To display the manifest for the dashboard pod, issue the command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;k8s describe pod &lt;span class="nt"&gt;-n&lt;/span&gt; kube-system kubernetes-dashboard
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Look for the &lt;code&gt;ports&lt;/code&gt; collection inside the container spec for &lt;code&gt;kubernetes-dashboard&lt;/code&gt; to see the port setting &lt;code&gt;8443/TCP&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Enabling DNS
&lt;/h2&gt;

&lt;p&gt;Kubernetes' DNS provides service discovery, a valuable feature when containers can disappear or get added, resulting in a shifting set of IP addresses. &lt;/p&gt;

&lt;p&gt;To add DNS, type:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;m8s &lt;span class="nb"&gt;enable &lt;/span&gt;dns
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Editing The Dashboard's Deployment and Service
&lt;/h2&gt;

&lt;p&gt;For safety, the dashboard is secure by default and allows HTTPS only through a certificate it creates. I want to demonstrate how to host the dashboard through the ingress controller through port 80. In a future post, we'll secure this with SSL termination on the ingress controller.&lt;/p&gt;

&lt;p&gt;The dashboard will require changes to host HTTP traffic and updating the service to bind to a different target port.&lt;/p&gt;

&lt;h3&gt;
  
  
  Changing The Deployment
&lt;/h3&gt;

&lt;p&gt;To fetch the current deployment manifest for the dashboard, use the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;k8s get deployment &lt;span class="nt"&gt;-n&lt;/span&gt; kube-system kubernetes-dashboard &lt;span class="nt"&gt;-o&lt;/span&gt; yaml &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; dashboard-deployment.yml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Open your favorite editor and follow each set of directions.&lt;/p&gt;

&lt;h4&gt;
  
  
  Enable Insecure Login
&lt;/h4&gt;

&lt;p&gt;Change &lt;code&gt;--auto-generate-certificates&lt;/code&gt; to &lt;code&gt;--enable-insecure-login&lt;/code&gt; to forgo generating self-signed certificates and bind the dashboard process to port &lt;code&gt;9090&lt;/code&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  Change 8443 to 9090
&lt;/h4&gt;

&lt;p&gt;We need to change the port the container will expose to &lt;code&gt;9090&lt;/code&gt; from &lt;code&gt;8443&lt;/code&gt; under the &lt;code&gt;ports&lt;/code&gt; section.&lt;/p&gt;

&lt;h4&gt;
  
  
  Update the Liveness Probe
&lt;/h4&gt;

&lt;p&gt;Edit the liveness probe section by changing the &lt;code&gt;httpGet&lt;/code&gt;'s port to &lt;code&gt;9090&lt;/code&gt; and the &lt;code&gt;scheme&lt;/code&gt; to &lt;code&gt;HTTP&lt;/code&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  Apply the Changes
&lt;/h4&gt;

&lt;p&gt;Save the changes you made to the file and apply our changes to the deployment; issue the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;k8s apply &lt;span class="nt"&gt;-f&lt;/span&gt; ./dashboard-deployment.yml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Changing The Service
&lt;/h3&gt;

&lt;p&gt;Now that our dashboard deployment is bound to port 9090, we need to update our service. To fetch the service manifest, type:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;k8s get service &lt;span class="nt"&gt;-n&lt;/span&gt; kube-system kubernetes-dashboard &lt;span class="nt"&gt;-o&lt;/span&gt; yaml &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; dashboard-service.yml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Change The Ports
&lt;/h4&gt;

&lt;p&gt;We'll change the &lt;code&gt;port&lt;/code&gt; from &lt;code&gt;443&lt;/code&gt; to &lt;code&gt;80&lt;/code&gt; and &lt;code&gt;targetPort&lt;/code&gt; from &lt;code&gt;8443&lt;/code&gt; to &lt;code&gt;9090&lt;/code&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  Apply the Changes
&lt;/h4&gt;

&lt;p&gt;Save your changes and update the service as we did with the deployment with the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;k8s apply &lt;span class="nt"&gt;-f&lt;/span&gt; ./dashboard-service.yml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Adding the NGINX Ingress Controller
&lt;/h2&gt;

&lt;p&gt;An Ingress Controller is how Kubernetes accepts incoming HTTP requests through a fixed set of IPs and directs them to the correct backing Pods/Containers based on configuration.&lt;/p&gt;

&lt;p&gt;To install the NGINX Ingress Controller from Kubernetes, we can enable the add-on as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;microk8s &lt;span class="nb"&gt;enable &lt;/span&gt;ingress
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Creating Ingress for The Dashboard
&lt;/h3&gt;

&lt;p&gt;Save the following YAML for the manifest in a file &lt;code&gt;http-dashboard-ingress.yml&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;apiVersion&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;networking.k8s.io/v1&lt;/span&gt;
&lt;span class="na"&gt;kind&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Ingress&lt;/span&gt;
&lt;span class="na"&gt;metadata&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;http-ingress&lt;/span&gt;
  &lt;span class="na"&gt;namespace&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;kube-system&lt;/span&gt;
  &lt;span class="na"&gt;annotations&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;nginx.ingress.kubernetes.io/use-regex&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;true"&lt;/span&gt;
    &lt;span class="na"&gt;nginx.ingress.kubernetes.io/rewrite-target&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;/$2&lt;/span&gt;    
&lt;span class="na"&gt;spec&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;rules&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;http&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;paths&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;/dash(/|$)(.*)&lt;/span&gt;
        &lt;span class="na"&gt;pathType&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Prefix&lt;/span&gt;
        &lt;span class="na"&gt;backend&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;service&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
            &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;kubernetes-dashboard&lt;/span&gt;
            &lt;span class="na"&gt;port&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
              &lt;span class="na"&gt;number&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;80&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From your shell, the following command will cause the ingress controller to update the NGINX configuration.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;k8s create &lt;span class="nt"&gt;-f&lt;/span&gt; ./http-dashboard-ingress.yml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The new NGINX configuration forwards all requests to port 80 to the dashboard container.&lt;/p&gt;

&lt;h3&gt;
  
  
  Finding The Cluster IP
&lt;/h3&gt;

&lt;p&gt;To access the dashboard, we'll need the IP address of the cluster. The endpoint slice named &lt;code&gt;kubernetes&lt;/code&gt; should resolve to the Ingress controller. Fetch the list of endpoint slices with the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;k8s get endpointslices
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Accessing The Dashboard
&lt;/h2&gt;

&lt;p&gt;The dashboard should now be accessible via port 80 at the URL &lt;code&gt;/dash/&lt;/code&gt;. The dashboard should display a notification in red at the bottom notifying you that authentication is disabled since you're accessing it via an unsecured (HTTP) connection through an IP other than &lt;code&gt;localhost&lt;/code&gt; or &lt;code&gt;127.0.0.1&lt;/code&gt;.&lt;/p&gt;

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

&lt;p&gt;The proxy built into microk8s is not compatible with the changes made to the dashboard deployment. The &lt;code&gt;port-forward&lt;/code&gt; feature in Kubernetes creates a tunnel from a specified resource to the localhost.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;k8s &lt;span class="nt"&gt;-n&lt;/span&gt; ingress port-forward service/ingress 8008:80
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now the dashboard can be accessed &lt;code&gt;http://localhost:8008/dash/&lt;/code&gt; and will accept authentication.&lt;/p&gt;

&lt;h2&gt;
  
  
  Up Next
&lt;/h2&gt;

&lt;p&gt;In the next post, I'll look at options for SSL termination.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://kubernetes.io/docs/concepts/services-networking/service/" rel="noopener noreferrer"&gt;Kubernetes Services&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://microk8s.io/docs/addon-ingress" rel="noopener noreferrer"&gt;Microk8s Addon: Ingress&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/kubernetes/ingress-nginx" rel="noopener noreferrer"&gt;NGINX Ingress Controller&lt;/a&gt;&lt;/p&gt;

</description>
      <category>socialmedia</category>
    </item>
    <item>
      <title>Local Kubernetes RBAC &amp; Dashboard Setup</title>
      <dc:creator>Alex Robson</dc:creator>
      <pubDate>Tue, 17 Jan 2023 04:00:28 +0000</pubDate>
      <link>https://dev.to/arobson/local-kubernetes-rbac-dashboard-setup-1keh</link>
      <guid>https://dev.to/arobson/local-kubernetes-rbac-dashboard-setup-1keh</guid>
      <description>&lt;p&gt;In my previous post, I showed how anyone could install a Kubernetes cluster locally using Canonical's &lt;a href="https://microk8s.io"&gt;microk8s&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;This post picks up where the last ended. Before I start looking at deploying software to my local cluster, I need to do some additional configuration.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Note: I've aliased &lt;code&gt;microk8s&lt;/code&gt; as &lt;code&gt;m8s&lt;/code&gt; and &lt;code&gt;microk8s kubectl&lt;/code&gt; as &lt;code&gt;k8s&lt;/code&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Kubernetes Dashboard
&lt;/h2&gt;

&lt;p&gt;The Kubernetes Dashboard is a web interface that makes discovery and simple observability straightforward. microk8s provides a dashboard package that you can install with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;m8s &lt;span class="nb"&gt;enable &lt;/span&gt;dashboard
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To view the dashboard, use the dashboard proxy command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;m8s dashboard-proxy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To open the dashboard, ctrl+click the URL in the console. Bypass your browser's complaint that the certificate is invalid*, copy the token at the end of the output, and use that to authenticate when prompted in the browser.&lt;/p&gt;

&lt;h2&gt;
  
  
  Role-Based Authentication Control (RBAC)
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What is it?
&lt;/h3&gt;

&lt;p&gt;Though Kubernetes is usable without it, RBAC allows you to practice good security hygiene and work in an environment closer to production clusters.&lt;/p&gt;

&lt;p&gt;If you're not familiar, RBAC consists of the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;service accounts&lt;/li&gt;
&lt;li&gt;roles&lt;/li&gt;
&lt;li&gt;role bindings&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Since you can bind multiple roles to a service account, this is a very flexible way to add or remove sets of permissions to an account.&lt;/p&gt;

&lt;h3&gt;
  
  
  Enabling RBAC
&lt;/h3&gt;

&lt;p&gt;Enabling RBAC is simple:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;microk8s &lt;span class="nb"&gt;enable &lt;/span&gt;rbac
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Fixing The Dashboard Account's Permissions
&lt;/h3&gt;

&lt;p&gt;Installing RBAC and the dashboard will create a service account for &lt;code&gt;kubernetes-dashboard&lt;/code&gt;. To see a list of service accounts that includes this new account, issue:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;k8s get sa &lt;span class="nt"&gt;-n&lt;/span&gt; kube-system
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To see the other RBAC resources created for us to make the dashboard accessible, issue the following:&lt;/p&gt;

&lt;h4&gt;
  
  
  Lists Cluster Roles
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;k8s get clusterroles &lt;span class="nt"&gt;-n&lt;/span&gt; kube-system | &lt;span class="nb"&gt;grep &lt;/span&gt;dashboard
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Lists Role Bindings
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;k8s get clusterrolebindings &lt;span class="nt"&gt;-n&lt;/span&gt; kube-system | &lt;span class="nb"&gt;grep &lt;/span&gt;dashboard
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Unfortunately, the permissions granted to the &lt;code&gt;kubernetes-dashboard&lt;/code&gt; account through the cluster role &lt;code&gt;kubernetes-dashboard&lt;/code&gt; are so restrictive that we won't get much visibility into what's already there.&lt;/p&gt;

&lt;p&gt;Rather than dive into the specifics of each manifest, I've put a new clusterrole, clusterrole-binding, and token file into a gist you can use to:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a new cluster role named &lt;code&gt;kubernetes-dashboard-readonly&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Create a cluster role binding named &lt;code&gt;kubernetes-dashboard-readonly&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Create an authentication token for the &lt;code&gt;kubernetes-dashboard&lt;/code&gt; account&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Save the contents of the &lt;a href="https://gist.github.com/arobson/2d87bd963c904960f4d632dcba875eb1"&gt;gist&lt;/a&gt; to &lt;code&gt;./read-only-dashboard.yml&lt;/code&gt; and then run the command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;k8s create &lt;span class="nt"&gt;-f&lt;/span&gt; ./read-only-dashboard.yml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To retrieve the token for login with the &lt;code&gt;kubernetes-dashboard&lt;/code&gt; use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;k8s describe secrets &lt;span class="nt"&gt;-n&lt;/span&gt; kube-system kubernetes-dashboard-token
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Copy the value following &lt;code&gt;token&lt;/code&gt; and use this to log into the dashboard. The first sign of success is that the namespaces drop-down in the top bar has more than &lt;code&gt;default&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Help With Custom Roles
&lt;/h3&gt;

&lt;p&gt;Finding a list of the available API groups and their related resources with their allowed verbs has been a headache. There is a built-in command that will provide a tab-delimited table:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;k8s api-resources &lt;span class="nt"&gt;-o&lt;/span&gt; wide
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To make this easier to consume (for myself), I put this in a Google Sheet and sorted it by the API Group and Resource Name columns. You can &lt;a href="https://docs.google.com/spreadsheets/d/1aEkHUhIu5fXsKnOX6sVaC5zc8Zqm4l6wxhGQsZNxtpM/edit#gid=0"&gt;view it here&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Up Next
&lt;/h2&gt;

&lt;p&gt;In my next post, I plan to add the Kubernetes Ingress NGINX Controller and demonstrate how this creates a reverse proxy and load balancer for services we may want to expose outside the cluster.&lt;/p&gt;

&lt;h2&gt;
  
  
  *Known Issues With Self-Signed Certificate
&lt;/h2&gt;

&lt;p&gt;Following these directions on a machine that does not allow you to proceed to an HTTPS URL with a self-signed certificate will prevent you from viewing the dashboard.&lt;/p&gt;

&lt;p&gt;In the next post, I'll look at ways to get a valid certificate for an ingress controller.&lt;/p&gt;

&lt;h2&gt;
  
  
  Resources
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://gist.github.com/arobson/2d87bd963c904960f4d632dcba875eb1"&gt;Gist: Read-only Dashboard Role&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://docs.google.com/spreadsheets/d/1aEkHUhIu5fXsKnOX6sVaC5zc8Zqm4l6wxhGQsZNxtpM"&gt;Kubernetes API Groups and Resources&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Further Reading
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://kubernetes.io/docs/reference/access-authn-authz/rbac/"&gt;Using RBAC Authorization&lt;/a&gt;&lt;/p&gt;

</description>
      <category>kubernetes</category>
      <category>beginners</category>
      <category>devops</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Installing A Local Kubernetes</title>
      <dc:creator>Alex Robson</dc:creator>
      <pubDate>Mon, 16 Jan 2023 01:18:35 +0000</pubDate>
      <link>https://dev.to/arobson/installing-a-local-kubernetes-2igp</link>
      <guid>https://dev.to/arobson/installing-a-local-kubernetes-2igp</guid>
      <description>&lt;h2&gt;
  
  
  Why
&lt;/h2&gt;

&lt;p&gt;There are good reasons to follow along and get a local Kubernetes cluster: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;learn more about containers and orchestration&lt;/li&gt;
&lt;li&gt;experimentation is a great way to learn&lt;/li&gt;
&lt;li&gt;gain new skills and understanding&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I will be writing more about CI/CD tooling that targets Kubernetes, and starting with documenting how I created my local cluster makes what I'm writing about easier for others to reproduce.&lt;/p&gt;

&lt;h2&gt;
  
  
  What's Kubernetes?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://kubernetes.io/" rel="noopener noreferrer"&gt;Kubernetes&lt;/a&gt; is an Open Source container orchestration system. Kubernetes' API provides a uniform control layer for managing containerized services. There is a lot of great material available that explains what Kubernetes is. See &lt;code&gt;Further Reading&lt;/code&gt; at the end for some suggestions.&lt;/p&gt;

&lt;p&gt;After five years managing physical servers, then another four years working with VM clusters, the value of &lt;a href="https://linuxcontainers.org/" rel="noopener noreferrer"&gt;Linux Containers&lt;/a&gt;(LXC) and their eventual productization as Docker appealed to me.&lt;/p&gt;

&lt;p&gt;Three years of creating and evolving internal tooling to manage hosting and configuration of Dockerized microservices ended when I discovered Kubernetes in the fall of 2016.&lt;/p&gt;

&lt;p&gt;At that time, I migrated a pricy Heroku deployment to a self-managed Kubernetes cluster in AWS that expanded our capabilities, reduced maintenance efforts, increased capacity, and slashed our hosting costs by more than half.&lt;/p&gt;

&lt;h2&gt;
  
  
  How
&lt;/h2&gt;

&lt;p&gt;Today there are quite a few ways to get a Kubernetes experience on a local machine. Here are a few that I'm most familiar with and have tried at one point or another:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://www.docker.com/products/kubernetes/" rel="noopener noreferrer"&gt;Docker for Desktop&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="//microk8s.io"&gt;microk8s&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://minikube.sigs.k8s.io/docs/start/" rel="noopener noreferrer"&gt;minikube&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://k3s.io/" rel="noopener noreferrer"&gt;k3s&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  microk8s
&lt;/h3&gt;

&lt;p&gt;microk8s is Canonical's packaged Kubernetes cluster purpose-built for more straightforward installs. Like Rancher Lab's k3s, Canonical built microk8s for local development, edge computing, and IoT applications.&lt;/p&gt;

&lt;h2&gt;
  
  
  My Environment
&lt;/h2&gt;

&lt;p&gt;For this post, I chose my Windows desktop running the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Windows 10.0.19044.2364&lt;/li&gt;
&lt;li&gt;WSL2 1.0.3.0&lt;/li&gt;
&lt;li&gt;Debian GNU/Linux 11 (bullseye)&lt;/li&gt;
&lt;li&gt;Kernel Linux 5.15.79.1-microsoft-standard-WSL2&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Some of the steps I share are specific to my environment. You may have to adjust the approach to work for you if you're running a different Linux distribution or version.&lt;/p&gt;

&lt;h3&gt;
  
  
  Prerequisites
&lt;/h3&gt;

&lt;p&gt;My WSL Debian container required two changes before I could install microk8s. I needed to enable systemd and install Canonical's Snap package manager.&lt;/p&gt;

&lt;h4&gt;
  
  
  Enable systemd
&lt;/h4&gt;

&lt;p&gt;You can enable systemd by creating (or adding to) the file &lt;code&gt;/etc/wsl.conf&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;[&lt;/span&gt;boot]
&lt;span class="nv"&gt;systemd&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You'll need to restart WSL after this:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Close your WSL terminal window&lt;/li&gt;
&lt;li&gt;Run &lt;code&gt;wsl.exe --shutdown&lt;/code&gt; from a PowerShell terminal&lt;/li&gt;
&lt;li&gt;Re-open your WSL terminal window&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Install Snap
&lt;/h4&gt;

&lt;p&gt;Now that systemd is up, install Snap with the following set of commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt update
&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;snapd
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Get microk8s
&lt;/h3&gt;

&lt;p&gt;To install microk8s:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;snap &lt;span class="nb"&gt;install &lt;/span&gt;microk8s &lt;span class="nt"&gt;--classic&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  System Setup
&lt;/h3&gt;

&lt;p&gt;I use zsh, so I needed to:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;add Snap's bin folder to my path&lt;/li&gt;
&lt;li&gt;add an alias for microk8s. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I edited my &lt;code&gt;~/.zshrc&lt;/code&gt; file to source the alias file and add Snap's bin folder to my path:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;source&lt;/span&gt; ~/.zsh_aliases
&lt;span class="nv"&gt;PATH&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$PATH&lt;/span&gt;:/snap/bin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I created an alias file &lt;code&gt;~/.zsh_aliases&lt;/code&gt; and added the contents:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;alias &lt;/span&gt;m8s&lt;span class="s1"&gt;'microk8s'&lt;/span&gt;
&lt;span class="nb"&gt;alias &lt;/span&gt;&lt;span class="nv"&gt;k8s&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'m8s kubectl'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally, I sourced my changes back into the current console session with the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;source&lt;/span&gt; ~/.zshrc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To verify everything is working, issue the command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;k8s get nodes
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You should see something like the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;NAME            STATUS   ROLES    AGE   VERSION
computer-name   Ready    &amp;lt;none&amp;gt;   9h    v1.26.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Up Next
&lt;/h2&gt;

&lt;p&gt;Now that I have a working cluster, the next thing I'll write about is to add some essential features like role based authentication (RBAC) and a dashboard.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://ubuntu.com/blog/kubernetes-on-windows-with-microk8s-and-wsl-2" rel="noopener noreferrer"&gt;Kubernetes on Windows with microk8s and wsl2&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.xda-developers.com/how-enable-systemd-in-wsl/" rel="noopener noreferrer"&gt;How To Enable systemd in WSL&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://snapcraft.io/docs/installing-snap-on-debian" rel="noopener noreferrer"&gt;Installing Snap on Debian&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Further Reading
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://cloud.google.com/kubernetes-engine/kubernetes-comic" rel="noopener noreferrer"&gt;Smooth Sailing with Kubernetes&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.cncf.io/phippy/the-childrens-illustrated-guide-to-kubernetes/" rel="noopener noreferrer"&gt;The Illustrated Children's Guide to Kubernetes&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.vmware.com/topics/glossary/content/kubernetes-architecture.html#:~:text=Kubernetes%20is%20an%20architecture%20that,one%20or%20more%20compute%20nodes." rel="noopener noreferrer"&gt;What is Kubernetes Architecture?&lt;/a&gt;&lt;/p&gt;

</description>
      <category>gratitude</category>
    </item>
  </channel>
</rss>
