JupyterHub ด้วย Kubernetes บน Windows

  1. ติดตั้ง kubectl บน Windows
  2. ติดตั้ง minikube บน Windows
  3. ติดตั้ง helm
  4. ติดตั้ง JupyterHub

Link

Document


ติดตั้ง Kubernetes บน Windows

1.ติดตั้ง kubectl บน Windows

Require Docker 18.09 or higher

ติดตั้งด้วย Chocolatey

เปิด PowerShell (Run as administrator)

Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
choco install kubernetes-cli

ตรวจสอบว่าติดตั้งเรียบร้อยมั๊ย

>kubectl version --client
Client Version: version.Info{Major:"1", Minor:"21", GitVersion:"v1.21.2", GitCommit:"092fbfbf53427de67cac1e9fa54aaa09a28371d7", GitTreeState:"clean", BuildDate:"2021-06-16T12:59:11Z", GoVersion:"go1.16.5", Compiler:"gc", Platform:"windows/amd64"}

ไปที่ home directory

cd ~

สร้างไดเร็กทอรี่ .kube 

mkdir .kube

สร้างไฟล์ .kube/config

Verify kubectl configuration

> kubectl cluster-info

ถ้าได้แบบนี้ก็ ok

Kubernetes control plane is running at https://127.0.0.1:62648
CoreDNS is running at https://127.0.0.1:62648/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.

แต่ถ้าได้แบบนี้ แสดงว่ายังไม่ได้สั่ง minikube start (ติดตั้ง minikube ตามข้อ 2 ก่อน)

To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
Unable to connect to the server: dial tcp [::1]:8080: connectex: No connection could be made because the target machine actively refused it.

เปิด browser ไปที่ https://127.0.0.1:62648 จะได้

{
  "kind": "Status",
  "apiVersion": "v1",
  "metadata": {
    
  },
  "status": "Failure",
  "message": "forbidden: User \"system:anonymous\" cannot get path \"/\"",
  "reason": "Forbidden",
  "details": {
    
  },
  "code": 403
}

แปลว่า ok ใช้ได้ เพราะยังไม่ได้ authen

kubectl cluster-info dump
> kubectl describe service kubernetes
Name:              kubernetes
Namespace:         default
Labels:            component=apiserver
                   provider=kubernetes
Annotations:       <none>
Selector:          <none>
Type:              ClusterIP
IP Family Policy:  SingleStack
IP Families:       IPv4
IP:                10.96.0.1
IPs:               10.96.0.1
Port:              https  443/TCP
TargetPort:        8443/TCP
Endpoints:         192.168.49.2:8443
Session Affinity:  None
Events:            <none>
> kubectl proxy
Starting to serve on 127.0.0.1:8001

2.ติดตั้ง minikube บน Windows

ลง Kubernetes ผ่าน Minikube

ดาว์นโหลด minikube-installer.exe และติดตั้ง

Start your cluster เปิด cmd ด้วยสิทธิ admin (Run as administrator)

minikube start


Interact with your cluster

If you already have kubectl installed, you can now use it to access your shiny new cluster:

> kubectl get po -A
NAMESPACE              NAME                                         READY   STATUS    RESTARTS   AGE
default                balanced-5744b548b4-n4wvb                    1/1     Running   1          12d
default                hello-minikube-6ddfcc9757-kvbzz              1/1     Running   3          14d
jhub                   continuous-image-puller-lqwk7                1/1     Running   2          14d
jhub                   hub-d7df4d54-l544t                           1/1     Running   2          14d
jhub                   proxy-5d5d74db85-c9kms                       1/1     Running   2          14d
jhub                   user-scheduler-544479f8b7-fppxn              1/1     Running   2          14d
jhub                   user-scheduler-544479f8b7-vfk95              1/1     Running   2          14d
kube-system            coredns-558bd4d5db-mz5j7                     1/1     Running   5          14d
kube-system            etcd-minikube                                1/1     Running   5          14d
kube-system            kube-apiserver-minikube                      1/1     Running   5          14d
kube-system            kube-controller-manager-minikube             1/1     Running   5          14d
kube-system            kube-proxy-gpp47                             1/1     Running   5          14d
kube-system            kube-scheduler-minikube                      1/1     Running   5          14d
kube-system            storage-provisioner                          1/1     Running   10         14d
kubernetes-dashboard   dashboard-metrics-scraper-7976b667d4-dqc75   1/1     Running   3          14d
kubernetes-dashboard   kubernetes-dashboard-6fcdf4f6d-8rswz         1/1     Running   5          14d

แสดง dashboard

minikube dashboard

LoadBalancer deployments

To access a LoadBalancer deployment, use the “minikube tunnel” command. Here is an example deployment:

kubectl create deployment balanced --image=k8s.gcr.io/echoserver:1.4  
kubectl expose deployment balanced --type=LoadBalancer --port=8080

In another window, start the tunnel to create a routable IP for the ‘balanced’ deployment:

minikube tunnel

To find the routable IP, run this command and examine the EXTERNAL-IP column:

kubectl get services balanced

Manage your cluster

minikube pause
minikube stop
minikube addons list

3.ติดตั้ง helm

ติดตั้ง helm ด้วย Chocolatey

choco install kubernetes-helm

ตรวจสอบ

helm version

4.ติดตั้ง JupyterHub

Initialize a Helm chart configuration file ด้วยการสร้างไฟล์ config.yaml

เช่นสร้างไว้ที่ C:\helm\config.yaml แล้วใส่ข้อความ (ใน comment) ตามนี้

# This file can update the JupyterHub Helm chart's default configuration values.
#
# For reference see the configuration reference and default values, but make
# sure to refer to the Helm chart version of interest to you!
#
# Introduction to YAML:     https://www.youtube.com/watch?v=cdLNKUoMc6c
# Chart config reference:   https://zero-to-jupyterhub.readthedocs.io/en/stable/resources/reference.html
# Chart default values:     https://github.com/jupyterhub/zero-to-jupyterhub-k8s/blob/HEAD/jupyterhub/values.yaml
# Available chart versions: https://jupyterhub.github.io/helm-chart/
#

ติดตั้ง JupyterHub

helm repo add jupyterhub https://jupyterhub.github.io/helm-chart/
helm repo update

จะเห็น output ประมาณนี้

Hang tight while we grab the latest from your chart repositories...
...Skip local chart repository
...Successfully got an update from the "stable" chart repository
...Successfully got an update from the "jupyterhub" chart repository
Update Complete. ⎈ Happy Helming!⎈

Now install the chart configured by your config.yaml by running this command from the directory that contains your config.yaml:

helm upgrade --cleanup-on-fail \
  --install <helm-release-name> jupyterhub/jupyterhub \
  --namespace <k8s-namespace> \
  --create-namespace \
  --version=<chart-version> \
  --values config.yaml

เช่น

helm upgrade --cleanup-on-fail --install jhub jupyterhub/jupyterhub --namespace jhub --create-namespace --version=1.0.0 --values config.yaml

While Step 2 is running, you can see the pods being created by entering in a different terminal:

kubectl get pod --namespace jhub

Wait for the hub and proxy pod to enter the Running state.

NAME                    READY     STATUS    RESTARTS   AGE
hub-5d4ffd57cf-k68z8    1/1       Running   0          37s
proxy-7cb9bc4cc-9bdlp   1/1       Running   0          37s

Find the IP we can use to access the JupyterHub. Run the following command until the EXTERNAL-IP of the proxy-public service is available like in the example output.

kubectl get service --namespace <k8s-namespace>

NAME           TYPE           CLUSTER-IP      EXTERNAL-IP     PORT(S)        AGE
hub            ClusterIP      10.51.243.14    <none>          8081/TCP       1m
proxy-api      ClusterIP      10.51.247.198   <none>          8001/TCP       1m
proxy-public   LoadBalancer   10.51.248.230   104.196.41.97   80:31916/TCP   1m

เช่น

kubectl get service --namespace jhub

ถ้าไม่เห็น EXTERNAL-IP เปิดอีก cmd แล้วรัน

minikube tunnel

ถ้าอยากดูรายละเอียด

>kubectl describe service proxy-public --namespace jhub

เปิด browser ไปที่ EXTERNAL-IP

ติดตั้ง Apache

sudo yum update
sudo yum install httpd

เปิด Firewall

sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload

start httpd

sudo systemctl start httpd


ตรวจสอบว่ารันมั๊ย

sudo systemctl status httpd

แสดง host’s network addresses (IP addresses separated by spaces)

hostname -I

CentOS ใน VirtualBox

ติดตั้ง CentOS ใน VirtualBox แล้วลง Guest Addition แต่พอ reboot แล้วปรับขนาดหน้าจอไม่ได้ และขึ้น Error ว่า

VBoxClient the VirtualBox kernel service is not running. 

ลองดู /var/log/vboxadd-setup.log เจอว่า

