KubeEdge集群搭建

KubeEdge集群搭建

1. 前言

上一篇文章我把整个KubeEdge的宏观架构设计讲了一遍,今天的内容是实操实践,手把手教你搭建KubeEdge集群。

2. 准备工作

需要两台机器,不管是笔记本也好还是树莓派都可以,单是有一个前提,作为Master节点的机器的配置至少要达到2C4G,不然跑不了k8s。还要就是OS要是Linux的,别的系统不行。负载节点就无所谓啦,比如说树莓派3B+或者是树莓派4B+都可以。现在的树莓派配置也是相当的高了,arm的小板子也能做到4C 8G。

3. 搭建K8s

搭建K8s我已经在之前的文章中写了,不会的直接回去看 传送门

4. 安装Cloudcore

安装有两种方式,一种源码编译手动安装,还有一种是使用ke提供的工具-keadm。手动安装比较繁琐,对于新手而言是一种很大的心智负担,最好大家还是都用keadm这个工具去安装,但是,这种方式安装最大的问题就是国内的墙的问题会导致很多某些资源无法下载,比如说 CRD的yaml,cloudcore启动的service,所以我会结合两者,采用半手动半工具的安装方式去帮助大家顺利的完成ke的集群搭建。

1 下载keadm

wget https://github.com/kubeedge/kubeedge/releases/download/v1.5.0/keadm-v1.5.0-linux-amd64.tar.gz 

我写这篇文章的时候,ke的版本还是v1.5.0,所以我就以安装1.5.0版本的作为一个例子。

下载下来之后执行

tar -zxvf keadm-v1.5.0-linux-amd64.tar.gz # 解压keadm的tar.gz的包
cd keadm-v1.5.0-linux-amd64/keadm && chmod +x keadm && mv keadm /usr/local/bin

验证keadm是否安装成功

$ keadm version
version: version.Info{Major:"1", Minor:"5", GitVersion:"v1.5.0", GitCommit:"8b0913e04ef4ef826af6715d336e23a66e3774df", GitTreeState:"clean", BuildDate:"2020-11-13T08:04:56Z", GoVersion:"go1.15", Compiler:"gc", Platform:"linux/amd64"}

2 使用keadm安装cloudcore

keadm init --advertise-address=xxx.xx.xx.xx --kubeedge-version=1.5.0
Kubernetes version verification passed, KubeEdge installation will start...
--2021-02-11 13:20:41--  https://raw.githubusercontent.com/kubeedge/kubeedge/master/build/crds/devices/devices_v1alpha2_device.yaml
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 151.101.76.133
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|151.101.76.133|:443... connected.
Unable to establish SSL connection.
Converted links in 0 files in 0 seconds.
Error: failed to run 'sh -c cd /etc/kubeedge/crds/devices && wget -k --no-check-certificate --progress=bar:force https://raw.githubusercontent.com/kubeedge/kubeedge/master/build/crds/devices/devices_v1alpha2_device.yaml' because of error : exit status 4
Usage:
  keadm init [flags]

Examples:

keadm init

- This command will download and install the default version of KubeEdge cloud component

keadm init --kubeedge-version=1.5.0  --kube-config=/root/.kube/config

  - kube-config is the absolute path of kubeconfig which used to secure connectivity between cloudcore and kube-apiserver


Flags:
      --advertise-address string   Use this key to set IPs in cloudcore's certificate SubAltNames field. eg: 10.10.102.78,10.10.102.79
      --domainname string          Use this key to set domain names in cloudcore's certificate SubAltNames field. eg: www.cloudcore.cn,www.kubeedge.cn
  -h, --help                       help for init
      --kube-config string         Use this key to set kube-config path, eg: $HOME/.kube/config (default "/root/.kube/config")
      --kubeedge-version string    Use this key to download and use the required KubeEdge version
      --master string              Use this key to set K8s master address, eg: http://127.0.0.1:8080
      --tarballpath string         Use this key to set the temp directory path for KubeEdge tarball, if not exist, download it

F0211 13:20:41.433946   15198 keadm.go:27] failed to run 'sh -c cd /etc/kubeedge/crds/devices && wget -k --no-check-certificate --progress=bar:force https://raw.githubusercontent.com/kubeedge/kubeedge/master/build/crds/devices/devices_v1alpha2_device.yaml' because of error : exit status 4
goroutine 1 [running]:
k8s.io/klog.stacks(0xc0000d3e00, 0xc000026480, 0x122, 0x176)
	/root/codes/src/github.com/kubeedge/kubeedge/vendor/k8s.io/klog/klog.go:883 +0xb9
