Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rancher安装k8s集群 #188

Open
v5tech opened this issue Aug 29, 2019 · 2 comments
Open

Rancher安装k8s集群 #188

v5tech opened this issue Aug 29, 2019 · 2 comments

Comments

@v5tech
Copy link
Owner

v5tech commented Aug 29, 2019

Vagrantfile

Vagrant.configure("2") do |config|
	config.vm.define "centos7" do |node|
	  node.vm.box = "centos/7"
	  node.vm.box_version = "1905.1"
	  node.vm.box_check_update = false

	  node.vm.provision "shell", inline: "echo This box contains CentOS 7 64-bit."
	  node.vm.hostname = "centos"
	  node.vm.network "public_network", ip: "172.30.31.246"
	  
	  node.vm.provider "virtualbox" do |v|
	    v.name = "centos"
	    v.memory = 4096
	    v.cpus = 2
	  end
	end
end

关闭SELinux

# vim /etc/selinux/config

SELINUX=disabled

关闭虚拟内存

# vim /etc/fstab

#/swapfile none swap defaults 0 0

禁用ipv6

# ifconfig -a | grep inet6
	inet6 fe80::211:aff:fe6a:9de4  prefixlen 64  scopeid 0x20
	inet6 ::1  prefixlen 128  scopeid 0x10[host]

# vim /etc/default/grub
GRUB_TIMEOUT=5
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="ipv6.disable=1 crashkernel=auto rhgb quiet"
GRUB_DISABLE_RECOVERY="true"

# grub2-mkconfig -o /boot/grub2/grub.cfg

# shutdown -r now	

# ip addr show | grep net6

https://www.thegeekdiary.com/centos-rhel-7-how-to-disable-ipv6/

安装docker

# 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

# sudo yum install docker-ce docker-ce-cli containerd.io	

# sudo systemctl start docker && sudo systemctl enable docker

# sudo systemctl status docker

禁用防火墙

# sudo systemctl stop firewalld.service && sudo systemctl disable firewalld.service

# sudo systemctl status firewalld.service

设置iptables

# sudo iptables -nL

# sudo iptables -P FORWARD ACCEPT

# sudo iptables -S

ipv4端口转发

# vim /etc/sysctl.conf

net.ipv4.ip_forward=1

docker中开启iptables

# vim /etc/systemd/system/docker.service

[Service]
ExecStartPost=/sbin/iptables -I FORWARD -s 0.0.0.0/0 -j ACCEPT

安装rancher

# sudo docker run -d --restart=unless-stopped -p 80:80 -p 443:443 rancher/rancher

# sudo docker run -d --privileged --restart=unless-stopped --net=host -v /etc/kubernetes:/etc/kubernetes -v /var/run:/var/run rancher/rancher-agent:v2.2.8 --server https://172.30.31.246 --token vgz22zdgc4g69cn4hqjttr47h8nqbfl7zwhmqhqh6sgmd6k5wkclvl --ca-checksum 09df17c14f54bac1c0c4842784652dfb168b9b741af6db8bfa37d1d6d8a31b7c --address 172.30.31.246 --internal-address 172.30.31.246 --etcd --controlplane --worker

参考文档

https://nll.im/post/hello-k3s.html

https://blog.ilemonrain.com/docker/rancher-with-k3s.html

http://xcx1024.com/ArtInfo/183043.html

@v5tech
Copy link
Owner Author

v5tech commented Aug 31, 2019

Vagrantfile

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.require_version ">= 1.6.0"

boxes = [
    {
        :name => "manager",
        :eth0 => "192.168.205.10",
        :mem => "1024",
        :cpu => "1"
    },
    {
        :name => "worker1",
        :eth0 => "192.168.205.11",
        :mem => "1024",
        :cpu => "1"
    },
    {
        :name => "worker2",
        :eth0 => "192.168.205.12",
        :mem => "1024",
        :cpu => "1"
    }
]

Vagrant.configure(2) do |config|

  config.vm.box = "centos7"
  config.vm.box_check_update = false
  config.ssh.username = 'root'
  config.ssh.password = 'root' 
  config.ssh.insert_key = 'true'

  boxes.each do |opts|
      config.vm.define opts[:name] do |config|
        config.vm.hostname = opts[:name]
        config.vm.provider "vmware_fusion" do |v|
          v.vmx["memsize"] = opts[:mem]
          v.vmx["numvcpus"] = opts[:cpu]
        end

        config.vm.provider "virtualbox" do |v|
          v.customize ["modifyvm", :id, "--memory", opts[:mem]]
          v.customize ["modifyvm", :id, "--cpus", opts[:cpu]]
        end

        config.vm.network :private_network, ip: opts[:eth0]
        config.vm.network :forwarded_port, guest: 8080, host: 8080
      end
  end

  config.vm.synced_folder ".", "/vagrant"
  config.vm.provision "shell", privileged: true, path: "./setup.sh"

end

setup.sh

# 安装你想安装的工具
sudo yum install -y git vim gcc glibc-static telnet bridge-utils

# 安装docker
curl -fsSL get.docker.com -o get-docker.sh
sh get-docker.sh

# 启动docker服务
sudo systemctl start docker

#移除安装包
rm -rf get-docker.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant