13

Jingzhao · 2019年10月10日

搭建基于Arm的kubernetes+Istio开发环境

随着云计算的普及,越来越多的公司、组织及个人开发者开始将业务转移至云服务提供商(如Ali,GKE,Amazon)。然而,在云计算带来便利的同时,也给开发团队带来了不小的挑战。比如,如何将传统单一应用拆分成多个微服务,实现各个微服务之间的松耦合,高内聚,如何实现各个微服务的通信,同步等。Service Mesh技术很好的解决了这些问题,Service Mesh通过代理技术,使各个模块之间解耦合,另一方面,又通过Service Function Chain将各个服务有机的连接在一起,从而组合实现复杂的功能。
在这篇文章中,我们将介绍如何在Arm平台上,利用Istio,搭建一个基于Kubernetes的Service Mesh平台。

流程
环境要求
准备配置环境
编译生成镜像
搭建Kubernetes 环境
配置安装Istio

环境要求
a. 至少两台Arm64主机(欢迎使用Raspberry Pi)
b. Ubuntu 16.04 或者是 Ubuntu 18.04 操作系统
c. 网络连接(方便安装各种软件)
说明:如果你仅有一台主机,也可以通过virt-manage 来创建两台虚拟Arm主机进行搭建。

准备配置环境
Istio软件由Pilot, Mixer, Istio-Auth以及proxy几个模块组成,其中proxy是由c++编写而成的,因此我们首先安装一些C++工具链,然后再安装golang工具链
a. 安装C++工具链

sudo apt-get install \
   libtool \
   cmake \
   clang-format-8 \
   automake \
   autoconf \
   make \
   ninja-build \
   curl \
   unzip \
   virtualenv

安装clang

wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key|sudo apt-key add -
# LLVM
apt-get install libllvm-8-ocaml-dev libllvm8 llvm-8 llvm-8-dev llvm-8-doc llvm-8-examples llvm-8-runtime
# Clang and co
apt-get install clang-8 clang-tools-8 clang-8-doc libclang-common-8-dev libclang-8-dev libclang1-8 clang-format-8 python-clang-8 clangd-8
# libfuzzer
apt-get install libfuzzer-8-dev
# lldb
apt-get install lldb-8
# lld (linker)
apt-get install lld-8
# libc++
apt-get install libc++-8-dev libc++abi-8-dev
# OpenMP
apt-get install libomp-8-dev

安装bazel 0.28.0
由于bazel官方没有提供arm64版本,因此我们从PPA上面找到相应的版本进行安装

# Ubuntu 16.04 (LTS) uses OpenJDK 8 by default:
# sudo apt-get install openjdk-8-jdk
# Ubuntu 18.04 (LTS) uses OpenJDK 11 by default:
sudo apt-get install openjdk-11-jdk
sudo add-apt-repository ppa:kingofcodecplusplus/bazel
sudo apt-get update
apt install bazel

修改环境变量

echo "CC=/usr/bin/clang" >> ~/.bashrc
echo "CXX=/usr/bin/clang++" >> ~/.bashrc

b. 安装golang (gotool.sh附在文章最后)

./gotool.sh --arm64

各个工具安装成功之后,下面开始编译生成可执行文件以及docker image

编译生成Istio可执行文件及docker image
克隆代码:

$ ~/.go/src/$ mkdir istio.io
$ ~/.go/src/istio.io$ git clone https://github.com/istio/proxy.git
$ ~/.go/src/istio.io$ git clone https://github.com/istio/istio.git

需要注意的是,此处不可以直接使用envoy直接来进行编译,因为Istio的proxy模块中,不仅包含了envoy,而且还有一个用于接收处理来自Mixer命令的代理。如果缺少此模块,将会导致一下错误:

[source/server/server.cc:92] error initializing configuration '/etc/istio/proxy/envoy.yaml': Didn't find a registered implementation for name: 'mixer' Didn't find a registered implementation for name: 'mixer'
2019-08-07T06:36:44.476075Z warn Epoch 0 terminated with an error: exit status 1

检查编译环境:

$ ~/.go/src/istio.io/istio$ bazel --version
bazel 0.28.1- (@non-git)
$ ~/.go/src/istio.io/istio$ clang --version
clang version 7.0.0-3~ubuntu0.18.04.1 (tags/RELEASE_700/final)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

编译Istio-proxy:

$ ~/.go/src/istio.io/proxy$ pwd
/home/jingzhao/.go/src/istio.io/proxy
$ ~/.go/src/istio.io/proxy$ git checkout 9e5640ad290377b406d15b9a59f2c3f56af17323
$ ~/.go/src/istio.io/proxy$ make
$ ~/.go/src/istio.io/proxy$ ls bazel-out/aarch64-fastbuild/bin/src/envoy/envoy -l
-r-xr-xr-x 1 jingzhao jingzhao 107015072 Aug 7 11:58 bazel-out/aarch64-fastbuild/bin/src/envoy/envoy

编译Istio其他组件:
由于Istio的bug,导致其在Arm64平台上编译出现一些问题,我们首先打上相应的补丁,然后进行编译。

$ ~/.go/src/istio.io/istio$ git checkout 86deb8bdd0e4c8fce367baabce1789fed3111ed4
$ ~/.go/src/istio.io/istio$ git apply 0001-Add-arm64-supportted.patch
$ ~/.go/src/istio.io/istio$ git status
HEAD detached at 86deb8bdd
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)
 
        modified:   Makefile
        modified:   bin/init.sh
        modified:   docker/Dockerfile.kubectl
        modified:   go.sum
        modified:   pilot/docker/Dockerfile.proxy_init
 
Untracked files:
  (use "git add <file>..." to include in what will be committed)
        0001-Add-arm64-supportted.patch