k8s.io/klog.(*loggingT).output(0x2cb3c80, 0xc000000003, 0xc0000b4b60, 0x29d13f1, 0x8, 0x1b, 0x0)
	/root/codes/src/github.com/kubeedge/kubeedge/vendor/k8s.io/klog/klog.go:834 +0x35f
k8s.io/klog.(*loggingT).printDepth(0x2cb3c80, 0xc000000003, 0x1, 0xc000843f68, 0x1, 0x1)
	/root/codes/src/github.com/kubeedge/kubeedge/vendor/k8s.io/klog/klog.go:706 +0x12d
k8s.io/klog.(*loggingT).print(...)
	/root/codes/src/github.com/kubeedge/kubeedge/vendor/k8s.io/klog/klog.go:697
k8s.io/klog.Fatal(...)
	/root/codes/src/github.com/kubeedge/kubeedge/vendor/k8s.io/klog/klog.go:1264
main.main()
	/root/codes/src/github.com/kubeedge/kubeedge/keadm/cmd/keadm/keadm.go:27 +0x8a

--advertise-address=xxx.xx.xx.xx 这里的xxx.xx.xx.xx换成你master机器的ip,可以是内网地址,也可以是公网ip地址,--kubeedge-version=1.5.0 意思是指定安装的ke的版本,如果你默认不指定那么keadm会自动去下载最新的版本。很遗憾,我在执行

keadm init --advertise-address=xxx.xx.xx.xx --kubeedge-version=1.5.0

命令的时候出错了,这个错的问题在于网络被墙了,特别是在公有云的虚拟机上,出现这种问题的概率特别大,这种问题咋解决,一种是*翻出去,另外一种是在/etc/hosts下添加如下内容

# GitHub Start
52.74.223.119 github.com
192.30.253.119 gist.github.com
54.169.195.247 api.github.com
185.199.111.153 assets-cdn.github.com
151.101.76.133 raw.githubusercontent.com
151.101.108.133 user-images.githubusercontent.com
151.101.76.133 gist.githubusercontent.com
151.101.76.133 cloud.githubusercontent.com
151.101.76.133 camo.githubusercontent.com
151.101.76.133 avatars0.githubusercontent.com
151.101.76.133 avatars1.githubusercontent.com
151.101.76.133 avatars2.githubusercontent.com
151.101.76.133 avatars3.githubusercontent.com
151.101.76.133 avatars4.githubusercontent.com
151.101.76.133 avatars5.githubusercontent.com
151.101.76.133 avatars6.githubusercontent.com
151.101.76.133 avatars7.githubusercontent.com
151.101.76.133 avatars8.githubusercontent.com
# GitHub End

添加这个的目的就是我们遇到的错误其实就是keadm初始化过程中可能无法解析raw.githubusercontent.com。

如果试了上述方法还是不行,那我只能用杀手锏了,我们回过头看错误

F0211 13:20:41.433946   15198 keadm.go:27] failed to run 'sh -c cd /etc/kubeedge/crds/devices && wget -k --no-check-certificate --progress=bar:force https://raw.githubusercontent.com/kubeedge/kubeedge/master/build/crds/devices/devices_v1alpha2_device.yaml' 

这是下载devices_v1alpha2_device.yaml这个crd的yaml下载不了啊。熟悉源码的朋友一定知道这不就是用于设备接入的CRD嘛。一个叫Devicle,一个叫DeviceModel。其实我的做法就是从源码里把这两个crd搞下来不就好了嘛。

mkdir -p /etc/kubeedge/crds/devices && mkdir -p /etc/kubeedge/crds/reliablesyncs 

按照这个路径创建文件夹 devices和reliablesyncs都是keadm去下载的

cd /etc/kubeedge/crds/devices && vim devices_v1alpha2_devicemodel.yaml ## 创建 evices_v1alpha2_devicemodel.yaml
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
  name: devicemodels.devices.kubeedge.io
