kubernetes 1.18安装
作者:互联网
准备环境:
主机名(centos7) | IP地址 | 角色 |
node01 | 192.168.254.101 | master |
node02 | 192.168.254.102 | node |
node03 | 192.168.254.103 | node |
注意:一定要修改hosts解析,否则使用ansible命令连接很慢
# 三台主机都修改hosts
cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 192.168.254.101 node01 192.168.254.102 node02 192.168.254.103 node03
一、安装Ansible
使用yum安装
192.168.254.101:
wget -O /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo
yum install ansible -y
配置ansible
~]# cat > /etc/ansible/hosts2 <<EOF [k8s] 192.168.254.101 192.168.254.102 192.168.254.103 EOF
#生成秘钥对
ssh-keygen
ssh-copy-id root@192.168.254.101
ssh-copy-id root@192.168.254.102
ssh-copy-id root@192.168.254.103
#测试
ansible k8s -m ping
二、安装docker
1 安装docker
# 1、安装docker: 分别在 254.101 254.102 254.103上执行,也可以通过ansible命令执行 sudo yum install -y yum-utils device-mapper-persistent-data lvm2 sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo # sudo yum install docker-ce docker-ce-cli containerd.io # 安装指定版本 sudo yum install docker-ce-19.03.8 docker-ce-cli-19.03.8 -y
2、配置加速
sudo mkdir -p /etc/docker sudo tee /etc/docker/daemon.json <<-'EOF' { "registry-mirrors": ["https://k1vsanis.mirror.aliyuncs.com"] } EOF sudo systemctl daemon-reload sudo systemctl restart docker sudo systemctl enable docker
3 关闭swap
关闭swap,注释swap分区 swapoff -a ~]# cat /etc/fstab #/dev/mapper/centos-swap swap swap defaults 0 0
# 使用ansible替换
ansible k8s -m shell -a "sed -i s@/dev/mapper/centos-swap@#/dev/mapper/centos-swap@g /etc/fstab"
ansible k8s -m shell -a "swapoff -a"
# 查看
ansible k8s -m shell -a "free -m"
4、桥接的IPv4流量传递到iptables的链 cat > /etc/sysctl.d/k8s.conf <<EOF net.bridge.bridge-nf-call-ip6tables = 1 net.bridge.bridge-nf-call-iptables = 1 EOF sysctl --system
# 使用ansible操作
ansible k8s -m copy -a "src=/etc/sysctl.d/k8s.conf dest=/etc/sysctl.d/k8s.conf"
ansible k8s -m shell -a "sysctl --system"
查看
ansible k8s -m shell -a "cat /etc/sysctl.d/k8s.conf"
5、安装常用工具 yum install vim bash-completion net-tools gcc wget -y
二、安装kubectl、kubelet、kubeadm
1、配置yum源
cat <<EOF > /etc/yum.repos.d/kubernetes.repo [kubernetes] name=Kubernetes baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/ enabled=1 gpgcheck=1 repo_gpgcheck=1 gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg EOF
2、安装 # yum install kubectl kubelet kubeadm -y # 安装指定版本 使用 --nogpgcheck
yum install --nogpgcheck kubectl-1.18.0-0.x86_64 kubelet-1.18.0-0.x86_64 kubeadm-1.18.0-0.x86_64 -y
systemctl enable kubelet
3、初始化k8s集群
api server地址就是master本机IP
kubeadm init --kubernetes-version=1.18.0 \ --apiserver-advertise-address=192.168.254.101 \ --image-repository registry.aliyuncs.com/google_containers \ --service-cidr=10.10.0.0/16 --pod-network-cidr=10.122.0.0/16 #记录最后内容 kubeadm join 192.168.56.105:6443 --token ozcotl.qixuwjitmj3jm18f \ --discovery-token-ca-cert-hash sha256:2ccba350a7833470c0c8ed6c007aadf73226b892be221ea78d9bfa35b2810dbf
配置网络
kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml
标签:kubernetes,--,192.168,etc,ansible,yum,1.18,k8s,安装 来源: https://www.cnblogs.com/zhutao2014/p/16652068.html