全部产品
阿里云办公

部署Virtual Kubelet

更新时间:2019-01-04 10:13:44

本文演示如何部署Virtual Kubelet,分源码编译和yaml配置两种方式,建议采用yaml配置方式进行部署,源码编译方式可提供功能有限。

说明: 以下内容均需要先开通ECI服务,然后在配置有kubernetes config的机器上操作,需要注意的是kubernetes集群务必在 ECI可用区 内。

1、源码编译

前提

具备go开发编译环境

操作步骤

1、在$GO_PATH下创建代码工作目录

  1. cd $GO_PATH && mkdir $GO_PATH/src && cd src
  2. mkdir -p github.com/virtual-kubelet

2、下载virtual-kubelet源码

  1. git clone https://github.com/virtual-kubelet/virtual-kubelet.git

3、编译代码

  1. make build

4、 编译完成后,生成bin/virtual-kubelet二进制文件

5、 启动virtual-kubelet

说明: $VKUBELET_POD_IP在容器组 CIDR

  1. export ECI_REGION=cn-xxxx
  2. export ECI_SECURITY_GROUP=sg-xxxx
  3. export ECI_VSWITCH=vsw-xxxx
  4. export ECI_ACCESS_KEY=xxxx
  5. export ECI_SECRET_KEY=xxxx
  6. export KUBELET_PORT=10250
  7. export VKUBELET_POD_IP=xxxx
  8. export VKUBELET_TAINT_VALUE="alibabacloud"
  9. export VKUBELET_TAINT_EFFECT=NoSchedule
  10. VKUBELET_TAINT_KEY=virtual-kubelet.io/provider bin/virtual-kubelet --provider alibabacloud --provider-config ./providers/alibabacloud/eci.toml

6、查看执行结果

  1. # kubectl get nodes -o wide
  2. NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
  3. cn-beijing.i-2zegk2mcxe9rokabn88p Ready <none> 4d v1.11.2 192.168.1.13 <none> CentOS Linux 7 (Core) 3.10.0-693.2.2.el7.x86_64 docker://17.6.2
  4. cn-beijing.i-2zegk2mcxe9rokabn88q Ready <none> 4d v1.11.2 192.168.1.12 <none> CentOS Linux 7 (Core) 3.10.0-693.2.2.el7.x86_64 docker://17.6.2
  5. virtual-kubelet Ready agent 4d v1.11.2 172.16.0.130 <none> <unknown> <unknown> <unknown>

参考链接

https://github.com/virtual-kubelet/virtual-kubelet#usage

https://github.com/virtual-kubelet/virtual-kubelet/blob/master/providers/alicloud/README.md

2、yaml配置

1、使用kubectl一键部署virtual kubelet虚拟节点

请替换alicloud-virtual-kubelet.yaml文件中的ECI_REGION、ECI_VSWITCH、ECI_SECURITY_GROUP、ECI_ACCESS_KEY、ECI_SECRET_KEY环境变量

  1. # cat alicloud-virtual-kubelet.yaml
  2. apiVersion: v1
  3. kind: ServiceAccount
  4. metadata:
  5. name: alicloud-virtual-kubelet
  6. namespace: default
  7. ---
  8. apiVersion: rbac.authorization.k8s.io/v1beta1
  9. kind: ClusterRoleBinding
  10. metadata:
  11. name: alicloud-virtual-kubelet
  12. namespace: default
  13. roleRef:
  14. apiGroup: rbac.authorization.k8s.io
  15. kind: ClusterRole
  16. name: cluster-admin
  17. subjects:
  18. - kind: ServiceAccount
  19. name: alicloud-virtual-kubelet
  20. namespace: default
  21. ---
  22. apiVersion: apps/v1beta2
  23. kind: Deployment
  24. metadata:
  25. name: alicloud-virtual-kubelet
  26. namespace: default
  27. labels:
  28. app: alicloud-virtual-kubelet
  29. spec:
  30. replicas: 1
  31. selector:
  32. matchLabels:
  33. app: alicloud-virtual-kubelet
  34. template:
  35. metadata:
  36. labels:
  37. app: alicloud-virtual-kubelet
  38. spec:
  39. serviceAccount: alicloud-virtual-kubelet
  40. containers:
  41. - name: alicloud-virtual-kubelet
  42. image: registry.cn-hangzhou.aliyuncs.com/ask/virtual-nodes-eci:v1.0.0.1-aliyun
  43. imagePullPolicy: Always
  44. args: ["--provider", "alibabacloud"]
  45. env:
  46. - name: KUBELET_PORT
  47. value: "10250"
  48. - name: VKUBELET_POD_IP
  49. valueFrom:
  50. fieldRef:
  51. fieldPath: status.podIP
  52. - name: VKUBELET_TAINT_KEY
  53. value: "virtual-kubelet.io/provider"
  54. - name: VKUBELET_TAINT_VALUE
  55. value: "alibabacloud"
  56. - name: VKUBELET_TAINT_EFFECT
  57. value: "NoSchedule"
  58. - name: ECI_REGION
  59. value: "cn-xxxx"
  60. - name: ECI_VSWITCH
  61. value: "vsw-xxxxxxxxxxx"
  62. - name: ECI_SECURITY_GROUP
  63. value: "sg-xxxxxxxxxxx"
  64. - name: ECI_ACCESS_KEY
  65. value: "xxxxxxxxxxxxx"
  66. - name: ECI_SECRET_KEY
  67. value: "xxxxxxxxxxxxx"

2、 执行yaml文件,然后查看pod和节点状态,可以发现,集群中已经添加了一个新的virtual-kubelet虚拟节点

  1. # kubectl apply -f ./alicloud-virtual-kubelet.yaml
  2. serviceaccount "alicloud-virtual-kubelet" created
  3. clusterrolebinding "alicloud-virtual-kubelet" created
  4. deployment "alicloud-virtual-kubelet" created
  1. # kubectl get node
  2. NAME STATUS ROLES AGE VERSION
  3. cn-hangzhou.i-bp19cyop0b1skne04djt Ready <none> 10m v1.11.2
  4. cn-hangzhou.i-bp19cyop0b1skne04dju Ready <none> 10m v1.11.2
  5. cn-hangzhou.i-bp19cyop0b1skne04djv Ready <none> 10m v1.11.2
  6. virtual-kubelet Ready agent 55s v1.11.2

3、通过控制台,同样可以看到virtual-kubelet虚拟节点的存在。 virtal-kubelet-console