Skip to content

Instantly share code, notes, and snippets.

@figaw
Last active February 11, 2022 23:43
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save figaw/4b6b04ecf4c73bc4b88a09f2e6be9111 to your computer and use it in GitHub Desktop.
Save figaw/4b6b04ecf4c73bc4b88a09f2e6be9111 to your computer and use it in GitHub Desktop.
Setup for labs.play-with-k8s

From 0 to 100 w/ one command and 4ish minutes, in labs.k8s

tl;dr

  1. Click the raw button to get the raw-url of the fig-play-with-k8s.sh-file and, in a VM from labs.play-with-k8s.com,
  2. Run bash -x <( curl -L url-to-raw-gist )
  3. Copy the "blue-port-url" and change http to https
  4. Goto url in Firefox

What happens?

The script will,

  1. Start kubeadm with a dashboard and cluster-admin access from the dashboard
  2. Install helpful tools (code-completion, vim, emacs, tmux, etc. )
  3. Display the kubeadm join-string, to be run on a new instance

Accessing the dashboard

You can now copy the url from the "blue link" in the top, exposing the dashboard on a port, it'll look somewhat like http://ip172-18-0-20-b9q1pplduh0g008cbc3g-30319.direct.labs.play-with-k8s.com/ change the http part to https and access the url from a browser.

NB: I've had problems using Chrome, but Firefox lets me ignore the security issues, and access the dashboard. Clearly it's important to configure security properly, but it's also of negligible importance; I have Firefox installed, this is not a production environment.

But why!?

Because Kubernetes is hard.. and it's nice to get something running quickly and be able to play around with it.. and labs.k8s makes this very easy and fast, but their franela/k8s images are very basic.

More?

Well, I have a tmux config you can also curl onto the machines, to break your fingers a little less. It's located here: gist.github.com/figaw/.tmux.conf

#!/bin/bash -x
## Setup http://labs.play-with-k8s.com/
#
# Inspired heavily by: https://gist.github.com/jjo/78f60702fbfa1cbec7dd865f67a3728a
# Some dev-tools omitted, changes in parenthesis.
#
# Run with:
# bash -x <( curl -L url-to-raw-gist )
#
# Initialize cluster and FIXUP some play-with-k8s annoyances (fixed kube-dashboard shortlink, update port-number)
test -d /etc/kubernetes/pki || (
# run kubeadm
kubeadm init --apiserver-advertise-address $(hostname -i) | tee ~/kubeadm-init.log
# apply weave cni
kubectl apply -n kube-system -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 -w0)"
# apply dashboard
curl -L -s https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml | sed 's/targetPort: 8443/targetPort: 8443\n type: LoadBalancer/' | kubectl apply -f -
# add Google's 8.8.8.8 dns
kubectl get deployment --namespace=kube-system kube-dns -oyaml|sed -r 's,(.*--server)=(/ip6.arpa/.*),&\n\1=8.8.8.8,'|kubectl apply -f -
# add service account to dashboard, from https://gist.github.com/figaw/17dc8ed72c8d2fe1a12682beb9c1e57e
# this gives anyone with access to the dashboard the cluster-admin role.. so.. clearly this is for development.
kubectl create -f https://gist.githubusercontent.com/figaw/17dc8ed72c8d2fe1a12682beb9c1e57e/raw/e2c472cab2aa2ffb410999bcdbd158aa7617d9a3/service-account.yaml
)
# k8s comfy'ness (add emacs)
cd
yum -q -y install bash-completion git-core tmux vim emacs wget sudo which > /dev/null
kubectl completion bash > /etc/bash_completion.d/kubectl.completion
source /etc/bash_completion.d/kubectl.completion
# show kubeadm join ...
echo "* Join nodes with:"
grep -o "kubeadm.*join.*" ~/kubeadm-init.log
# (master shouldn't join
# kubeadm join --token $(kubeadm token list |sed -n 2p|egrep -o '^\S+') $(sed -rn s,.*server:.*//,,p /etc/kubernetes/admin.conf)
@yangshenhuai
Copy link

hi, when i access "blue link" it need a Kubeconfig or Token .

@rahgadda
Copy link

rahgadda commented Jun 17, 2018

I am not able to see "Blue Hyperlink" in the latest version v1.10.2 of Kubernetes Play Groud.
Can you please help
no blue link

@natiki
Copy link

natiki commented Aug 23, 2018

Hi,

image

while I can see the port link I cannot connect to the URL as I get a connection reset with both the http and https versions:

http://ip172-18-0-15-bdva6bg51bg0009g1di0-31867.direct.labs.play-with-k8s.com/

Does this still work with the current version of the playground?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment