openSUSE Tumbleweed Kubic 快速架設 Kubernetes Cluster 小記
OS: openSUSE Tumbleweed Kubic
使用 ISO:
- openSUSE-Tumbleweed-Kubic-DVD-x86_64-Snapshot20190115-Media.iso
- openSUSE-Tumbleweed-Kubic-DVD-x86_64-Snapshot20190125-Media.iso
參考官方文件
授權合約: 點選 下一步
進行網路設定
選取要執行的角色, 因為今天是要架設 kubernetes
選取 kubeadm 節點 -- > 下一步
NTP Server 設定, 按照預設值
選取 下一步
設定 root 密碼
點選 下一步
檢視安裝設定
點選 安裝
點選 安裝
安裝之後在本機以 root 登入系統
新增使用者 sakana
#useradd -m sakana
設定使用者 sakana 密碼
#passwd sakana
這邊解釋一下為何要新增一般使用者
- 原廠的文件建議你遠端連線過去操作, 好複製 kubeadm join 指令帶出來的 token, 可是預設 kubic 的 ssh 連線是不能 root 登入
在自己的機器使用 ssh 遠端連線剛剛架設的 kubic
> ssh -l sakana YOUR_SERVER_IP
在 Kubic Master 上面:
切換為 root
>su -
進行 kubeadm init
# kubeadm init --cri-socket=/var/run/crio/crio.sock --pod-network-cidr=10.244.0.0/16
Your Kubernetes master has initialized successfully!
To start using your cluster, you need to run the following as a regular user:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
https://kubernetes.io/docs/concepts/cluster-administration/addons/
You can now join any number of machines by running the following on each node
as root:
kubeadm join xxx.yyy.zz.aa:6443 --token rx4vgw.7eps0trobpfxfwym --discovery-token-ca-cert-hash sha256:55a330afd557c210f8f2482c76c0e05a068c2d8a1c5a794458301f811a485796
退回一般使用者
#exit
> mkdir -p $HOME/.kube
> sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:
#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.
[sudo] password for root:
> sudo chown $(id -u):$(id -g) $HOME/.kube/config
觀察相關資訊
> cat ~/.kube/config
> kubectl get nodes
NAME STATUS ROLES AGE VERSION
kubic-master NotReady master 9m32s v1.13.2
NAME STATUS ROLES AGE VERSION
kubic-master NotReady master 9m32s v1.13.2
> kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/bc79dd1505b0c8681ece4de4c0d86c5cd2643275/Documentation/kube-flannel.yml
clusterrole.rbac.authorization.k8s.io/flannel created
clusterrolebinding.rbac.authorization.k8s.io/flannel created
serviceaccount/flannel created
configmap/kube-flannel-cfg created
daemonset.extensions/kube-flannel-ds-amd64 created
daemonset.extensions/kube-flannel-ds-arm64 created
daemonset.extensions/kube-flannel-ds-arm created
daemonset.extensions/kube-flannel-ds-ppc64le created
daemonset.extensions/kube-flannel-ds-s390x created
clusterrolebinding.rbac.authorization.k8s.io/flannel created
serviceaccount/flannel created
configmap/kube-flannel-cfg created
daemonset.extensions/kube-flannel-ds-amd64 created
daemonset.extensions/kube-flannel-ds-arm64 created
daemonset.extensions/kube-flannel-ds-arm created
daemonset.extensions/kube-flannel-ds-ppc64le created
daemonset.extensions/kube-flannel-ds-s390x created
> kubectl get nodes
NAME STATUS ROLES AGE VERSION
kubic-master Ready master 12m v1.13.2
在 Kubic Slave 上面:
安裝之後在本機以 root 登入系統
新增使用者 sakana
#useradd -m sakana
設定使用者 sakana 密碼
#passwd sakana
在自己的機器使用 ssh 遠端連線剛剛架設的 kubic
> ssh -l sakana YOUR_SERVER_IP
在 Kubic Slave 上面:
切換成管理者 root
> su -
使用剛剛的資訊加入 kubic master
# kubeadm join xxx.yyy.zz.aa:6443 --token rx4vgw.7eps0trobpfxfwym --discovery-token-ca-cert-hash sha256:55a330afd557c210f8f2482c76c0e05a068c2d8a1c5a794458301f811a485796
在 Kubic Master 上面:
> kubectl get nodes
NAME STATUS ROLES AGE VERSION
kubic-2 Ready <none> 2m50s v1.13.2
kubic-master Ready master 124m v1.13.2
在本機上面:
將遠端的 ~/.kube/config 複製過來
建立本機上面的 .kube 目錄
> mkdir -p $HOME/.kube
> scp sakana@YOUR_SERVER_IP:/home/sakana/.kube/config ~/.kube/config.vm
Password: 請輸入密碼
config 100% 5454 860.2KB/s 00:00
觀察資訊
> ls ~/.kube/
cache config.azure config.bak config.vm http-cache
接下來準備設定 ~/.kube/config
狀況 1:
如果本來沒有 ~/.kube/config 直接更名為 config 就可以
> mv ~/.kube/config.vm ~/.kube/config
狀況 2:
如果本來有管理其他的 kubernetes cluster
將所有 config 透過 export 定義 KUBECONFIG ( 請將路徑換成自己 cluster 檔案 )
> export KUBECONFIG=~/.kube/config.vm:~/.kube/config.azure
確認相關資訊
>echo $KUBECONFIG
/home/sakana/.kube/config.vm:/home/sakana/.kube/config.azure
使用 kubectl config 指令合併兩個檔案
> kubectl config view --flatten > ~/.kube/mergedkub
將 mergedkub 檔案更名並複製到 ~/.kube/config
> mv ~/.kube/mergedkub ~/.kube/config
接下來進行測試
> kubectl get nodes
NAME STATUS ROLES AGE VERSION
linux-gotz Ready <none> 154m v1.13.2
linux-nuvj Ready master 174m v1.13.2
建立一個 pod.yaml
> vi pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: nginx-pod-example
spec:
containers:
- name: nginx-pod-example
image: library/nginx
測試運作
> kubectl create -f pod.yaml
pod/nginx-pod-example created
觀察資訊
> kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-pod-example 1/1 Running 0 72s
使用 kubectl port-forward 指令
> kubectl port-forward nginx-pod-example 8000:80
Forwarding from 127.0.0.1:8000 -> 80
Forwarding from [::1]:8000 -> 80
開啟瀏覽器 http://localhost:8000
測試完成
這樣就可以輕鬆進行 kubernetes cluster 相關測試
~ enjoy it
之後待研究
- kubeadm token create --print-join-command
Reference
沒有留言:
張貼留言