参考网址 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.145,过程如下:

重新安装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/-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节点,

执行

kubeadm init --image-repository registry.aliyuncs.com/google_containers --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address=10.9.10.154 --node-name=master

输出如下:

Your Kubernetes control-plane has initialized successfully!

To start using your cluster, you need to run the following as a regular user:

  mkdir -p $HOME/.kube

  sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config

  sudo chown $(id -u):$(id -g) $HOME/.kube/config

You should now deploy a pod network to the cluster.

Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:

  https://kubernetes.io/docs/concepts/cluster-administration/addons/

Then you can join any number of worker nodes by running the following on each as root:

kubeadm join 172.16.151.146: --token bggbum.mj3ogzhnm1wz07mj \

    --discovery-token-ca-cert-hash sha256:8f02f83357a965b5db5c5c70bc1dec4c57d507ebae8c50b0d2efef4c32f5d106 

先在master里执行下面语句,如果是root用户,可执行(export KUBECONFIG=/etc/kubernetes/kubelet.conf),如果是其他用户,执行下面语句

mkdir -p $HOME/.kube

sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config

sudo chown $(id -u):$(id -g) $HOME/.kube/config

执行:

kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/62e44c867a2846fefb68bd5f178daf4da3095ccb/Documentation/kube-flannel.yml

多节点安装遇到了权限的错误,暂时放弃。

Error from server (Forbidden): namespaces is forbidden: User "system:node:master" cannot list resource "namespaces" in API group "" at the cluster scope

再用上面的语句在node1里执行,把node1加入master

详情可参考 https://kubernetes.io/docs/setup/independent/create-cluster-kubeadm/

过程种遇到的问题:

1、找不到端口列表,需要把https://github.com/linianhui/code/blob/master/shell/ubuntu.k8s.0.pre-setting.sh再执行一遍

2、运行kubectl get services报509错误,需要执行一下 export KUBECONFIG=/etc/kubernetes/kubelet.conf





最新文章

  1. 排序算法----基数排序(RadixSort(L))单链表智能版本
  2. Eclipse智能提示及快捷键
  3. 修改linux最大文件句柄数
  4. python mysqldb连接数据库
  5. 关于A*寻路算法的认识
  6. SQL Server还原和一些小发现
  7. Matlab的parfor并行编程
  8. intellij idea该插件开发摘要
  9. jquery验证表单中的单选与多选
  10. Docker 网络 Flannel
  11. Swift 动态创建提示框
  12. python函数式编程之yield表达式形式
  13. 11.Flask钩子函数
  14. DataGridView中进行增删改查
  15. Vim中YouCompleteMe插件安装
  16. Nginx 的线程池与性能剖析【转载】
  17. C语言 · 龟兔赛跑预测
  18. PAT——1053. 住房空置率
  19. Docker安装和状态查询指令
  20. Luogu2917_ [USACO08NOV]奶牛混合起来Mixed Up Cows_KEY

热门文章

  1. 九度oj 题目1130:日志排序
  2. vscode & code snippets
  3. Apple Pay强势来袭,开发者应做的事情(转)
  4. Windows下ElasticSearch的使用方式 CURL+Cygwin+Head插件
  5. Laravel 5 Form 和 HTML 的使用
  6. 洛谷 P 1330 封锁阳光大学
  7. 巴厘岛的雕塑 BZOJ 4069
  8. Scott Mitchell的ASP.NET2.0数据指南中文版索引
  9. hdu3491最小割转最大流+拆点
  10. Oracle外键级联删除和级联更新