在虚拟机上搭建单机 k8s 环境
Download images and tools
Install virtualbox
https://www.virtualbox.org/wiki/Downloads
From System Preference -> Security & Privacy, allow Oracle access From Virtualbox -> File -> Host Network Manager, click Create button to create one
Install ubuntu iso from below link
https://releases.ubuntu.com/20.04/
Installation and configuration
Install virtualbox
Open virtualbox manager console
Ensure you have correct host network manager settings
properties->vboxnet0->192.168.34.1/24
If the subnet is different, you can edit and update it
Do not enable dhcp
Boot new VM
Click new button
Choose OS as ubuntu 64bit and 30G disk, make sure your #CPU>=2
Start VM, choose the downloaded ubuntu ISO and follow the installation wizard
Specify username/password like cadmin/cadmin (这个可以自定,只要记得密码就好)
Install ssh server, enable and start the service
Do not install built-in kubenernetes
Wait enough long for the os installation complete
Shutdown the OS, and set 2nd network adapter
Go to VM->settings->network->adapter 2
Enable the adapter and select host only adapter, and choose vboxnet0,
vboxnet0
the host network name configured above
Login to the system and set ip for second adapter
Network configuration
Now your VM has two adapters:
One is NAT which will get an IP automatically, generally it's 10.0.2.15, this interface is for external access from your VM
One is host adapter which need create extra ip, which is configured as 192.168.34.2 the reason we need the host adapter and static IP is then we can set this static IP as k8s advertise IP and you can move your VM in different everywhere.(otherwise your VM IP would be changed in different environment)
Swap off
Install docker
Update cgroupdriver to systemd
以上是基础环境搭建部分,完成了虚拟机和 docker 的安装
接下来就是重头戏了:
Install kubernetes
Letting iptables see bridged traffic
Update the apt package index and install packages needed to use the Kubernetes apt repository:
Install kubeadm
Add the Kubernetes apt repository
Update apt package index, install kubelet, kubeadm and kubectl
kubeadm init
Copy kubeconfig
Untaint master
Install calico cni plugin
https://docs.projectcalico.org/getting-started/kubernetes/quickstart
至此,安装过程结束,但是可能还要过一会儿才能完成 k8s 的初始化,一开始我用 kubectl get node 得到的结果是这样的:
当时以为失败了,结果机器没关,到了第二天一看,竟然就成功了:
此时用命令查看 k8s 的容器,都在运行中
版权声明: 本文为 InfoQ 作者【红莲疾风】的原创文章。
原文链接:【http://xie.infoq.cn/article/4713fb33feb83ce3faea184fa】。文章转载请联系作者。
评论