ansible搭建k8s

Posted 小怪獣55

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ansible搭建k8s相关的知识,希望对你有一定的参考价值。

1.主机规划

类型

主机ip

域名

vip

k8s-master

192.168.47.47

k8s-master.example.com

192.168.47.49

k8s-harbar/haproxy

192.168.47.48

k8s-​harbar.example.com


k8s-etcd1

192.168.47.50

k8s-​​​etcd1.example.com


k8s-etcd2

192.168.47.51

k8s-​​​etcd2.example.com


k8s-etcd3

192.168.47.52

k8s-​​​etcd3​.example.com


k8s-node1

192.168.47.53

k8s-​​​node1.example.com


k8s-node2

192.168.47.54

k8s-​​​node2.example.com


环境

root@ubuntu:~# cat /etc/issue
Ubuntu 18.04.3 LTS \\n \\l

2.基础环境准备

2.1.更改网卡名称为eth0

vim /etc/default/grub
------------------------------------------------------
GRUB_CMDLINE_LINUX="net.ifnames=0 biosdevname=0"
------------------------------------------------------
update-grub

2.2.更改系统ip地址

vim /etc/netplan/01-netcfg.yaml
------------------------------------------------------
network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: no
addresses: [192.168.47.47/24]
gateway4: 192.168.47.2
nameservers:
addresses: [192.168.47.2]
------------------------------------------------------
netplan apply

2.3.更改主机名

cat /etc/hostname
------------------------
k8s-master.example.com
------------------------

2.4.apt源改为阿里源

​https://developer.aliyun.com/mirror/ubuntu?spm=a2c6h.13651102.0.0.3e221b11mmN9H3​

apt-get upgrade

2.5.安装常用命令

apt-get  install iproute2  ntpdate  tcpdump telnet traceroute \\
nfs-kernel-server nfs-common lrzsz tree openssl libssl-dev \\
libpcre3 libpcre3-dev zlib1g-dev ntpdate tcpdump telnet traceroute \\
gcc openssh-server lrzsz tree openssl libssl-dev libpcre3 libpcre3-dev \\
zlib1g-dev ntpdate tcpdump telnet traceroute iotop unzip zip -y

2.6.其他配置

grep "^[a-Z]" /etc/sysctl.conf 
---------------------------------------------
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
vm.swappiness=0
net.ipv4.ip_forward = 1
---------------------------------------------

2.7.安装docker

参考:​​https://developer.aliyun.com/article/110806​

#方式1:官方安装脚本自动安装
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun

#方式2:
apt-get update
apt-get -y install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
apt-get -y update && apt-get -y install docker-ce
docker info

#镜像加速:
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-EOF

"registry-mirrors": ["https://vmaivck0.mirror.aliyuncs.com"]

EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

2.8.禁用swap,selinux(ubuntu没有),iptables

swapoff -a #临时关闭swap

2.9master/node/etcd安装

apt-get install python2.7 -y && ln -s /usr/bin/python2.7 /usr/bin/python

2.10.reboot做快照

3.keepalived

apt-get install keepalived  -y

cp /usr/share/doc/keepalived/samples/keepalived.conf.vrrp /etc/keepalived/keepalived.conf
vim /etc/keepalived/keepalived.conf
-----------------------------------------------------------------
virtual_ipaddress
192.168.47.49/24 dev eth0 label eth0:1 #设置的vip必须被master访问

-----------------------------------------------------------------
systemctl restart keepalived && systemctl enable keepalived

4.harproxy

apt-get install haproxy -y

vim /etc/haproxy/haproxy.cfg
----Win10下从零搭建Linux+Ansible+K8S 学习环境笔记(1*Master/controller+3*Node)

Win10下从零搭建Linux+Ansible+K8S 学习环境笔记(1*Master/controller+3*Node)

从零搭建Linux+Docker+Ansible+kubernetes 学习环境(1*Master+3*Node)

从零搭建Linux+Docker+Ansible+kubernetes 学习环境(1*Master+3*Node)

k8s-监控组件:heaper部署

K8s(v1.25.1) 高可用集群(3 Master + 5 Node) Ansible 剧本部署(CRI使用docker,cri-docker)