Orchestrating Containers
Kubernetes - Learning ContinuesEueung Mulyana
http://eueung.github.io/docker-stuff/learning-k8sCodeLabs | Attribution-ShareAlike CC BY-SA
1 / 37
Outline
Base Setup & OS Con�g
k8s Addons - DNS & Dashboard
Remote Master & k8s Visualizer
Test It All
2 / 37
5 / 37
HypriotOS0.8.0
$ flash -d /dev/mmcblk0 hypriotos-rpi-v0.8.0.img$ flash -d /dev/mmcblk0 hypriotos-rpi-v0.8.0.img
$ ssh-keygen -f "/home/em/.ssh/known_hosts" -R black-pearl.local$ ssh [email protected]# pirate/hypriot
$ sudo nano /etc/network/interfaces.d/eth0$ sudo nano /etc/hosts$ sudo nano /etc/hostname
# ---$ sudo nano /boot/device-init.yaml
# hostname for your HypriotOS devicehostname: node2 docker: images: - "/var/local/rpi-consul_v0.6.4.tar.gz" - "/var/local/rpi-swarm_v1.2.2.tar.gz"clusterlab: service: run_on_boot: "false"
# optional wireless network settingswifi: interfaces:# wlan0:# ssid: "MyNetwork"# password: "secret_password"
6 / 37
HypriotOS0.8.0
$ sudo su$ mount -o remount,rw /sys/fs/cgroup$ mkdir /sys/fs/cgroup/cpuset$ nano /boot/cmdline.txt# edit: cgroup_enable=cpuset #---$ nano /etc/resolv.confsearch default.svc.cluster.local svc.cluster.local cluster.localnameserver 10.0.0.10nameserver 192.168.1.1
#---# optional tools$ apt-get install dnsutils zip
$ shutdown -r now#---
$ ssh-keygen -R 192.168.1.101 && ssh-keygen -R node2.local$ ssh-copy-id -oStrictHostKeyChecking=no -oCheckHostIP=no pirate@
$ sftp [email protected]# put images...# put kube-systemd...
7 / 37
kubernetes-on-arm v0.7.0
$ dpkg -i kube-systemd.deb$ kube-config install #rpi or rpi-2, hypriotos
$ gzip -dc images.tar.gz | docker load$ kube-config info
$ kube-config enable-master$ kube-config enable-worker 192.168.1.102
$ sudo kube-config enable-addon dashboard$ sudo kube-config enable-addon dnsnamespace "kube-system" createdWarning: Unit file of networking.service changed on disk, 'systemctl daemon-reload' recommended.replicationcontroller "kube-dns-v8" createdservice "kube-dns" createdStarted addon: dns
$ kubectl cluster-infoKubernetes master is running at http://localhost:8080KubeDNS is running at http://localhost:8080/api/v1/proxy/namespaces/kube-system/services/kube-dnsDashboard is running at http://localhost:8080/api/v1/proxy/namespaces/kube-system/services/kubernetes-dashboard
$ kubectl --namespace=kube-system get pods,rc,svcNAME READY STATUS RESTARTS AGEkube-dns-v8-uv6r5 4/4 Running 0 1hkubernetes-dashboard-h5g84 1/1 Running 0 1hNAME DESIRED CURRENT AGEkube-dns-v8 1 1 22hkubernetes-dashboard 1 1 22hNAME CLUSTER-IP EXTERNAL-IP PORT(S) AGEkube-dns 10.0.0.10 <none> 53/UDP,53/TCP 22hkubernetes-dashboard 10.0.0.249 <none> 80/TCP 22h
9 / 37
Master
# ksp-restart.sh# ---#!/bin/bash
kubectl delete po $(kubectl get po --namespace=kube-system | grep kube-dns | cut -d' 'kubectl delete po $(kubectl get po --namespace=kube-system | grep dashboard | cut -d' '
10 / 37
Restart Pods
$ kubectl --namespace=kube-system get poNAME READY STATUS RESTARTS AGEkube-dns-v8-8dk0a 4/4 Running 0 11skubernetes-dashboard-ew4ec 1/1 Running 0 21s
$ kubectl logs --namespace=kube-system kube-dns-v8-8dk0a -c kube2skyI0531 23:29:01.131613 1 kube2sky.go:462 Etcd server found: http://127.0.0.1:4001I0531 23:29:02.225877 1 kube2sky.go:529 Using https://10.0.0.1:443 for kubernetes masterI0531 23:29:02.226027 1 kube2sky.go:530 Using kubernetes API <nil>I0531 23:29:02.231187 1 kube2sky.go:598 Waiting for service: default/kubernetesI0531 23:29:03.431233 1 kube2sky.go:660 Successfully added DNS record for Kubernetes service.
$ kubectl --namespace=kube-system exec -ti kube-dns-v8-8dk0a -- nslookup kubernetes.default.svc.cluster.local localhost...
$ kubectl --namespace=kube-system exec -ti kube-dns-v8-8dk0a -- cat /etc/hosts$ kubectl --namespace=kube-system exec -ti kube-dns-v8-8dk0a -- cat /etc/resolv.conf
11 / 37
CheckDNS Service
# luxas/addons/sleep.yamlapiVersion: v1kind: Podmetadata: name: alpine-sleep namespace: defaultspec: containers: - image: luxas/alpine command: - sleep - "3600" imagePullPolicy: IfNotPresent name: alpine-sleep restartPolicy: Always---apiVersion: v1kind: Podmetadata: name: raspbian-sleep namespace: defaultspec: containers: - image: resin/rpi-raspbian:jessie command: - sleep - "3600" imagePullPolicy: IfNotPresent name: raspbian-sleep restartPolicy: Always
12 / 37
TestDNS Service
$ kubectl create -f sleep.yaml
$ kubectl exec -it alpine-sleep -- nslookup kubernetes.default 10.0.0.10$ kubectl exec -it alpine-sleep -- nslookup kubernetes 10.0.0.10$ kubectl exec -it alpine-sleep -- nslookup kube-dns.kube-system.svc.cluster.local 10.0$ kubectl exec -it alpine-sleep -- nslookup kubernetes-dashboard.kube-system.svc.cluster.local Server: 10.0.0.10Address 1: 10.0.0.10
Name: kubernetes-dashboard.kube-system.svc.cluster.localAddress 1: 10.0.0.249
13 / 37
TestDNS Service
# from Worker/Minion
pirate@node2 in ~$ curl -k https://kubernetes.default.svc.cluster.local$ curl -k https://kubernetes{ "paths": [ "/api", "/api/v1", "/apis", "/apis/autoscaling", "/apis/autoscaling/v1", "/apis/batch", "/apis/batch/v1", "/apis/extensions", "/apis/extensions/v1beta1", "/healthz", "/healthz/ping", "/logs/", "/metrics", "/resetMetrics", "/swagger-ui/", "/swaggerapi/", "/ui/", "/version" ]}
14 / 37
TestDNS Service
$ wget https://storage.googleapis.com/kubernetes-release/release/v1.2.0/bin/linux/amd64/kubectl $ chmod +x kubectl && sudo mv kubectl /usr/local/bin/
$ kubectl config set-cluster lk8 --server=http://192.168.1.102:8080$ kubectl config set-context lk8 --cluster=lk8$ kubectl config use-context lk8
$ kubectl get nodesNAME STATUS AGE192.168.1.100 Ready 3d192.168.1.101 Ready 3d192.168.1.102 Ready 3d
21 / 37
RemoteMaster
$ git clone https://github.com/saturnism/gcp-live-k8s-visualizer.git k8s-visualizer$ cd k8s-visualizer$ kubectl proxy --www=.Starting to serve on 127.0.0.1:8001
22 / 37
k8sVisualizer
$ kubectl run hello-kube --image=hypriot/rpi-nano-httpd --port=80 -l visualize=true,run=hello-kubedeployment "hello-kube" created
$ kubectl expose deployment hello-kube --type="LoadBalancer" --external-ip="192.168.1.102"service "hello-kube" exposed# any node eth0 address: 102,101,100
$ kubectl get svcNAME CLUSTER-IP EXTERNAL-IP PORT(S) AGEhello-kube 10.0.0.157 ,192.168.1.102 80/TCP 37skubernetes 10.0.0.1 <none> 443/TCP 3d
$ kubectl get po -o wideNAME READY STATUS RESTARTS AGE NODEalpine-sleep 1/1 Running 0 1h 192.168.1.102hello-kube-658934829-o6ka3 1/1 Running 0 2m 192.168.1.101k8s-master-192.168.1.102 4/4 Running 3 2h 192.168.1.102raspbian-sleep 1/1 Running 0 1h 192.168.1.102
25 / 37
Test #1
# from node3$ curl 192.168.1.102$ curl 10.0.0.157$ curl hello-kube<html><head><title>Pi armed with Docker by Hypriot</title> <body style="width: 100%; background-color: black;"> <div id="main" style="margin: 100px auto 0 auto; width: 800px;"> <img src="pi_armed_with_docker.jpg" alt="pi armed with docker" style="width: 800px" </div> </body></html>
26 / 37
Test #1Reachability
$ kubectl get po -o wideNAME READY STATUS RESTARTS AGE NODEalpine-sleep 1/1 Running 2 2h 192.168.1.102k8s-master-192.168.1.102 4/4 Running 3 4h 192.168.1.102my-nginx-afadx 1/1 Running 0 19m 192.168.1.100my-nginx-e5coa 1/1 Running 0 19m 192.168.1.101my-nginx2-68r7o 1/1 Running 0 6m 192.168.1.101my-nginx2-pviak 1/1 Running 0 6m 192.168.1.100raspbian-sleep 1/1 Running 2 2h 192.168.1.102
$ kubectl get svcNAME CLUSTER-IP EXTERNAL-IP PORT(S) AGEkubernetes 10.0.0.1 <none> 443/TCP 3dmy-nginx2 10.0.0.138 8300/TCP 6m
$ curl my-nginx2:8300<p>WELCOME TO NGINX</p>HypriotOS/armv7: pirate@node1 in ~
33 / 37
Test #2Reachability
Refs1. Docker Pirates ARMed with explosive stu�2. kubernetes-on-arm - by @luxas3. k8s-visualizer @brendandburns @saturnism4. Setting up Kubernetes visualization of a cluster - @rpicloud
36 / 37
ENDEueung Mulyana
http://eueung.github.io/docker-stuff/learning-k8sCodeLabs | Attribution-ShareAlike CC BY-SA
37 / 37