spec:
  group: devices.kubeedge.io
  names:
    kind: DeviceModel
    plural: devicemodels
  scope: Namespaced
  validation:
    openAPIV3Schema:
      properties:
        apiVersion:
          description: 'APIVersion defines the versioned schema of this representation
            of an object. Servers should convert recognized schemas to the latest
            internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#resources'
          type: string
        kind:
          description: 'Kind is a string value representing the REST resource this
            object represents. Servers may infer this from the endpoint the client
            submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds'
          type: string
        metadata:
          type: object
        spec:
          properties:
            properties:
              description: 'Required: List of device properties.'
              items:
                properties:
                  description:
                    description: The device property description.
                    type: string
                  name:
                    description: 'Required: The device property name.'
                    type: string
                  type:
                    description: 'Required: PropertyType represents the type and data
                      validation of the property.'
                    properties:
                      int:
                        properties:
                          accessMode:
                            description: 'Required: Access mode of property, ReadWrite
                              or ReadOnly.'
                            type: string
                            enum:
                              - ReadOnly
                              - ReadWrite
                          defaultValue:
                            format: int64
                            type: integer
                          maximum:
                            format: int64
                            type: integer
                          minimum:
                            format: int64
                            type: integer
                          unit:
                            description: The unit of the property
                            type: string
                        required:
                          - accessMode
                        type: object
                      string:
                        properties:
                          accessMode:
                            description: 'Required: Access mode of property, ReadWrite
                              or ReadOnly.'
                            type: string
                            enum:
                              - ReadOnly
                              - ReadWrite
                          defaultValue:
                            type: string
                        required:
                          - accessMode
                        type: object
                      double:
                        properties:
                          accessMode:
                            description: 'Required: Access mode of property, ReadWrite
                              or ReadOnly.'
                            type: string
                            enum:
                              - ReadOnly
                              - ReadWrite
                          defaultValue:
                            format: double
                            type: number
                          maximum:
                            format: double
                            type: number
                          minimum:
                            format: double
                            type: number
                          unit:
                            description: The unit of the property
                            type: string
                        required:
                          - accessMode
                        type: object
                      float:
                        properties:
                          accessMode:
                            description: 'Required: Access mode of property, ReadWrite
                              or ReadOnly.'
                            type: string
                            enum:
                              - ReadOnly
                              - ReadWrite
                          defaultValue:
                            format: float
                            type: number
                          maximum:
                            format: float
                            type: number
                          minimum:
                            format: float
                            type: number
                          unit:
                            description: The unit of the property
                            type: string
                        required:
                          - accessMode
                        type: object
                      boolean:
                        properties:
                          accessMode:
                            description: 'Required: Access mode of property, ReadWrite
                              or ReadOnly.'
                            type: string
                            enum:
                              - ReadOnly
                              - ReadWrite
                          defaultValue:
                            type: boolean
                        required:
                          - accessMode
                        type: object
                      bytes:
                        properties:
                          accessMode:
                            description: 'Required: Access mode of property, ReadWrite
                              or ReadOnly.'
                            type: string
                            enum:
                              - ReadOnly
                              - ReadWrite
                        required:
                          - accessMode
                        type: object
                    type: object
                required:
                  - name
                  - type
                type: object
              type: array
          type: object
  version: v1alpha2
cd /etc/kubeedge/crds/devices && vim devices_v1alpha2_device.yaml
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
  labels:
    controller-tools.k8s.io: "1.0"
  name: devices.devices.kubeedge.io
