February 11

Vagrantfile for KubeAdm/Calico using CentOS

This is an alternate Vagrantfile that uses CentOS 7, instead of Ubuntu 16.04 for creating a two node KubeAdm cluster for Kubernetes with Calico plugin. See https://blog.michali.net/2017/02/11/using-kubeadm-an…r-ipv6-addresses/ for info on how this is used. Besides the different image, the provision has some minor changes. Here’s the file contents, which I’ll eventually put into a github repo:
Update: You can do the mods mentioned in https://blog.michali.net/2017/02/13/update-on-kubeadm-with-calico/ for the Ubuntu version of the vagrant file. This would use and IP of 10.20.30.10 for the master node, which you can use in the “kubeadm init” command with –api-advertise-addresses=10.20.30.10 option.

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

# The calicoctl download URL.
calicoctl_url = "https://github.com/projectcalico/calico-containers/releases/download/v1.0.0/calicoctl"

# The version of the calico docker images to install. This is used to pre-load
# the calico/node image which slows down the install process, but speeds up the tutorial.
#
# This version should match the version required by calicoctl installed from
# calicoctl_url.
calico_node_ver = "latest"

# Size of the cluster created by Vagrant
num_instances=2

# Change basename of the VM
instance_name_prefix="cnode"

# The IP address of the first server
primary_ip = "10.96.0."

Vagrant.configure(2) do |config|
 # always use Vagrants insecure key
 config.ssh.insert_key = 'true'
 config.ssh.username = 'vagrant'

# Use Centos/7 box
 # https://atlas.hashicorp.com/boxes/search
 config.vm.box = "centos/7"

config.vm.provider "virtualbox" do |vb|
 vb.cpus = 2
 vb.memory = 2048
 end

# Set up each box
 (1..num_instances).each do |i|
 vm_name = "%s-%02d" % [instance_name_prefix, i]
 config.vm.define vm_name do |host|
 host.vm.hostname = vm_name

ip = "#{primary_ip}#{i+100}"

host.vm.network :private_network, ip: ip

# Add repo, disable security, install kubelet, kubeadm, kubectl and k8s-CNI binaries.
 # Start docker and kubelet.
 # host.vm.provision "file", source: "kubernetes.repo", destination: "/etc/yum.repos.d/kubernetes.repo"
 host.vm.provision :shell, inline: <<-SHELL
 cat > /etc/yum.repos.d/kubernetes.repo <<EOF
[kubernetes]
name=Kubernetes
baseurl=http://yum.kubernetes.io/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg
 https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
EOF
 setenforce 0
 yum install -y docker kubelet kubeadm kubectl kubernetes-cni
 systemctl enable docker && systemctl start docker
 systemctl enable kubelet && systemctl start kubelet
 SHELL
 host.vm.provision :shell, inline: "docker pull quay.io/calico/node:#{calico_node_ver}"
 host.vm.provision :shell, inline: "docker pull quay.io/calico/ctl:#{calico_node_ver}"
 # download calicoctl.
 host.vm.provision :shell, inline: "curl -L --silent #{calicoctl_url} -o /usr/local/bin/calicoctl"
 host.vm.provision :shell, inline: "chmod +x /usr/local/bin/calicoctl"
 host.vm.provision :shell, inline: "echo PATH=${PATH}:/usr/local/bin > /etc/profile.d/local-bin.sh && chmod 755 /etc/profile.d/local-bin.sh"
 end
 end
 vm_name = "%s-01" % instance_name_prefix
 config.vm.define vm_name do |host|
   host.vm.provision "file", source: "calico.yaml", destination: "calico.yaml"
 end
end

Tags: ,
Copyright 2017-2024. All rights reserved.

Posted February 11, 2017 by pcm in category "Kubernetes