本文为苏宁网络架构师陈刚的原创文章。
01 准备测试机
在16G的笔记本没跑起来,就干脆拼凑了一台游戏工作室级别的机器:双路E5-2860v3 CPU,24核48线程,128G DDR4 ECC内存,NVME盘 512G。在上面开5个VM,假装是物理服务器。
· 192.16.35.110 deployer
· 192.16.35.111 tf控制器
· 192.16.35.112 openstack服务器,同时也是计算节点
· 192.16.35.113 k8s master
· 192.16.35.114 k8s的Node k01,同时也是ops的计算节点
直接使用vagrant拉镜像会很慢,就先下载下来:
https://cloud.centos.org/centos/7/vagrant/x86_64/images/
下载对应的VirtualBox.box文件。
然后使用命令, 命名为vagrant的box:
vagrant box add centos/7 CentOS-7-x86_64-Vagrant-2004_01.VirtualBox.box
cat << EEOOFF > vagrantfile
###start
#-*- mode: ruby -*-
#vi: set ft=ruby :
Vagrant.require_version ">=2.0.3"
#All Vagrant configuration is done below. The "2" in Vagrant.configure
#configures the configuration version (we support older styles for
#backwards compatibility). Please don't change it unless you know what
#you're doing.
ENV["LC_ALL"] = "en_US.UTF-8"
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure("2") do |config|
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at
# https://docs.vagrantup.com.
# Every Vagrant development environment requires a box. You can search for
# boxes at https://atlas.hashicorp.com/search.
config.vm.box = "geerlingguy/centos7"
# config.vbguest.auto_update = false
# config.vbguest.no_remote = true
config.vm.define "deployer" do | dp |
dp.vm.provider "virtualbox" do | v |
v.memory = "8000"
v.cpus = 2
end
dp.vm.network "private_network", ip: "192.16.35.110", auto_config: true
dp.vm.hostname = "deployer"
end
config.vm.define "tf" do | tf |
tf.vm.provider "virtualbox" do | v |
v.memory = "64000"
v.cpus = 16
end
tf.vm.network "private_network", ip: "192.16.35.111", auto_config: true
tf.vm.hostname = "tf"
end
config.vm.define "ops" do | os |
os.vm.provider "virtualbox" do | v |
v.memory = "16000"
v.cpus = 4
end
os.vm.network "private_network",ip: "192.16.35.112", auto_config: true
os.vm.hostname = "ops"
end
config.vm.define "k8s" do | k8 |
k8.vm.provider "virtualbox" do | v |
v.memory = "8000"
v.cpus = 2
end
k8.vm.network "private_network", ip: "192.16.35.113", auto_config: true
k8.vm.hostname = "k8s"
end
config.vm.define "k01" do | k1 |
k1.vm.provider "virtualbox" do | v |
v.memory = "4000"
v.cpus = 2
end
k1.vm.network "private_network", ip: "192.16.35.114", auto_config: true
k1.vm.hostname = "k01"
end
config.vm.provision "shell", privileged: true, path: "./setup.sh"
end
EEOOFF
cat << EEOOFF > setup.sh
#!/bin/bash
#
#Setup vagrant vms.
#
set -eu
#Copy hosts info
cat <<EOF > /etc/hosts
127.0.0.1 localhost
127.0.1.1 vagrant.vm vagrant
192.16.35.110 deployer
192.16.35.111 tf
192.16.35.112 ops
192.16.35.113 k8s
192.16.35.114 k01
#The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
EOF
systemctl stop firewalld
systemctl disable firewalld
iptables -F && iptables -X && iptables -F -t nat && iptables -X -t nat
iptables -P FORWARD ACCEPT
swapo