spec:
  group: devices.kubeedge.io
  names:
    kind: Device
    plural: devices
  scope: Namespaced
  validation:
    openAPIV3Schema:
      properties:
        apiVersion:
          description: 'APIVersion defines the versioned schema of this representation
            of an object. Servers should convert recognized schemas to the latest
            internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#resources'
          type: string
        kind:
          description: 'Kind is a string value representing the REST resource this
            object represents. Servers may infer this from the endpoint the client
            submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds'
          type: string
        metadata:
          type: object
        spec:
          properties:
            deviceModelRef:
              description: 'Required: DeviceModelRef is reference to the device model
                used as a template to create the device instance.'
              type: object
            nodeSelector:
              description: NodeSelector indicates the binding preferences between
                devices and nodes. Refer to k8s.io/kubernetes/pkg/apis/core NodeSelector
                for more details
              type: object
            protocol:
              description: 'Required: The protocol configuration used to connect to
                the device.'
              properties:
                bluetooth:
                  description: Protocol configuration for bluetooth
                  properties:
                    macAddress:
                      description: Unique identifier assigned to the device.
                      type: string
                  type: object
                modbus:
                  description: Protocol configuration for modbus
                  properties:
                    slaveID:
                      description: Required. 0-255
                      format: int64
                      type: integer
                      minimum: 0
                      maximum: 255
                  required:
                    - slaveID
                  type: object
                opcua:
                  description: Protocol configuration for opc-ua
                  properties:
                    certificate:
                      description: Certificate for access opc server.
                      type: string
                    password:
                      description: Password for access opc server.
                      type: string
                    privateKey:
                      description: PrivateKey for access opc server.
                      type: string
                    securityMode:
                      description: Defaults to "none".
                      type: string
                    securityPolicy:
                      description: Defaults to "none".
                      type: string
                    timeout:
                      description: Timeout seconds for the opc server connection.???
                      format: int64
                      type: integer
                    url:
                      description: 'Required: The URL for opc server endpoint.'
                      type: string
                    userName:
                      description: Username for access opc server.
                      type: string
                  required:
                    - url
                  type: object
                common:
                  description: Common part of protocol configuration
                  properties:
                    com:
                      properties:
                        baudRate:
                          description: Required. BaudRate 115200|57600|38400|19200|9600|4800|2400|1800|1200|600|300|200|150|134|110|75|50
                          format: int64
                          type: integer
                          enum:
                            - 115200
                            - 57600
                            - 38400
                            - 19200
                            - 9600
                            - 4800
                            - 2400
                            - 1800
                            - 1200
                            - 600
                            - 300
                            - 200
                            - 150
                            - 134
                            - 110
                            - 75
                            - 50
                        dataBits:
                          description: Required. Valid values are 8, 7, 6, 5.
                          format: int64
                          type: integer
                          enum:
                            - 8
                            - 7
                            - 6
                            - 5
                        parity:
                          description: Required. Valid options are "none", "even",
                            "odd". Defaults to "none".
                          type: string
                          enum:
                            - none
                            - even
                            - odd
                        serialPort:
                          description: Required.
                          type: string
                        stopBits:
                          description: Required. Bit that stops 1|2
                          format: int64
                          type: integer
                          enum:
                            - 1
                            - 2
                      required:
                        - baudRate
                        - dataBits
                        - parity
                        - serialPort
                        - stopBits
                      type: object
                    tcp:
                      properties:
                        ip:
                          description: Required.
                          type: string
                        port:
                          description: Required.
                          format: int64
                          type: integer
                      required:
                        - ip
                        - port
                      type: object
                    commType:
                      description: Communication type, like tcp client, tcp server or COM
                      type: string
                    reconnTimeout:
                      description: Reconnection timeout
                      type: integer
                    reconnRetryTimes:
                      description: Reconnecting retry times
                      type: integer
                    collectTimeout:
                      description: 'Define timeout of mapper collect from device.'
                      format: int64
                      type: integer
                    collectRetryTimes:
                      description: 'Define retry times of mapper will collect from device.'
                      format: int64
                      type: integer
                    collectType:
                      description: 'Define collect type, sync or async.'
                      type: string
                      enum:
                        - sync
                        - async
                    customizedValues:
                      description: Customized values for provided protocol
                      type: object
                  type: object
                customizedProtocol:
                  description: Protocol configuration for customized Protocol
                  properties:
                    protocolName:
                      description: The name of protocol
                      type: string
                    configData:
                      description: customized config data
                      type: object
                  required:
                    - protocolName
                  type: object
              type: object
            propertyVisitors:
              description: 'Required: List of property visitors which describe how
                to access the device properties. PropertyVisitors must unique by propertyVisitor.propertyName.'
              items:
                properties:
                  bluetooth:
                    description: Bluetooth represents a set of additional visitor
                      config fields of bluetooth protocol.
                    properties:
                      characteristicUUID:
                        description: 'Required: Unique ID of the corresponding operation'
                        type: string
                      dataConverter:
                        description: Responsible for converting the data being read
                          from the bluetooth device into a form that is understandable
                          by the platform
                        properties:
                          endIndex:
                            description: 'Required: Specifies the end index of incoming
                              byte stream to be considered to convert the data the
                              value specified should be inclusive for example if 3
                              is specified it includes the third index'
                            format: int64
                            type: integer
                          orderOfOperations:
                            description: Specifies in what order the operations(which
                              are required to be performed to convert incoming data
                              into understandable form) are performed
                            items:
                              properties:
                                operationType:
                                  description: 'Required: Specifies the operation
                                    to be performed to convert incoming data'
                                  type: string
                                  enum:
                                    - Add
                                    - Subtract
                                    - Multiply
                                    - Divide
                                operationValue:
                                  description: 'Required: Specifies with what value
                                    the operation is to be performed'
                                  format: double
                                  type: number
                              type: object
                            type: array
                          shiftLeft:
                            description: Refers to the number of bits to shift left,
                              if left-shift operation is necessary for conversion
                            format: int64
                            type: integer
                          shiftRight:
                            description: Refers to the number of bits to shift right,
                              if right-shift operation is necessary for conversion
                            format: int64
                            type: integer
                          startIndex:
                            description: 'Required: Specifies the start index of the
                              incoming byte stream to be considered to convert the
                              data. For example: start-index:2, end-index:3 concatenates
                              the value present at second and third index of the incoming
                              byte stream. If we want to reverse the order we can
                              give it as start-index:3, end-index:2'
                            format: int64
                            type: integer
                        required:
                          - endIndex
                          - startIndex
                        type: object
                      dataWrite:
                        description: 'Responsible for converting the data coming from
                          the platform into a form that is understood by the bluetooth
                          device For example: "ON":[1], "OFF":[0]'
                        type: object
                    required:
                      - characteristicUUID
                    type: object
                  modbus:
                    description: Modbus represents a set of additional visitor config
                      fields of modbus protocol.
                    properties:
                      isRegisterSwap:
                        description: Indicates whether the high and low register swapped.
                          Defaults to false.
                        type: boolean
                      isSwap:
                        description: Indicates whether the high and low byte swapped.
                          Defaults to false.
                        type: boolean
                      limit:
                        description: 'Required: Limit number of registers to read/write.'
                        format: int64
                        type: integer
                      offset:
                        description: 'Required: Offset indicates the starting register
                          number to read/write data.'
                        format: int64
                        type: integer
                      register:
                        description: 'Required: Type of register'
                        type: string
                        enum:
                          - CoilRegister
                          - DiscreteInputRegister
                          - InputRegister
                          - HoldingRegister
                      scale:
                        description: The scale to convert raw property data into final
                          units. Defaults to 1.0
                        format: double
                        type: number
                    required:
                      - limit
                      - offset
                      - register
                    type: object
                  opcua:
                    description: Opcua represents a set of additional visitor config
                      fields of opc-ua protocol.
                    properties:
                      browseName:
                        description: The name of opc-ua node
                        type: string
                      nodeID:
                        description: 'Required: The ID of opc-ua node, e.g. "ns=1,i=1005"'
                        type: string
                    required:
                      - nodeID
                    type: object
                  customizedProtocol:
                    description: customized protocol
                    properties:
                      protocolName:
                        description: The name of protocol
                        type: string
                      configData:
                        description: customized config data
                        type: object
                    required:
                      - protocolName
                      - configData
                    type: object
                  propertyName:
                    description: 'Required: The device property name to be accessed.
                      This should refer to one of the device properties defined in
                      the device model.'
                    type: string
                  reportCycle:
                    description: 'Define how frequent mapper will report the value.'
                    format: int64
                    type: integer
                  collectCycle:
                    description: 'Define how frequent mapper will collect from device.'
                    format: int64
                    type: integer
                  customizedValues:
                    description: Customized values for visitor of provided protocols
                    type: object
                required:
                  - propertyName
                type: object
              type: array
            data:
              properties:
                dataTopic:
                  description: 'Topic used by mapper, all data collected from dataProperties
                    should be published to this topic,
                    the default value is $ke/events/device/+/data/update'
                  type: string
                dataProperties:
                  description: A list of data properties, which are not required to be processed by edgecore
                  items:
                    properties:
                      propertyName:
                        description: 'Required: The property name for which the desired/reported
                          values are specified. This property should be present in the
                          device model.'
                        type: string
                      metadata:
                        description: Additional metadata like filter policy, should be k-v format
                        type: object
                    required:
                      - propertyName
                    type: object
                  type: array
              type: object
          required:
            - deviceModelRef
            - nodeSelector
          type: object
        status:
          properties:
            twins:
              description: A list of device twins containing desired/reported desired/reported
                values of twin properties. A passive device won't have twin properties
                and this list could be empty.
              items:
                properties:
                  desired:
                    description: 'Required: the desired property value.'
                    properties:
                      metadata:
                        description: Additional metadata like timestamp when the value
                          was reported etc.
                        type: object
                      value:
                        description: 'Required: The value for this property.'
                        type: string
                    required:
                      - value
                    type: object
                  propertyName:
                    description: 'Required: The property name for which the desired/reported
                      values are specified. This property should be present in the
                      device model.'
                    type: string
                  reported:
                    description: 'Required: the reported property value.'
                    properties:
                      metadata:
                        description: Additional metadata like timestamp when the value
                          was reported etc.
                        type: object
                      value:
                        description: 'Required: The value for this property.'
                        type: string
                    required:
                      - value
                    type: object
                required:
                  - propertyName
                type: object
              type: array
          type: object
  version: v1alpha2

