系列导航
- Istio Mixer Adapter开发 (一)K8S环境搭建
- Istio Mixer Adapter开发 (二)Istio环境搭建
- Istio Mixer Adapter开发 (三)自定义Mixer Grpc Adapter部署
概述
由于Kubernetes(后面简称K8S)本身是一个非常复杂的容器管理平台/容器编排系统,本文重点是讲述Istio Mixer适配器组件的开发,在这里我们仅以最简单的方式(使用kubeadm安装一个本地K8S环境)搭建一个K8S集群作为我们部署研究Istio的基础环境
对于Istio,笔者在这里做了一个假设,就是读者均已了解Service Mesh,Istio的基本原理与架构,Istio与Kubernetes的关系,Istio与Service Mesh的关系,这里除有必要部分,不会详细阐述其更多详细功能特性
常用工具安装
安装zsh,参考下面网站
ohmyz.sh/
root@worker05:~# apt install zsh -y
root@worker05:~# sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
➜ ~ vim .zshrc
ZSH_THEME="agnoster"
plugins=(kubectl)
source <(kubectl completion zsh)
安装kubeadm,docker组件
安装kubeadm,docker
$ curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
$ cat <<EOF > /etc/apt/sources.list.d/kubernetes.list
deb http://apt.kubernetes.io/ kubernetes-xenial main
EOF
$ apt-get update
$ apt-get install -y docker.io
$ apt remove kubelet kubectl kubeadm
$ apt install kubelet=1.11.3-00
$ apt install kubectl=1.11.3-00
$ apt install kubeadm=1.11.3-00
部署 Kubernetes 的 Master 节点
首先编写一个kubeadm的安装描述文件kubeadm.yaml
➜ kubeadm vi kubeadm.yaml
apiVersion: kubeadm.k8s.io/v1alpha1
kind: MasterConfiguration
controllerManagerExtraArgs:
horizontal-pod-autoscaler-use-rest-clients: "true"
horizontal-pod-autoscaler-sync-period: "10s"
node-monitor-grace-period: "10s"
apiServerExtraArgs:
runtime-config: "api/all=true"
kubernetesVersion: "stable-1.11"
执行kubeadm init初始化K8S集群
➜ kubeadm init --config kubeadm.yaml
过程中出现一些错误,按照提示解决即可,如笔者遇到的问题用下面两个命令可以解决
➜ kubeadm systemctl enable docker.service
➜ kubeadm swapoff -a
重新执行init操作,若看到如下提示说明init master成功,并提示了加入集群的命令,把他记录下来
Your Kubernetes master has initialized successfully!
To start using your cluster, you need to run the following as a regular user:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
https://kubernetes.io/docs/concepts/cluster-administration/addons/
You can now join any number of machines by running the following on each node
as root:
kubeadm join 192.168.101.6:6443 --token 0ha4j0.g61yo2fbbtqorfd3 --discovery-token-ca-cert-hash sha256:502af619f2997ac5cdbc7a54cd01f9a2fac3bdcd7a9f0d15c588cf1aec3aa67d
执行提示的命令,使本地的kubectl生效
➜ ~ mkdir -p $HOME/.kube
➜ ~ sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
➜ ~ sudo chown $(id -u):$(id -g) $HOME/.kube/config
➜ ~ kubectl get nodes
NAME STATUS ROLES AGE VERSION
worker05 NotReady master 3m v1.11.3
通过命令行输出我们可以看到节点状态的NotReady,查看NotReady的原因
➜ ~ kubectl describe node worker05
...
Conditions:
Ready False Tue, 19 Feb 2019 08:11:20 +0000 Tue, 19 Feb 2019 08:07:26 +0000 KubeletNotReady runtime network not ready: NetworkReady=false reason:NetworkPluginNotReady message:docker: network plugin is not ready: cni config uninitialized
...
意思是我们没部署任何K8S网络插件,使用下述命令部署网络插件
➜ ~ kubectl apply -f https://git.io/weave-kube-1.6
再次查看节点状态,已经可以了
➜ ~ kubectl get nodes
NAME STATUS ROLES AGE VERSION
worker05 Ready master 10m v1.11.3
这里我们的master节点就创建好了,但是,默认k8s的调度策略是不会向master节点调度pods的,原因是默认master节点上会有“污点”,使调度程序调度pod的时候会绕开带有“污点”的节点,我们要做一点特殊设置,去掉这个“污点”
使用如下命令
➜ ~ kubectl describe node worker05
...
Taints: node-role.kubernetes.io/master:NoSchedule
...
# 我们把这个“污点”去掉,就可以让k8s的调度系统调度pod到master节点上了
➜ ~ kubectl taint nodes --all node-role.kubernetes.io/master-
node/worker05 untainted
接下来我们为这个K8S集群部署一个Dashboard可视化插件
➜ ~ kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v1.10.1/src/deploy/recommended/kubernetes-dashboard.yaml
注意部署好的dashboard应用是无法直接被集群外访问的,我们要为其指定类型为NodePort的Service是集群外可以通过节点IP+NodePort端口的方式访问集群内的服务,如下所示:
➜ ~ kubectl edit svc kubernetes-dashboard -n kube-system
...
type: NodePort #将ClusterIP修改成NodePort
...
参考官方文档为该dashboard应用创建用户及token
复制输出当中的token
➜ kubedash kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep admin-user | awk '{print $1}')
➜ kubedash kubectl get svc --all-namespaces
NAMESPACE NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
default kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 50m
kube-system kube-dns ClusterIP 10.96.0.10 <none> 53/UDP,53/TCP 50m
kube-system kubernetes-dashboard NodePort 10.111.245.181 <none> 443:31100/TCP 34m
通过上述命令输出的端口号 + 节点ip(https://192.168.101.6:31100)即可从集群外访问Kubernetes dashboard
如图所示:
至此我们的K8S单节点集群已经搭建好并安装好了dashboard组件,并配置了集群外访问的方式,为下一步部署Istio打下了基础