Toggle navigation
Home
安装部署
Archives
Tags
kubeedge deployment
2020-01-10 08:29:53
138
0
0
louyj
KubeEdge is composed of cloud and edge parts. It is built upon Kubernetes and provides core infrastructure support for networking, application deployment and metadata synchronization between cloud and edge. So if we want to setup kubeedge, we need to setup kubernetes cluster, cloud side and edge side. on cloud side, we need to install docker, kubernetes cluster and cloudcore. on edge side, we need to install docker, mqtt and edgecore. Go dependency and Kubernetes compatibility please refer  #Prerequisites ##Cloud side ###Install golang ``` wget https://dl.google.com/go/go1.12.15.linux-amd64.tar.gz tar zxvf go1.12.15.linux-amd64.tar.gz mv go /opt/go vi .bash_profile export GOROOT=/opt/go export PATH=$PATH:$GOROOT/bin export GOPATH=/root/go export PATH=$PATH:$GOPATH/BIN ``` ##Edge side ###Install golang ``` wget https://dl.google.com/go/go1.12.15.linux-amd64.tar.gz tar zxvf go1.12.15.linux-amd64.tar.gz mv go /opt/go vi .bash_profile export GOROOT=/opt/go export PATH=$PATH:$GOROOT/bin export GOPATH=/root/go export PATH=$PATH:$GOPATH/BIN source .bash_profile ``` ###Install docker ``` ## Install prerequisites. yum install yum-utils device-mapper-persistent-data lvm2 ## Add docker repository. yum-config-manager \ --add-repo \ https://download.docker.com/linux/centos/docker-ce.repo ## Install docker. yum update && yum install \ containerd.io-1.2.10 \ docker-ce-19.03.4 \ docker-ce-cli-19.03.4 ## Create /etc/docker directory. mkdir /etc/docker mkdir /docker # Setup daemon. cat > /etc/docker/daemon.json <<EOF { "log-driver": "json-file", "log-opts": { "max-size": "100m" }, "storage-opts": [ "overlay2.override_kernel_check=true" ], "bip": "172.17.0.1/24", "data-root": "/docker", "registry-mirrors": [ "https://1nj0zren.mirror.aliyuncs.com", "https://docker.mirrors.ustc.edu.cn", "http://f1361db2.m.daocloud.io", "https://registry.docker-cn.com" ] } EOF # "bip": "192.168.35.1/24" # ip link del docker0 mkdir -p /etc/systemd/system/docker.service.d # Restart docker. systemctl daemon-reload systemctl restart docker systemctl enable docker.service ``` ###Install mosquitto ``` yum -y install epel-release yum -y install mosquitto systemctl start mosquitto systemctl enable mosquitto ``` #Run KubeEdge ##Setup cloud side ###Clone KubeEdge ``` git clone https://github.com/kubeedge/kubeedge.git $GOPATH/src/github.com/kubeedge/kubeedge cd $GOPATH/src/github.com/kubeedge/kubeedge ``` ###Generate Certificates RootCA certificate and a cert/key pair is required to have a setup for KubeEdge. Same cert/key pair can be used in both cloud and edge. ``` $GOPATH/src/github.com/kubeedge/kubeedge/build/tools/certgen.sh genCertAndKey edge ``` The cert/key will be generated in the `/etc/kubeedge/ca` and `/etc/kubeedge/certs` respectively, so this command should be run with root or users who have access to those directories. We need to copy these files to the corresponding edge side server directory. ###Run as a binary Firstly, make sure gcc is already installed on your host. You can verify it via: gcc --version Build cloudcore ``` cd $GOPATH/src/github.com/kubeedge/kubeedge/ make all WHAT=cloudcore ``` Create device model and device CRDs. ``` cd $GOPATH/src/github.com/kubeedge/kubeedge/build/crds/devices kubectl create -f devices_v1alpha1_devicemodel.yaml kubectl create -f devices_v1alpha1_device.yaml ``` Copy cloudcore binary and config file ``` cd $GOPATH/src/github.com/kubeedge/kubeedge/cloud # run edge controller # `conf/` should be in the same directory as the cloned KubeEdge repository # verify the configurations before running cloud(cloudcore) mkdir -p ~/cmd/conf cp cloudcore ~/cmd/ cp -rf conf/* ~/cmd/conf/ ``` Note ~/cmd/ dir is an example, in the following examples we continue to use ~/cmd/ as the binary startup directory. You can move cloudcore or edgecore binary to anywhere, but you need to create conf dir in the same directory as binary. Set cloudcore config file ``` cd ~/cmd/conf vim controller.yaml ``` verify the configurations before running cloudcore cloudcore default supports https connection to Kubernetes apiserver, so you need to check whether the path for `controller.kube.kubeconfig` and `devicecontroller.kube.kubeconfig` exist, but if `master` and `kubeconfig` are both set, `master` will override any value in kubeconfig. Check whether the cert files for `cloudhub.ca, cloudhub.cert,cloudhub.key` exist. Run cloudcore ``` cd ~/cmd/ nohup ./cloudcore & ``` Run cloudcore with systemd It is also possible to start the cloudcore with systemd. If you want, you could use the example systemd-unit-file. The following command will show you how to setup this: ``` sudo mv build/tools/cloudcore.service /etc/systemd/system/cloudcore.service vi /etc/systemd/system/cloudcore.service ExecStart=/root/cmd/cloudcore sudo systemctl daemon-reload sudo systemctl start cloudcore sudo systemctl enable cloudcore ``` ###Deploy the edge node We have provided a sample node.json to add a node in kubernetes. Please make sure edge-node is added in kubernetes. Run below steps to add edge-node. ``` mkdir -p ~/cmd/yaml cp $GOPATH/src/github.com/kubeedge/kubeedge/build/node.json ~/cmd/yaml vi node.json { "kind": "Node", "apiVersion": "v1", "metadata": { "name": "worker02", "labels": { "name": "worker02", "node-role.kubernetes.io/edge": "" } } } ``` Make sure role is set to edge for the node. For this a key of the form "node-role.kubernetes.io/edge" must be present in labels tag of metadata If role is not set for the node, the pods, configmaps and secrets created/updated in the cloud cannot be synced with the node they are targeted for. Deploy edge node (you must run on cloud side) kubectl apply -f ~/cmd/yaml/node.json Transfer certificate files to the edge node, because edgecore use these certificate files to connection cloudcore scp -r /etc/kubeedge/ worker02:/etc/ ##Setup edge side ###Clone KubeEdge ``` git clone https://github.com/kubeedge/kubeedge.git $GOPATH/src/github.com/kubeedge/kubeedge cd $GOPATH/src/github.com/kubeedge/kubeedge ``` ###Run Edge ####Configuring MQTT mode The Edge part of KubeEdge uses MQTT for communication between deviceTwin and devices. KubeEdge supports 3 MQTT modes: - internalMqttMode: internal mqtt broker is enabled. - bothMqttMode: internal as well as external broker are enabled. - externalMqttMode: only external broker is enabled. Use mode field in edge.yaml to select the desired mode. To use KubeEdge in double mqtt or external mode, you need to make sure that mosquitto or emqx edge is installed on the edge node as an MQTT Broker. ####Run as a binary Build Edge ``` yum install gcc cd $GOPATH/src/github.com/kubeedge/kubeedge make all WHAT=edgecore ``` KubeEdge can also be cross compiled to run on ARM based processors. Please follow the instructions given below or click Cross Compilation for detailed instructions. ``` cd $GOPATH/src/github.com/kubeedge/kubeedge/edge make edge_cross_build ``` KubeEdge can also be compiled with a small binary size. Please follow the below steps to build a binary of lesser size: ``` apt-get install upx-ucl cd $GOPATH/src/github.com/kubeedge/kubeedge/edge make edge_small_build ``` Note: If you are using the smaller version of the binary, it is compressed using upx, therefore the possible side effects of using upx compressed binaries like more RAM usage, lower performance, whole code of program being loaded instead of it being on-demand, not allowing sharing of memory which may cause the code to be loaded to memory more than once etc. are applicable here as well. Set edgecore config file ``` mkdir ~/cmd/conf -p cp $GOPATH/src/github.com/kubeedge/kubeedge/edge/conf/* ~/cmd/conf vim ~/cmd/conf/edge.yaml #verify the configurations before running edgecore #change podsandbox-image: kubeedge/pause:3.1 #change edgehub.websocket.url: wss://192.168.1.122:10000 #change edgehub.quic.url: url: 192.168.1.122:10001 #replace edge-node with edge node name in edge.yaml for the below fields: websocket:URL, controller:node-id, edged:hostname-override #change interface-name ``` verify the configurations before running edgecore  Run edgecore ``` # run mosquitto mosquitto -d -p 1883 # or run emqx edge # emqx start cp $GOPATH/src/github.com/kubeedge/kubeedge/edge/edgecore ~/cmd/ cd ~/cmd ./edgecore # or nohup ./edgecore > edgecore.log 2>&1 & ``` Run edgecore with systemd ``` sudo ln build/tools/edgecore.service /etc/systemd/system/edgecore.service vi /etc/systemd/system/edgecore.service ExecStart=/root/cmd/edgecore sudo systemctl daemon-reload sudo systemctl start edgecore systemctl enable edgecore ``` Check status kubectl get nodes Please make sure the status of edge node you created is ready. Deploy Application on cloud side kubectl apply -f $GOPATH/src/github.com/kubeedge/kubeedge/build/deployment.yaml Note: Currently, for applications running on edge nodes, **we don’t support kubectl logs and kubectl exec commands**(will support in future release), support pod to pod communication running on edge nodes in same subnet using edgemesh.
Pre:
k8s vpn 路由设置
Next:
kubernetes with stacked etcd 部署
0
likes
138
Weibo
Wechat
Tencent Weibo
QQ Zone
RenRen
Submit
Sign in
to leave a comment.
No Leanote account?
Sign up now.
0
comments
More...
Table of content
No Leanote account? Sign up now.