device的crd好了,现在去弄reliablesyncs的crd还是一样

cd /etc/kubeedge/crds/reliablesyncs && vim cluster_objectsync_v1alpha1.yaml
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
  labels:
    controller-tools.k8s.io: "1.0"
  name: clusterobjectsyncs.reliablesyncs.kubeedge.io
spec:
  group: reliablesyncs.kubeedge.io
  names:
    kind: ClusterObjectSync
    plural: clusterobjectsyncs
  scope: Cluster
  subresources:
    status: {}
  validation:
    openAPIV3Schema:
      properties:
        apiVersion:
          description: 'APIVersion defines the versioned schema of this representation
            of an object. Servers should convert recognized schemas to the latest
            internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#resources'
          type: string
        kind:
          description: 'Kind is a string value representing the REST resource this
            object represents. Servers may infer this from the endpoint the client
            submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds'
          type: string
        metadata:
          type: object
        spec:
          properties:
            objectType:
              description: NodeSelector indicates the binding preferences between
                devices and nodes. Refer to k8s.io/kubernetes/pkg/apis/core NodeSelector
                for more details
              type: string
            objectName:
              description: 'Required: The protocol configuration used to connect to
                the device.'
              type: string
        status:
          properties:
            objectResourceVersion:
              description: 'Required: DeviceModelRef is reference to the device model
                            used as a template to create the device instance.'
              type: string
  version: v1alpha
