参考网址 https://kubernetes.io/docs/setup/
1、安装vmvare
2、下载ubuntu镜像(可以不要界面,可以下载server版大约900M,否则下载desktop版大约1.9G),我下载的是18.04.2版本,
因为server版配置静态ip没找到文件,所以换成了desktop版本。
3、安装第一个ubuntu系统,起名叫master,设置静态ip172.16.151.146,过程如下:
重新安装vim解决不识别上下按键的问题:
ubuntu预装的是vim tiny版本,而需要的是vim full版本。执行下面的语句安装vim full版本:
$sudo apt-get remove vim-common
$sudo apt-get install vim
设置主机名master(修改名字后要重启才能生效)
vi /etc/hostname
设置root用户:
sudo passwd root
设置root自动登陆
sudo gedit /usr/share/lightdm/lightdm.conf.d/50-ubuntu.conf
内容替换如下:
autologin-user=root
user-session=ubuntu
greeter-show-manual-login=true
sudo gedit /root/.profile
将mesg n替换成tty -s && mesg n
重启ubuntu后以root自动登陆
设置静态ip:
vmvare的网络设置为nat模式
修改/etc/network/interfaces,如果是desktop版,可以通过网络设置界面修改。修改完后需要重启网络链接。
开启ssh服务:
sudo apt-get install openssh-server
打开密码登陆:登录目标机器 修改 /etc/ssh/sshd_config文件中 PermitRootLogin without-password 改为 PermitRootLogin yes
确认sshserver是否启动了:ps -ef |grep ssh
3、安装docker和k8s (使用李念辉写的脚本)
git clone https://github.com/linianhui/code.git
安装docker使用
https://github.com/linianhui/code/blob/master/docker/docker-in-ubuntu.md
安装k8s使用
https://github.com/linianhui/code/blob/master/shell/ubuntu.k8s.0.pre-setting.sh
https://github.com/linianhui/code/blob/master/shell/ubuntu.k8s.1.kubeadm.install.sh
https://github.com/linianhui/code/blob/master/shell/ubuntu.k8s.2.kubeadm.pull-images.sh
4、关闭虚拟机,复制虚拟机文件,重新生成mac地址,设置名字为node1,设置静态ip172.16.151.147,
5、启动master虚拟机,初始化master节点,
执行 https://github.com/linianhui/code/blob/master/shell/ubuntu.k8s.3.kubeadm.init.sh
输出如下:
Then you can join any number of worker nodes by running the following on each as root:
kubeadm join 172.16.151.146:6443 --token bggbum.mj3ogzhnm1wz07mj \
--discovery-token-ca-cert-hash sha256:8f02f83357a965b5db5c5c70bc1dec4c57d507ebae8c50b0d2efef4c32f5d106
用上面的语句在node1里执行,把node1加入master
详情可参考 https://kubernetes.io/docs/setup/independent/create-cluster-kubeadm/