环境

  • 操作系统:centos7
  • docker:1.13.1
  • 用户: root
  • 自己本机已经有docker 如果没有 下面的命令也会自动安装

步骤:

1、 systemctl disable firewalld    //先关闭防火墙
2、yum install -y etcd kubernetes  //yum安装 可以自动安装docker
3、修改一下docker配置文件  /etc/sysconfig/docker, 
参数:OPTIONS=’–selinux-enabled=false –insecure-registry gcr.io’
4、因为是单机版本:把Kubernetes apiservce配置文件 /etc/kubernetes/apiserver中
KUBE_ADMISSION_CONTROL="--admission_control=NamespaceLifecycle,NamespaceExists,ServiceAccount,LimitRanger,ResourceQuota"中的ServiceAccount给删掉,
5、按照以下顺序依次启动:
    systemctl start etcd
    systemctl start docker
    systemctl start kube-apiserver
    systemctl start kube-controller-manager
    systemctl start kube-scheduler
    systemctl start kubelet
    systemctl start kube-proxy
6、启动完成之后执行命令 kubectl version 出现以下则成功
   Client Version: version.Info{Major:"1", Minor:"5", GitVersion:"v1.5.2",GitCommit:"269f928217957e7126dc87e6adfa82242bfe5b1e", GitTreeState:"clean", BuildDate:"2017-07-03T15:31:10Z", GoVersion:"go1.7.4", Compiler:"gc", Platform:"linux/amd64"}
   Server Version: version.Info{Major:"1", Minor:"5", GitVersion:"v1.5.2", GitCommit:"269f928217957e7126dc87e6adfa82242bfe5b1e", GitTreeState:"clean", BuildDate:"2017-07-03T15:31:10Z", GoVersion:"go1.7.4", Compiler:"gc", Platform:"linux/amd64"}

出现问题:

第一个问题:执行: systemctl start kube-apiserver   命令时候报: 
kube-apiserver.service: main process exited, code=exited, status=255/n/a 问题:
此处端口冲突了,默认8080和自己本地一个服务冲突,然后将kube-apiserver端口修改了:
配置文件: /etc/kubernetes/apiserver 参数 KUBE_API_PORT 然后启动之后没什么问题
第二个问题: 再所有服务启动完成之后执行命令  kubectl version,然后出现了:客户端正常:
服务端出现了: Error from server (BadRequest): the server rejected our request for  an unknow,
服务端拒绝了连接。说明了,kube-apiserver 启动没有成功,有问题。
解决: 因为k8s默认使用的是8080,需要修改很多配置默认端口,自己是将自己的本地测试服务的
端口8080修改了,将k8s的 kube-apiserver 服务的端口又改为了8080(此处参照上一个问题修改端
口),然后重启kube-apiserver 服务,重启完成后输入 kubectl version 出现了第三个问题:
第三个问题:The connection to the server localhost:8080 was refused - did you specify the right 
host or port?
Client Version: version.Info{Major:"1", Minor:"5", GitVersion:"v1.5.2", GitCommit:"269f928217957e7126dc87e6adfa82242bfe5b1e", GitTreeState:"clean", BuildDate:"2017-07-03T15:31:10Z", GoVersion:"go1.7.4", Compiler:"gc", Platform:"linux/amd64"}
The connection to the server localhost:8080 was refused - did you specify the right host or port?
这个问题是因为没有按照启动顺序重启:坑爹
systemctl restart etcd
    systemctl restart docker
    systemctl restart kube-apiserver
    systemctl restart kube-controller-manager
    systemctl restart kube-scheduler
    systemctl restart kubelet
    systemctl restart kube-proxy
依次重启之后安装完成:输入kubectl  version
Client Version: version.Info{Major:"1", Minor:"5", GitVersion:"v1.5.2", GitCommit:"269f928217957e7126dc87e6adfa82242bfe5b1e", GitTreeState:"clean", BuildDate:"2017-07-03T15:31:10Z", GoVersion:"go1.7.4", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"5", GitVersion:"v1.5.2", GitCommit:"269f928217957e7126dc87e6adfa82242bfe5b1e", GitTreeState:"clean", BuildDate:"2017-07-03T15:31:10Z", GoVersion:"go1.7.4", Compiler:"gc", Platform:"linux/amd64"}
大功告成
参考博客:

k8s入门、安装、实践
k8s中文文档

Logo

开源、云原生的融合云平台

更多推荐