cd /etc/kubeedge/crds/reliablesyncs && vim objectsync_v1alpha1.yaml
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
  labels:
    controller-tools.k8s.io: "1.0"
  name: objectsyncs.reliablesyncs.kubeedge.io
spec:
  group: reliablesyncs.kubeedge.io
  names:
    kind: ObjectSync
    plural: objectsyncs
  scope: Namespaced
  subresources:
    status: {}
  validation:
    openAPIV3Schema:
      properties:
        apiVersion:
          description: 'APIVersion defines the versioned schema of this representation
            of an object. Servers should convert recognized schemas to the latest
            internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#resources'
          type: string
        kind:
          description: 'Kind is a string value representing the REST resource this
            object represents. Servers may infer this from the endpoint the client
            submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds'
          type: string
        metadata:
          type: object
        spec:
          properties:
            objectType:
              description: NodeSelector indicates the binding preferences between
                devices and nodes. Refer to k8s.io/kubernetes/pkg/apis/core NodeSelector
                for more details
              type: string
            objectName:
              description: 'Required: The protocol configuration used to connect to
                the device.'
              type: string
        status:
          properties:
            objectResourceVersion:
              description: 'Required: DeviceModelRef is reference to the device model
                           used as a template to create the device instance.'
              type: string
  version: v1alpha1#

还有一个事情要提前说下,这些crd都准备好了之后,keadm会去下载kubedge的资源。我们实现准备好的话是不是就可以啦,主要还是怕你网络不行,网络ok的话就没有这个问题。

在 /etc/kubeedge下面执行

wget https://github.com/kubeedge/kubeedge/releases/download/v1.5.0/kubeedge-v1.5.0-linux-amd64.tar.gz
## 因为的机器是x86架构的处理器,所以是amd64,如果你是别的那就改下这个就行了。

这些都创建完了之后再次执行