modprobe vboxguest failed

ให้แก้ไขด้วยคำสั่ง

sudo yum update
sudo yum install binutils gcc make patch libgomp glibc-headers glibc-devel kernel-headers 
sudo yum install kernel-devel
sudo reboot

น่าจะใช้ได้ปกติละ แต่ถ้ายังไม่ได้ก็ลอง ติดตั้ง VBoxLinuxAdditions ใหม่อีกครั้ง

คำสั่งพื้นฐาน CentOS 7

ทำ user ให้เป็น root

user ที่จะใช้คำสั่ง sudo ได้ ต้องอยู่ใน sudoers file ก่อน ด้วยคำสั่ง wheel (แทนค่า “username” ด้วย user ที่ต้องการ)

$ usermod -aG wheel username

เสร็จแล้วตรวจสอบด้วยคำสั่ง whoami ถ้าได้ root ก็เป็นอันเสร็จ

$ sudo whoami

โปรแกรมน่าติดตั้ง

$ sudo yum install net-tools
$ sudo yum install wget
$ sudo yum install tree
$ sudo yum install nano

ถ้าจะ uninstall package ใช้คำสั่ง

sudo yum remove package_name 

เรื่องของ yum.repos.d

พาท /etc/yum.repos.d/

ตัวอย่างการเพิ่มด้วย curl

sudo curl -o /etc/yum.repos.d/msprod.repo https://packages.microsoft.com/config/rhel/7/prod.repo

หรือ

sudo curl https://packages.microsoft.com/config/rhel/7/prod.repo > /etc/yum.repos.d/msprod.repo

ตัวอย่างการเพิ่มด้วย sh

sudo sh -c 'echo -e "[code]\nname=Visual Studio Code\nbaseurl=https://packages.microsoft.com/yumrepos/vscode\nenabled=1\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc" > /etc/yum.repos.d/vscode.repo'

จะได้

$ cat /etc/yum.repos.d/vscode.repo
[code]
name=Visual Studio Code
baseurl=https://packages.microsoft.com/yumrepos/vscode
enabled=1
gpgcheck=1
gpgkey=https://packages.microsoft.com/keys/microsoft.asc

ดู repository ทั้งหมด

yum repolist all | grep mysql

ดู repository เฉพาะที่ enabled

yum repolist enabled | grep mysql

ifconfig

ifconfig equivalent

ip addr

ติดตั้ง net-tools เพื่อใช้คำสั่ง ifconfig

yum install net-tools

แล้วก็ใช้ netstat

netstat -antp

update

sudo yum update

ถ้ามี error during download metadata for repository ให้แก้ไขโดยเปิดไฟล์ /etc/sysconfig/network-scripts/ifcfg-eth0 แล้วให้ค่า ONBOOT=yes (Ref)

View All the Host Names

hostnamectl

หรือ

hostnamectl status

Set All the Host Names

# hostnamectl set-hostname name

Configure Static IP Address

เดิมค่า BOOTPROTO=dhcp เปลี่ยนเป็น BOOTPROTO=static แล้วเพิ่ม IPADDR และ NETMASK

# vi /etc/sysconfig/network-scripts/ifcfg-enp0s8
BOOTPROTO=static
IPADDR=192.168.56.2
NETMASK=255.255.255.0
ONBOOT=yes

Restart the network services 

sudo service network restart

To verify the IP address

$ ip -br a

ไฟล์ ifcfg-enp0s8 หาย!!!

หาค่า UUID

$  nmcli con show
NAME                UUID                                  TYPE      DEVICE
Wired connection 1  bdcfff16-3517-32ef-8bbe-67ea15cb8bce  ethernet  enp0s8
virbr0              7c1d8308-5525-4ca9-8e1f-33d282de91fd  bridge    virbr0
enp0s3              6f0e07f5-2060-45ad-b7c0-b180974c04c5  ethernet  --

สร้างไฟล์ /etc/sysconfig/network-scripts/ifcfg-enp0s8 แล้วกำหนดค่าต่างๆ

TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
IPADDR=192.168.56.105
NETMASK=255.255.255.0
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=enp0s8
UUID=bdcfff16-3517-32ef-8bbe-67ea15cb8bce
DEVICE=enp0s8
ONBOOT=yes

Restart the network services 

sudo service network restart

ติดตั้ง Git

Install Git with Yum

sudo yum install git
$ git --version
git version 1.8.3.1

Set Up Git

git config --global user.name "Your Name"
git config --global user.email "you@example.com"
git config --list