{"id":3105,"date":"2022-09-23T09:42:27","date_gmt":"2022-09-23T13:42:27","guid":{"rendered":"https:\/\/dft.wiki\/?p=3105"},"modified":"2026-04-21T13:36:49","modified_gmt":"2026-04-21T17:36:49","slug":"running-k3s-kubernetes-locally-on-ubuntu-22-04","status":"publish","type":"post","link":"https:\/\/dft.wiki\/?p=3105","title":{"rendered":"Running K3s (Kubernetes) Locally on Ubuntu"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-4095 size-medium\" src=\"https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2022\/09\/K3s-300x118.png\" alt=\"\" width=\"300\" height=\"118\" srcset=\"https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2022\/09\/K3s-300x118.png 300w, https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2022\/09\/K3s.png 565w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n<p><strong>K3s<\/strong> is a free and open-source [<a href=\"https:\/\/github.com\/k3s-io\/k3s\/\">Link<\/a>] fully certified Kubernetes-compliant distribution [<a href=\"https:\/\/k3s.io\/\">Link<\/a>].<\/p>\n<p>It is offers a simplified Kubernetes deployments and a lightweight single binary (~45MB) that implements Kubernetes APIs.<\/p>\n<p>Popular features of the K3s are:<\/p>\n<ul>\n<li>Lightweight (consumes less then 512 MB of RAM),<\/li>\n<li>Full ARM architecture support (e.g. Raspberry Pi),<\/li>\n<li>Multi-node or single-node cluster,<\/li>\n<li>Edge computing and Production ready!<\/li>\n<\/ul>\n<hr \/>\n<p><strong>INSTALLATION<\/strong><\/p>\n<p>Easiest way (takes few seconds and no interaction):<\/p>\n<pre>curl -sfL https:\/\/get.k3s.io | sh -<\/pre>\n<p>Issue the following command to allow any user to issue command to K3s without <strong>sudo<\/strong>. <span style=\"text-decoration: underline;\">It is not recommended to production, just for test environments.<\/span><\/p>\n<pre>sudo chmod 777 \/etc\/rancher\/k3s\/k3s.yaml<\/pre>\n<p>Check the newly deployed nodes:<\/p>\n<pre>k3s kubectl get nodes<\/pre>\n<p>Deploy a test application:<\/p>\n<pre>k3s kubectl create deployment hello-node --image=registry.k8s.io\/echoserver:1.4<\/pre>\n<p>Check the deployment and its pods (objects):<\/p>\n<pre>k3s kubectl get deployments\r\nk3s kubectl get pods<\/pre>\n<p>Copy the configuration that kubectl uses to interact with the server to another machine on the network to manage it remotely:<\/p>\n<pre>scp \/etc\/rancher\/k3s\/k3s.yaml <strong>userName<\/strong>@<strong>10.10.10.10:.<\/strong><\/pre>\n<p><strong>Note:<\/strong> replace the username and IP accordingly to the destination machine where you want to remotely access the K3s from.<\/p>\n<hr \/>\n<p><strong>JOINING AGENTS TO THE CLUSTER<\/strong><\/p>\n<p>Copy the token that authorizes Agents to join the server:<\/p>\n<pre>cat \/var\/lib\/rancher\/k3s\/server\/node-token<\/pre>\n<p>Then, define environment variables on the server that will be configured as a new Agent to the cluster:<\/p>\n<pre>export K3S_TOKEN=<strong>&lt;paste the node-token here&gt;<\/strong>\r\nexport K3S_TOKEN=https:\/\/<strong>10.10.10.1<\/strong>:6443<\/pre>\n<p><strong>Note:<\/strong> replace the commands above with the node token acquired on the first command and the IP address where the K3S server is installed.<\/p>\n<hr \/>\n<p><strong>CONFIGURING AND ACCESSING THE DASHBOARD<\/strong><\/p>\n<p>Deploy the dashboard [<a href=\"https:\/\/github.com\/kubernetes\/dashboard\">Link<\/a>].<\/p>\n<pre>GITHUB_URL=https:\/\/github.com\/kubernetes\/dashboard\/releases\r\nVERSION_KUBE_DASHBOARD=$(curl -w '%{url_effective}' -I -L -s -S ${GITHUB_URL}\/latest -o \/dev\/null | sed -e 's|.*\/||')\r\nk3s kubectl create -f https:\/\/raw.githubusercontent.com\/kubernetes\/dashboard\/${VERSION_KUBE_DASHBOARD}\/aio\/deploy\/recommended.yaml<\/pre>\n<p>Create the admin Service Account:<\/p>\n<pre>nano dashboard.admin-user.yml<\/pre>\n<pre>apiVersion: v1\r\nkind: ServiceAccount\r\nmetadata:\r\nname: admin-user\r\nnamespace: kubernetes-dashboard<\/pre>\n<p>Create the RBAC (Role-based access control) for the admin Service Account:<\/p>\n<pre>nano dashboard.admin-user-role.yml<\/pre>\n<pre>apiVersion: rbac.authorization.k8s.io\/v1\r\nkind: ClusterRoleBinding\r\nmetadata:\r\nname: admin-user\r\nroleRef:\r\napiGroup: rbac.authorization.k8s.io\r\nkind: ClusterRole\r\nname: cluster-admin\r\nsubjects:\r\n- kind: ServiceAccount\r\nname: admin-user\r\nnamespace: kubernetes-dashboard<\/pre>\n<p>Deploy both:<\/p>\n<pre>k3s kubectl create -f dashboard.admin-user.yml -f dashboard.admin-user-role.yml<\/pre>\n<p>Get the token for the admin:<\/p>\n<pre>k3s kubectl -n kubernetes-dashboard create token admin-user<\/pre>\n<p>Start the proxy:<\/p>\n<pre>k3s kubectl proxy<\/pre>\n<p><strong>Note:<\/strong> the proxy is enabled but cannot be reached from outside the server. Do not try to bind the proxy on 0.0.0.0 because the latest version of the dash board will not allow admin access from outside localhost if not under HTTPS. To work around this and securely connect to the server estabilsh a SSH tunnel as follows.<\/p>\n<p>Establishing an SSH tunnel to the proxy that serves the dashboard.<\/p>\n<pre>ssh 190.10.10.1 -L 8001:localhost:8001 -N<\/pre>\n<p>Now, with the proxy started and the SSH tunnel listening on local host and port forwarding the traffic to the remote server on the same port, navigate to <strong>http:\/\/localhost:8001\/api\/v1\/namespaces\/kubernetes-dashboard\/services\/https:kubernetes-dashboard:\/proxy\/<\/strong><\/p>\n<hr \/>\n<p><strong>OTHER POSTS<\/strong><\/p>\n<p><strong>Minikube<\/strong> on Ubuntu 22.04 [<a href=\"https:\/\/dft.wiki\/?p=3087\">Link<\/a>].<\/p>\n<p><strong>MicroK8s<\/strong> on Ubuntu 22.04 [<a href=\"https:\/\/dft.wiki\/?p=3151\">Link<\/a>].<\/p>\n<p><strong>K8s<\/strong> Persistent Volumes [<a href=\"https:\/\/dft.wiki\/?p=1435\">Link<\/a>].<\/p>\n<p><strong>K8s<\/strong> Cheat Sheet [<a href=\"https:\/\/dft.wiki\/?p=1372\">Link<\/a>].<\/p>\n<p><strong>K8s<\/strong> Dashboard [<a href=\"https:\/\/dft.wiki\/?p=4114\">Link<\/a>].<\/p>\n","protected":false},"excerpt":{"rendered":"<p>K3s is a free and open-source [Link] fully certified Kubernetes-compliant distribution [Link]. It is offers [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-3105","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts\/3105","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dft.wiki\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3105"}],"version-history":[{"count":8,"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts\/3105\/revisions"}],"predecessor-version":[{"id":5501,"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts\/3105\/revisions\/5501"}],"wp:attachment":[{"href":"https:\/\/dft.wiki\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3105"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dft.wiki\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3105"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dft.wiki\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3105"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}