keadm init --advertise-address=xxx.xx.xx.xx --kubeedge-version=1.5.0
Kubernetes version verification passed, KubeEdge installation will start...
W0211 13:58:27.853894   23320 warnings.go:67] apiextensions.k8s.io/v1beta1 CustomResourceDefinition is deprecated in v1.16+, unavailable in v1.22+; use apiextensions.k8s.io/v1 CustomResourceDefinition
W0211 13:58:27.862976   23320 warnings.go:67] apiextensions.k8s.io/v1beta1 CustomResourceDefinition is deprecated in v1.16+, unavailable in v1.22+; use apiextensions.k8s.io/v1 CustomResourceDefinition
W0211 13:58:27.870072   23320 warnings.go:67] apiextensions.k8s.io/v1beta1 CustomResourceDefinition is deprecated in v1.16+, unavailable in v1.22+; use apiextensions.k8s.io/v1 CustomResourceDefinition
W0211 13:58:27.876587   23320 warnings.go:67] apiextensions.k8s.io/v1beta1 CustomResourceDefinition is deprecated in v1.16+, unavailable in v1.22+; use apiextensions.k8s.io/v1 CustomResourceDefinition
Expected or Default KubeEdge version 1.5.0 is already downloaded and will checksum for it.
kubeedge-v1.5.0-linux-amd64.tar.gz checksum:
checksum_kubeedge-v1.5.0-linux-amd64.tar.gz.txt content:
[Run as service] start to download service file for cloudcore
Output failed:  exit status 4
Error: fail to download service file,error:{failed to run command(cd /etc/kubeedge/ && sudo -E wget -t 5 -k --no-check-certificate https://raw.githubusercontent.com/kubeedge/kubeedge/release-1.5/build/tools/cloudcore.service), err:exit status 4}
Usage:
  keadm init [flags]

Examples:

keadm init

- This command will download and install the default version of KubeEdge cloud component

keadm init --kubeedge-version=1.5.0  --kube-config=/root/.kube/config

  - kube-config is the absolute path of kubeconfig which used to secure connectivity between cloudcore and kube-apiserver


Flags:
      --advertise-address string   Use this key to set IPs in cloudcore's certificate SubAltNames field. eg: 10.10.102.78,10.10.102.79
      --domainname string          Use this key to set domain names in cloudcore's certificate SubAltNames field. eg: www.cloudcore.cn,www.kubeedge.cn
  -h, --help                       help for init
      --kube-config string         Use this key to set kube-config path, eg: $HOME/.kube/config (default "/root/.kube/config")
      --kubeedge-version string    Use this key to download and use the required KubeEdge version
      --master string              Use this key to set K8s master address, eg: http://127.0.0.1:8080
      --tarballpath string         Use this key to set the temp directory path for KubeEdge tarball, if not exist, download it

F0211 13:58:30.352570   23320 keadm.go:27] fail to download service file,error:{failed to run command(cd /etc/kubeedge/ && sudo -E wget -t 5 -k --no-check-certificate https://raw.githubusercontent.com/kubeedge/kubeedge/release-1.5/build/tools/cloudcore.service), err:exit status 4}
goroutine 1 [running]:
k8s.io/klog.stacks(0xc000599300, 0xc0008ce2c0, 0x11a, 0x2a4)
	/root/codes/src/github.com/kubeedge/kubeedge/vendor/k8s.io/klog/klog.go:883 +0xb9
k8s.io/klog.(*loggingT).output(0x2cb3c80, 0xc000000003, 0xc0002f2850, 0x29d13f1, 0x8, 0x1b, 0x0)
	/root/codes/src/github.com/kubeedge/kubeedge/vendor/k8s.io/klog/klog.go:834 +0x35f
k8s.io/klog.(*loggingT).printDepth(0x2cb3c80, 0xc000000003, 0x1, 0xc00089ff68, 0x1, 0x1)
	/root/codes/src/github.com/kubeedge/kubeedge/vendor/k8s.io/klog/klog.go:706 +0x12d
k8s.io/klog.(*loggingT).print(...)
	/root/codes/src/github.com/kubeedge/kubeedge/vendor/k8s.io/klog/klog.go:697
k8s.io/klog.Fatal(...)
	/root/codes/src/github.com/kubeedge/kubeedge/vendor/k8s.io/klog/klog.go:1264
main.main()
	/root/codes/src/github.com/kubeedge/kubeedge/keadm/cmd/keadm/keadm.go:27 +0x8a

到了最后还是出了一个问题,还是网络的问题啊,意思是cloudcore的service文件下载不了,那没办法了,手动创建咯。

vim cloudcore.service
[Unit]
Description=cloudcore.service

[Service]
Type=simple
ExecStart=/etc/kubeedge/kubeedge-v1.5.0-linux-amd64/cloud/cloudcore/cloudcore --logtostderr=false --log-file=/var/log/kubeedge/cloudcore.log -v=3
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target

然后我们再执行

$ keadm init --advertise-address=106.13.177.82 --kubeedge-version=1.5.0
Kubernetes version verification passed, KubeEdge installation will start...
W0211 14:04:38.942389   29815 warnings.go:67] apiextensions.k8s.io/v1beta1 CustomResourceDefinition is deprecated in v1.16+, unavailable in v1.22+; use apiextensions.k8s.io/v1 CustomResourceDefinition
W0211 14:04:38.950811   29815 warnings.go:67] apiextensions.k8s.io/v1beta1 CustomResourceDefinition is deprecated in v1.16+, unavailable in v1.22+; use apiextensions.k8s.io/v1 CustomResourceDefinition
W0211 14:04:38.966118   29815 warnings.go:67] apiextensions.k8s.io/v1beta1 CustomResourceDefinition is deprecated in v1.16+, unavailable in v1.22+; use apiextensions.k8s.io/v1 CustomResourceDefinition
W0211 14:04:38.975750   29815 warnings.go:67] apiextensions.k8s.io/v1beta1 CustomResourceDefinition is deprecated in v1.16+, unavailable in v1.22+; use apiextensions.k8s.io/v1 CustomResourceDefinition
Expected or Default KubeEdge version 1.5.0 is already downloaded and will checksum for it.
kubeedge-v1.5.0-linux-amd64.tar.gz checksum:
checksum_kubeedge-v1.5.0-linux-amd64.tar.gz.txt content:
[Run as service] service file already exisits in /etc/kubeedge//cloudcore.service, skip download
kubeedge-v1.5.0-linux-amd64/
kubeedge-v1.5.0-linux-amd64/edge/
kubeedge-v1.5.0-linux-amd64/edge/edgecore
kubeedge-v1.5.0-linux-amd64/cloud/
kubeedge-v1.5.0-linux-amd64/cloud/csidriver/
kubeedge-v1.5.0-linux-amd64/cloud/csidriver/csidriver
kubeedge-v1.5.0-linux-amd64/cloud/admission/
kubeedge-v1.5.0-linux-amd64/cloud/admission/admission
kubeedge-v1.5.0-linux-amd64/cloud/cloudcore/
kubeedge-v1.5.0-linux-amd64/cloud/cloudcore/cloudcore
kubeedge-v1.5.0-linux-amd64/version

