Skip to content

Latest commit

 

History

History
164 lines (138 loc) · 7.12 KB

yurtctl.md

File metadata and controls

164 lines (138 loc) · 7.12 KB

Yurtctl

Assume that you are within the OpenYurt repository root directory, and has the _output/bin/yurtctl binary available.

Convert a single-node minikube cluster

You can use yurtctl to convert a standard Kubernetes cluster to a Yurt cluster. Let's use a minikube cluster as an example.

  1. simply run the following command
$ _output/bin/yurtctl convert --provider minikube
  1. yurtctl will install all required components and reset the edge node. The output will look something like
I0527 14:39:24.633962   13385 convert.go:148] mark minikube as the edge-node
I0527 14:39:24.640553   13385 convert.go:159] mark minikube as autonomous node
I0527 14:39:24.654238   13385 convert.go:178] deploy the yurt controller manager
I0527 14:39:24.681435   13385 convert.go:190] deploying the yurt-hub and resetting the kubelet service...
I0527 14:40:44.774684   13385 util.go:137] servant job(yurtctl-servant-convert-minikube) has succeeded
  1. and yurt controller manager and yurt hub will be up and running in around one minutes
$ kubectl get deploy -A
NAMESPACE     NAME            READY   UP-TO-DATE   AVAILABLE   AGE   CONTAINERS      IMAGES                          SELECTOR
                                                            ......
kube-system   yurt-ctrl-mgr   1/1     1            1           12m   yurt-ctrl-mgr   openyurt/yurt-ctrl-mgr:latest   app=yurt-ctrl-mgr

$ kubectl get po -A
NAMESPACE     NAME                               READY   STATUS    RESTARTS   AGE   IP               NODE       NOMINATED NODE   READINESS GATES
                                                            ......
kube-system   yurt-hub-minikube                  1/1     Running   0          13m   192.168.64.193   minikube   <none>           <none>
  1. As the cluster only contains one node, the node will be marked as an automous edge node, you can check this by inspecting the node's labels and annotations
# edge node will have label "alibabacloud.com/is-edge-worker" set as "true"
$ kubectl describe node | grep Labels -A 3
Labels:             alibabacloud.com/is-edge-worker=true
                    ... 
                    ... 
                    ... 

# automous node will have annotation "node.beta.alibabacloud.com/autonomy" set as "true"
$ kubectl describe node | grep Annotations -A 3
Annotations:        ... 
                    ... 
                    node.beta.alibabacloud.com/autonomy: true
                    ... 
  1. To check if the edge node works as expected when it is disconnected from apiserver, 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
pod/bbox created

$ kc get po -A
NAMESPACE     NAME                               READY   STATUS    RESTARTS   AGE
default       bbox                               1/1     Running   0          19s
                                        ...
  1. then login to the node and change the yurt-hub'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 
  1. and the yurt-hub will be disconnected from the apiserver, to verify this, you can curl the yurt-hub from inside the node and will see something like
$ 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
}
  1. after 40 seconds, the node status will become NotReady, but the pod/bbox won't be evicted and will keep running on the node
$ kc get node && kc get po
NAME       STATUS     ROLES    AGE   VERSION
minikube   NotReady   master   58m   v1.18.2
NAME   READY   STATUS    RESTARTS   AGE
bbox   1/1     Running   0          19m

Convert a multi-nodes Kubernetes cluster

Sometimes, you may only want to convert part of the nodes to edge nodes, but leave the rest of the nodes as default. yurtctl convert achieve this by allowing user to specify a list of cloud nodes that won't be converted through option -c, --cloud-nodes.

  1. Assume you have 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
  1. you can converted it into a Yurt cluster that contains only one edge node~(i.e. minikube) by typing the following command
$ _output/bin/yurtctl convert --cloud-nodes minikube --provider minikube
I0527 15:55:32.254651   15210 convert.go:140] mark minikube as the cloud-node
I0527 15:55:32.259656   15210 convert.go:148] mark minikube-m02 as the edge-node
I0527 15:55:32.265289   15210 convert.go:159] mark minikube-m02 as autonomous node
I0527 15:55:32.283366   15210 convert.go:178] deploy the yurt controller manager
I0527 15:55:32.310913   15210 convert.go:190] deploying the yurt-hub and resetting the kubelet service...
I0527 15:56:22.393261   15210 util.go:137] servant job(yurtctl-servant-convert-minikube-m02) has succeeded
  1. as only the node minikube-m02 is converted to an edge node, node minikube will be marked as a non-edge node, you can check this by inspecting its labels
$ kubectl describe node minikube | grep Labels
Labels:             alibabacloud.com/is-edge-worker=false
  1. also when the Yurt 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    RESTARTS   AGE     IP               NODE           NOMINATED NODE   READINESS GATES
                                                           ......
kube-system   yurt-ctrl-mgr-546489b484-78c2f     1/1     Running   0          5m49s   10.244.0.2       minikube       <none>           <none>

Revert a Yurt cluster

You can also use yurtctl to revert a Yurt cluster back to the original Kubernetes cluster by typing

$ _output/bin/yurtctl revert
I0527 16:04:13.254555   17159 revert.go:100] label alibabacloud.com/is-edge-worker is removed
I0527 16:04:13.259337   17159 revert.go:110] yurt controller manager is removed
I0527 16:04:13.274970   17159 revert.go:124] ServiceAccount node-controller is created
I0527 16:04:23.299404   17159 util.go:137] servant job(yurtctl-servant-revert-minikube-m02) has succeeded
I0527 16:04:23.299441   17159 revert.go:133] yurt-hub is removed, kubelet service is reset

Before performing the reversion, please make sure all edge nodes are reachable from the apiserver.

Troubleshooting

1. Fail to convert due to pulling image timeout

The default timeout value of the conversion is 2 minutes, sometimes, pulling the related images (i.e., openyurt/yurt-hub, openyurt/yurtctl-servant, and openyurt/yurt-ctrl-mgr) can take more than 2 minutes. To avoid the conversion failure due to pulling images timeout, you can save images on the node in advance.