no changes added to commit (use "git add" and/or "git commit -a")

编译Istio的可执行文件以及Docker image:

$ ~/.go/src/istio.io/istio$ make build #Build Binary file
$ ~/.go/src/istio.io/istio$ make docker #Generate the docker file
$ ~/.go/src/istio.io/istio$ docker images|grep istio|grep latest #Check the istio docker images
istio/node-agent-k8s                                                   latest                                                          7bc48103e2ae        2 weeks ago         129MB
istio/kubectl                                                          latest                                                          01cc8b3980a4        2 weeks ago         149MB
istio/sidecar_injector                                                 latest                                                          f9ca31eb9dad        2 weeks ago         57.7MB
istio/galley                                                           latest                                                          e7cc59bff1e5        2 weeks ago         148MB
istio/citadel                                                          latest                                                          6412a65db167        2 weeks ago         44.9MB
istio/mixer_codegen                                                    latest                                                          45cfd95b605b        2 weeks ago         20MB
istio/mixer                                                            latest                                                          f3c60fcb55fe        2 weeks ago         75.7MB
istio/proxy_init                                                       latest                                                          54e29e47d915        2 weeks ago         114MB
istio/test_policybackend                                               latest                                                          88fbadfdedc7        2 weeks ago         94.3MB
istio/app_sidecar                                                      latest                                                          0a89ade82be5        2 weeks ago         301MB
istio/app                                                              latest                                                          fa75e5657989        2 weeks ago         128MB
istio/proxyv2                                                          latest                                                          5a6cdc506096        2 weeks ago         229MB
istio/proxytproxy                                                      latest                                                          ef61bae6b271        2 weeks ago         381MB
istio/proxy_debug                                                      latest                                                          e7c6de99ec46        2 weeks ago         229MB
istio/pilot                                                            latest                                                          addc3a6c8210        2 weeks ago         146MB
istionightly/base_debug                                                latest                                                          637e5b9364d0        2 weeks ago         76.1MB

到目前为止,对应的Istio组件已经全部编译完成,接下来,可以利用kubeadm工具,搭建我们的自己的kubernetes cluster。
搭建Kubernetes环境
安装配置kubeadm,kubelet,kubectl具体请参考kubernetes的 官方文档:
https://kubernetes.io/zh/docs...
搭建K8s 集群:

$ sudo kubeadm init --pod-network-cidr=192.168.0.0/16
$ #创建配置文件
$ mkdir -p $HOME/.kube
$ sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
$ sudo chown $(id -u):$(id -g) $HOME/.kube/config
$ #安装Calico CNI
$ kubectl apply -f etcd.yaml
$ kubectl apply -f rbac.yaml
$ kubectl apply -f calico.yaml

安装好之后,检查cluster运行状态

$ kubectl get pods --all-namespaces
NAME                                      READY   STATUS    RESTARTS   AGE
calico-etcd-arm64-4bt95                   1/1     Running   0          141m
calico-kube-controllers-5b778df58-bltkt   1/1     Running   2          141m
calico-node-29rdl                         2/2     Running   3          141m
calico-node-8cdzj                         2/2     Running   2          141m
calico-node-dnn87                         2/2     Running   3          141m
coredns-54ff9cd656-78tfx                  1/1     Running   0          145m
coredns-54ff9cd656-wnhzn                  1/1     Running   0          145m
etcd-host1                                1/1     Running   0          144m
kube-apiserver-host1                      1/1     Running   0          144m
kube-controller-manager-host1             1/1     Running   0          144m
kube-proxy-7j7l5                          1/1     Running   0          142m
kube-proxy-7thlr                          1/1     Running   0          145m
kube-proxy-kl97l                          1/1     Running   0          143m
kube-scheduler-host1                      1/1     Running   0          144m

一般来说,K8s中master节点不能运行pod,但是如果你仅有单个节点,可以用“taint”命令,让master节点也参与到K8s的调度当中:

$ kubectl taint nodes --all node-role.kubernetes.io/master-

配置安装Istio
a. 下载Istio-1.2.3

$ curl -L https://git.io/getLatestIstio | ISTIO_VERSION=1.2.3 sh -
$ cd istio-1.2.3

b. 部署Istio和configMap

$ for i in install/kubernetes/helm/istio-init/files/crd*yaml; do kubectl apply -f $i; done
$ kubectl apply -f install/kubernetes/istio-demo-arm64.yaml
$ kubectl apply -f istio-inject-configmap-1.1.7.yaml

c. 使能Istio自动注入功能

$ kubectl label namespace default istio-injection=enabled --overwrite
$ kubectl get namespace -L istio-injection
NAME           STATUS   AGE     ISTIO-INJECTION
default        Active   3d23h   enabled
istio-system   Active   3d22h   disabled
kube-public    Active   3d23h
kube-system    Active   3d23h

现在,在default namespace下,Istio已经可以使用了

Istio在Arm64上的状态
现在,Istio arm64版本仍然没有发布。我们现在正在不断同社区交流,尽快将相应的patch更新到新版的Istio当中。

文件名 大小 下载次数 操作
0001-Add-arm64-supportted.patch 6.95KB 23 下载
istio-demo-arm64.yaml 575.86KB 21 下载
calico.yaml 12.84KB 5 下载
etcd.yaml 2.78KB 3 下载
rbac.yaml 1.34KB 8 下载
gotool.sh 2.41KB 23 下载
推荐阅读
关注数
2440
内容数
14
介绍Arm相关的开源软件。
目录
极术微信服务号
关注极术微信号
实时接收点赞提醒和评论通知
安谋科技学堂公众号
关注安谋科技学堂
实时获取安谋科技及 Arm 教学资源
安谋科技招聘公众号
关注安谋科技招聘
实时获取安谋科技中国职位信息