KubeEdge cloudcore is running, For logs visit:  /var/log/kubeedge/cloudcore.log
CloudCore started

这就表示cloudcore已经安装完成了

3. 校验cloudcore安装情况

1. 检查进程的运行情况

$ ps aux | grep cloudcore
root       599  0.0  0.0  16188  1012 pts/0    S+   14:07   0:00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn --exclude-dir=.idea --exclude-dir=.tox cloudcore
root     32150  0.8  1.2 1269852 51632 ?       Ssl  14:06   0:00 /etc/kubeedge/kubeedge-v1.5.0-linux-amd64/cloud/cloudcore/cloudcore --logtostderr=false --log-file=/var/log/kubeedge/cloudcore.log -v=3

如果你想把cloudcore交给systemed托管的话切记把cloudcore.service移到/etc/systemed/system下面然后再执行下systemctl daemon-reload

2. 查看k8s

正常的情况下cloudcore运行起来之后会在k8s器群创建一个叫kubeedge的namespace,这个ns下面有secret,存的就是ke集群的token cert啥的

$ k get secret -nkubeedge
NAME                  TYPE                                  DATA   AGE
casecret              Opaque                                2      21h
cloudcoresecret       Opaque                                2      21h
default-token-bt26c   kubernetes.io/service-account-token   3      21h
tokensecret           Opaque                                1      21h

如果你的结果和我的一样,恭喜你,你的ke的cloudcore已经顺利安装完成了。

5. 安装edgecore

edgecore的安装相比cloudcore而言简单很多,不过我们还是要靠keadm这个工具,先在边缘节点上安装keadm,安装方式和上面cloudcore的一样,这里就不重复说了。如果你的边缘节点的网络不是很好的话还是建议提早下载好ke的资源文件,和安装cloudcore的时候一样

mkdir -p /etc/kubeedge && wget https://github.com/kubeedge/kubeedge/releases/download/v1.5.0/kubeedge-v1.5.0-linux-arm.tar.gz
## 我用树莓派作为边缘节点的,所以下载的是arm架构的

直接执行

keadm join --cloudcore-ipport=xx.xx.xx.xx:10000 --kubeedge-version=1.5.0 --token=<token>

-cloudcore-ipport表示的是cloudcore的对外暴露的ip就是公网ip了,记得打开安全组的端口如果你是在公有云服务器上的

--kubeedge-version就是ke的版本

--token= 这个token从master机器上来,执行

$ keadm gettoken
b75afee838d35d8208a6880381ceca1aa1a1d72e289d307723da210a87cc6bf0.eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2MTMxMTAwMTJ9.jtrC0EBjuq3VpwIGQ21a5aPq5dr3wJniH6XGVnu_rKE

下面的这一大串就是token,这个token就是用于去拿ca证书的。

6. 检查ke集群是否安装完成

在master机器上执行

$ k get no
NAME          STATUS   ROLES        AGE     VERSION
didi-cloud    Ready    <none>       3d15h   v1.19.7
k8s-master    Ready    master       4d      v1.19.7
raspberrypi   Ready    agent,edge   16h     v1.19.3-kubeedge-v1.5.0

树莓派就是ke的边缘节点,并且已经是ready,如果你的结果和我一样,那么恭喜你,你的ke的集群已经搭建完成了。

上一篇:bps(bitspersecond)是什么?


下一篇:C#中word导出功能骚操作