Kubernetes in 10 Seconds
Kubernetes in 10 Seconds
September 12, 2019
By Katie McCaskey
2 minute read time
Sonatype's DJ Schleen ( @djschleen) creates a full Kubernetes cluster, installed locally, ready to deploy workloads in less than 10 seconds.
" K3s is a really exciting product," says DJ, "It's minimal, it's small, it installs quick, it can run on a Raspberry PI." He adds: "I wanted to share how quickly a developer can bring up a local development environment where they can experiment, learn, or deploy code for local testing."
"I'm building a workshop which will walk attendees through the process of creating an end-to-end, lightweight DevSecOps pipeline. The environment can be spun up with code in a few minutes. We'll be able to follow an application through the full pipeline lifecycle."
K3s is a Certified Kubernetes Distribution designed to run on resource-constrained devices (such as a Raspberry Pi). It's a great platform for local development and playing with Kubernetes. The distribution removes all alpha features, plugins, legacy code, and more to produce a 40mb binary that can run with only 512mb of memory and 200mb of disk space. It is ideal for anything from a small device to a desktop.
However, DJ cautions: the K3s install uses root access to install and run the cluster. This poses a security risk. It's highly recommended not to pipe downloaded shell scripts to sh or bash especially when running as root. ("Download, review, then use," says DJ.)
There are other alternatives when installing, so it's recommended to read the instructions. Please review the warnings in the GitHub Gist before attempting to run this in your own environment. The target machine for the installer should not be publicly accessible from the Internet.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
| #!/bin/bash | |
| # Kubernetes in 10 seconds (with k3s) | |
| # | |
| # WARNING!!!! | |
| # | |
| # This script uses root account access to install k3s and pipes a downloaded | |
| # to sh. ALWAYS DOWNLOAD SCRIPTS AND REVIEW THE CODE BEFORE CALLING SH. | |
| # Note that no security hardening has been done. Please run this in a contained | |
| # environment without incoming access from the internet. For alternative methods | |
| # to install k3s head to https://k3s.io | |
| # | |
| # Destroy the cluster with the k3s-uninstall command when done and your machine | |
| # will return to its prior state. | |
| sudo su | |
| echo "Starting k3s installation @ $(date)" # install k3s | |
| curl -sfL https://get.k3s.io | sh - | |
| # download the kubernetes-dashboard-yaml | |
| curl -sfL https://raw.githubusercontent.com/kubernetes/dashboard/v1.10.1/src/deploy/recommended/kubernetes-dashboard.yaml > kubernetes-dashboard.yaml | |
| #k3s will pick this up and install | |
| cp kubernetes-dashboard.yaml /var/lib/rancher/k3s/server/manifests | |
| #verify | |
| kubectl get services --namespace kube-system | |
| kubectl get ns | |
| echo "Finished k3s installation @ $(date)" |