一、安装docker

Service mesh 学习03 Istio安装_Istio安装

两台机器各自安装docker

192.168.183.134

192.168.183.136    

1.1 确保系统是最新的 执行命令

yum update -y

1.2 安装一些必要的包 执行命令

yum install -y yum-utils device-mapper-persistent-data lvm2

1.3 添加docker仓库 

yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

1.4 安装docker执行以下命令

yum install -y docker-ce

安装后如下

Service mesh 学习03 Istio安装_Istio安装_02

然后启动docker

1.5 启动docker前,一定要关闭防火墙

# 关闭
systemctl stop firewalld
# 禁止开机启动防火墙
systemctl disable firewalld

1.6 启动docker 命令如下

systemctl start docker  # 启动docker服务

1.7 查看docker版本,命令如下

docker -

Service mesh 学习03 Istio安装_Istio安装_03

二、安装k8s集群

https://blog.csdn.net/helenyqa/article/details/130984734

2.1修改节点名称

# master 节点
hostnamectl set-hostname master
# work1节点
hostnamectl set-hostname work1

2.2 为每个节点添加host映射

echo "192.168.183.134 master" >>/etc/hosts
echo "192.168.183.135 work1" >>/etc/hosts

2.3 每个节点关闭selinux和swap

#永久关闭selinux
sed -i 's/enforcing/disabled/' /etc/selinux/config
#临时关闭selinux
setenforce 0

#永久关闭swap
sed -ri 's/.*swap.*/#&/' /etc/fstab
#临时关闭swap
swapoff -a

Service mesh 学习03 Istio安装_Istio安装_04

2.4 执行命令关闭防火墙

#临时关闭
systemctl stop firewalld
# 永久关闭
systemctl disable firewalld

2.5 每个节点安装常用命令

yum install net-tools.x86_64  vim  conntrack ntpdate ntp ipvsadm ipset jq iptables curl sysstatlibseccomp wget vim net-tools git iproute lrzsz bash-completion tree bridge-utils unzip bind-utils gcc -y

Service mesh 学习03 Istio安装_Istio安装_05

2.6 安装docker,之前安装过

sudo yum update
    sudo yum install -y yum-utils device-mapper-persistent-data lvm2
    #官网镜像
    # sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
	# aliyun镜像
	sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
	sudo yum makecache fast
	# 安装
    sudo yum install docker-ce docker-ce-cli containerd.io
    # 启动
    sudo systemctl start docker
    # 开机启动
    sudo systemctl enable docker

Service mesh 学习03 Istio安装_Istio安装_06

2.7 修改docker配置etc/docker/daemon.json,如下

vi /etc/docker/daemon.json

{
  "exec-opts": ["native.cgroupdriver=systemd"],
  "registry-mirrors": [
    "https://pmyvcr6n.mirror.aliyuncs.com",
    "https://docker.mirrors.ustc.edu.cn",
    "http://hub-mirror.c.163.com"
  ],
  "max-concurrent-downloads": 10,
  "max-concurrent-uploads": 10,
  "log-driver": "json-file",
  "log-level": "warn",
  "log-opts": {
    "max-size": "10m",
    "max-file": "3"
    },
  "data-root": "/var/lib/docker"
}

Service mesh 学习03 Istio安装_Istio安装_07

然后执行 

systemctl daemon-reload
systemctl restart docker

docker启动成功

systemctl status docker.service 查看docker状态

Service mesh 学习03 Istio安装_Istio安装_08

2.8 添加kubernetes仓库

sudo cat > /etc/yum.repos.d/kubernetes.repo << EOF
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF

Service mesh 学习03 Istio安装_Istio安装_09

2.9 master安装kubernetes

#指定版本
yum install -y kubelet-1.23.5 kubeadm-1.23.5 kubectl-1.23.5
sudo systemctl start kubelet
sudo systemctl enable kubelet

Service mesh 学习03 Istio安装_Istio安装_10

Service mesh 学习03 Istio安装_Istio安装_11

2.10 其他节点安装kubernetes

#指定版本
yum install -y kubelet-1.23.5 kubeadm-1.23.5
sudo systemctl enable kubelet

Service mesh 学习03 Istio安装_Istio安装_12

Service mesh 学习03 Istio安装_Istio安装_13

2.11 配置kubernetes

cat > /etc/sysctl.d/k8s.conf <<EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
# /etc/sysctl.d/k8s.conf命令生效
sysctl --system

Service mesh 学习03 Istio安装_Istio安装_14

2.12 启动kubernetes

sudo kubeadm init --apiserver-advertise-address=192.168.183.134 --image-repository registry.aliyuncs.com/google_containers --kubernetes-version v1.23.5 --service-cidr=10.96.0.0/12 --pod-network-cidr=10.244.0.0/16

master节点启动k8s成功

Service mesh 学习03 Istio安装_Istio安装_15

验证当前系统k8s是否正在运行

# systemctl status kubelet.service

Service mesh 学习03 Istio安装_Istio安装_16

2.13 配置k8s

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

2.14 其他节点安装k8s

先在master生成token 命令如下

kubeadm token create --print-join-command

生成如下

kubeadm join 192.168.183.134:6443 --token 2tqdrx.2s7gkvasotb03ctv --discovery-token-ca-cert-hash sha256:97cb40d09c395586908ba894a4753407e5e811985db185052f62317e9dc16df1

Service mesh 学习03 Istio安装_Istio安装_17

然后在slave节点执行加入k8s集群的命令,token就是上面生成的那个

Service mesh 学习03 Istio安装_Istio安装_18

验证下

kubectl get nodes

发现状态还是NotReady

Service mesh 学习03 Istio安装_Istio安装_19

2.15 安装网络插件calico

虽然现在k8s集群已经有1个master节点,2个worker节点,但是此时三个节点的状态都是NotReady的,原因是没有CNI网络插件,为了节点间的通信,需要安装cni网络插件,常用的cni网络插件有calico和flannel,两者区别为:flannel不支持复杂的网络策略,calico支持网络策略,因为今后还要配置k8s网络策略networkpolicy,所以本文选用的cni网络插件为calico!

安装calico

https://blog.csdn.net/helenyqa/article/details/130984734

kubectl apply -f calico.yaml

Service mesh 学习03 Istio安装_Istio安装_20

Service mesh 学习03 Istio安装_Istio安装_21

重新修改master和work1节点的/etc/hosts后问题解决

Service mesh 学习03 Istio安装_Istio安装_22

看下pods,执行命令

kubectl get pods -n kube-system

Service mesh 学习03 Istio安装_Istio安装_23

三、安装istio

https://github.com/istio/istio/releases/tag/1.0.6

3.1 下载istio压缩包后解压到istio目录

Service mesh 学习03 Istio安装_Istio安装_24

看下install 目录

Service mesh 学习03 Istio安装_Istio安装_25

3.2 进入到工具目录

cd install/kubernetes/helm/istio/templates

Service mesh 学习03 Istio安装_Istio安装_26

执行安装istio命令

kubectl apply -f crds.yaml

使用kubectl get crd -n istio-system | wc -l 查看个数

Service mesh 学习03 Istio安装_Istio安装_27

3.3 解读一下官方的demo文件istio-demo.yaml

Service mesh 学习03 Istio安装_Istio安装_28

Service mesh 学习03 Istio安装_Istio安装_29

然后执行安装命令

kubectl apply -f istio-demo.yaml

然后查看命名空间

kubectl get pods -n istio-system

Service mesh 学习03 Istio安装_Istio安装_30