This tutorial demonstrates how to use yurtctl to install/uninstall OpenYurt.
We assume a minikube cluster (version 1.14 or less)
is installed in the machine and _output/bin/yurtctl binary is built.
Let us use yurtctl to convert a standard Kubernetes cluster to an OpenYurt cluster.
- Run the following command
$ _output/bin/yurtctl convert --provider minikubeyurtctlwill install all required components and reset the kubelet in the edge node. The output looks like:
convert.go:148] mark minikube as the edge-node
convert.go:159] mark minikube as autonomous node
convert.go:178] deploy the yurt controller manager
convert.go:190] deploying the yurt-hub and resetting the kubelet service...
util.go:137] servant job(yurtctl-servant-convert-minikube) has succeeded- yurt controller manager and yurthub Pods will be up and running in one minute. Let us verify them:
$ kubectl get deploy yurt-ctrl-mgr -n kube-system
NAME READY UP-TO-DATE AVAILABLE AGE
yurt-ctrl-mgr 1/1 1 1 23h
$ kubectl get po yurt-hub-minikube -n kube-system
NAME READY STATUS RESTARTS AGE
yurt-hub-minikube 1/1 Running 0 23h- As the minikube cluster only contains one node, the node will be marked as an autonomous edge node. Let us verify this by inspecting the node's labels and annotations:
$ kubectl describe node | grep Labels -A 3
Labels: alibabacloud.com/is-edge-worker=true
$ kubectl describe node | grep Annotations -A 3
Annotations: node.beta.alibabacloud.com/autonomy: true
By now, the OpenYurt cluster is ready. Users will not notice any differences compared to native Kubernetes when operating the cluster. If you login to the node, you will find the local cache has been populated:
$ minikube ssh
$ ls /etc/kubernetes/cache/kubelet/
configmaps events leases nodes pods secrets services
To test if edge node autonomy works as expected, we will simulate a node "offline" scenario.
- Let's first create a sample pod:
kubectl apply -f-<<EOF
> apiVersion: v1
> kind: Pod
> metadata:
> name: bbox
> spec:
> containers:
> - image: busybox
> command:
> - top
> name: bbox
> EOF- Make the edge node "offline" by changing the
yurthub's server-addr to an unreachable address:
$ minikube ssh
$ sudo sed -i 's|--server-addr=.*|--server-addr=https://1.1.1.1:1111|' /etc/kubernetes/manifests/yurt-hub.yaml - Now
yurthubis disconnected from the apiserver and works in offline mode. To verify this, we can do the following:
$ minikube ssh
$ curl -s http://127.0.0.1:10261
{
"kind": "Status",
"metadata": {
},
"status": "Failure",
"message": "request( get : /) is not supported when cluster is unhealthy",
"reason": "BadRequest",
"code": 400
}- After 40 seconds, the edge node status becomes
NotReady, but the pod/bbox won't be evicted and keeps running on the node:
$ kubectl get node && kubectl get po
NAME STATUS ROLES AGE VERSION
minikube NotReady master 58m v1.18.2
NAME READY STATUS RESTARTS AGE
bbox 1/1 Running 0 19mAn OpenYurt cluster may consist of some edge nodes and some nodes in the cloud site.
yurtctl allows users to specify a list of cloud nodes that won't be converted.
- Start with a two-nodes minikube cluster,
$ kubectl get node
NAME STATUS ROLES AGE VERSION
minikube Ready master 2m5s v1.18.2
minikube-m02 Ready <none> 84s v1.18.2- You can convert only one node to edge node(i.e., minikube-m02) by using this command:
$ _output/bin/yurtctl convert --cloud-nodes minikube --provider minikube
convert.go:140] mark minikube as the cloud-node
convert.go:148] mark minikube-m02 as the edge-node
convert.go:159] mark minikube-m02 as autonomous node
convert.go:178] deploy the yurt controller manager
convert.go:190] deploying the yurt-hub and resetting the kubelet service...
util.go:137] servant job(yurtctl-servant-convert-minikube-m02) has succeeded- Node
minikubewill be marked as a non-edge node. You can verify this by inspecting its labels:
$ kubectl describe node minikube | grep Labels
Labels: alibabacloud.com/is-edge-worker=false- When the OpenYurt cluster contains cloud nodes, yurt controller manager will be deployed on the cloud node (in this case, the node
minikube):
$ kubectl get po -A -o wide
NAMESPACE NAME READY STATUS AGE IP NODE
kube-system yurt-ctrl-mgr-546489b484-78c2f 1/1 Running 5m49s 10.244.0.2 minikubeUsing yurtctl to revert an OpenYurt cluster can be done by doing the following:
$ _output/bin/yurtctl revert
revert.go:100] label alibabacloud.com/is-edge-worker is removed
revert.go:110] yurt controller manager is removed
revert.go:124] ServiceAccount node-controller is created
util.go:137] servant job(yurtctl-servant-revert-minikube-m02) has succeeded
revert.go:133] yurt-hub is removed, kubelet service is reset
Note that before performing the uninstall, please make sure all edge nodes are reachable from the apiserver.
The default timeout value of cluster conversion is 2 minutes. Sometimes pulling the related images
might take more than 2 minutes. To avoid the conversion failure due to pulling images timeout, you can pull all images on the node manually
or use automation tools such as broadcastjob(from Kruise) in advance.
In case any adhoc failure makes the Kubelet fail to communicate with APIServer, one can recover the original Kubelet setup by running the following command in edge node directly:
$ sudo sed -i "s|--kubeconfig=.*kubelet.conf|--kubeconfig=/etc/kubernetes/kubelet.conf|g;" /etc/systemd/system/kubelet.service.d/10-kubeadm.conf && sudo systemctl daemon-reload && sudo systemctl restart kubelet.service