官网:https://github.com/kubernetes/kubernetes/blob/release-1.0/docs/getting-started- guides/centos/centos_manual_config.md
在两个主机上分别配置
vi /etc/hostname
echo "192.168.18.128 centos-master 192.168.18.130 centos-minion
" >> /etc/hosts
使得两个主机可以互ping
cd /etc/yum.repo.d
vi virt7-testing.repo
[virt7-testing]
name=virt7-testing baseurl=http://cbs.centos.org/repos/virt7- testing/x86_64/os/
gpgcheck=0
原来安装了docker1.8的先删除,没有安装的就不用执行下面这个步骤了
正式安装
Install Kubernetes on all hosts - centos-{master,minion}(所有的机器都安装)
yum -y install --enablerepo=virt7-testing kubernetes
master 节点安装 etcd package:
yum install http://cbs.centos.org/kojifiles/packages/etcd/0.4.6/7.el7.centos/x86_64/etcd-0.4.6-7.el7.centos.x86_64.rpm
关闭防火墙
systemctl disable iptables-services firewalld (firewalid是自定义的)
systemctl stop iptables-services firewalld
每个节点上修改kubernetes配置文件:
vi /etc/kubernetes/config
# How the controller-manager, scheduler, and proxy find the apiserver
KUBE_MASTER="--master=http://centos-master:8080" (centos-master是master节点的主机名,用来配置apiserver)
KUBE_ETCD_SERVERS="--etcd_servers=http://centos-master:4001"(配置etcd)
Master节点上 vi /etc/kubernetes/apiserver
# The address on the local server to listen to.
KUBE_API_ADDRESS="--address=0.0.0.0" KUBE_API_PORT="--port=8080"(配置apiserver)
# Comma separated list of nodes in the etcd cluster
#KUBE_ETCD_SERVERS="--etcd_servers=http://127.0.0.1:2379"(上面已经配置过了,这里不用管)
Master节点启动相关kubernetes服务:
for SERVICES in etcd kube-apiserver kube-controller- manager kube-scheduler; do
systemctl restart $SERVICES
systemctl enable $SERVICES
systemctl status $SERVICES
done
查看状态
for SERVICES in etcd kube-apiserver kube-controller- manager kube-scheduler; do
systemctl status $SERVICES done
Master节点启动相关kubernetes服务
查看启动的结果:
Node节点修改/etc/kubernetes/kubelet:
###
# kubernetes kubelet (minion) config
KUBELET_ADDRESS="--address=0.0.0.0" (绑定本地的端口)
KUBELET_PORT="--port=10250"(指定自己的端口绑定给本地的0000端口)
KUBELET_HOSTNAME="--hostname_override=centos-minion" (给master节点汇报自己节点的主机名)
KUBELET_API_SERVER="--api_servers=http://centos-master:8080“ (要访问的apiserver的地址)
# Add your own!
KUBELET_ARGS=""
node节点:
for SERVICES in kube-proxy kubelet docker; do
systemctl restart $SERVICES
systemctl enable $SERVICES
systemctl status $SERVICES
done
for SERVICES in kube-proxy kubelet docker; do
systemctl status $SERVICES
done
tail -f /var/log/messages |grep kube
在master节点执行kubectl get nodes
查看到节点注册成功,则表明系统安装正常
[root@centos-master yum.repos.d]# kubectl get nodes
NAME LABELS STATUS centos-minion kubernetes.io/hostname=centos-minion Ready (ready表示成功)
[root@centos-master yum.repos.d]# kubectl cluster-info
Kubernetes master is running at http://localhost:8080
kubectl describe --help
可以看到资源的信息属性等
kubernetes中的namespace不是为了隔离,而是为了配额,比如,某个namespace只能占用10%的cpu
vi nginx-pod.yaml
apiVersion: v1
kind: Pod (资源类型)
metadata:
name: nginx
spec:
containers:
- name: nginx
image: nginx ports:
- containerPort: 80
可能会报错
//service account配置的问题,在之前的apiserver中的一个参数
[root@centos-master ~]# kubectl create -f nginx-pod.yaml Error from
server: error when creating "nginx-pod.yaml": Pod "nginx" is forbidden:
no API token found for service account default/default, retry after the
token is automatically created and added to the service account
参数在这里
KUBE_ADMISSION_CONTROL="-- admission_control=NamespaceLifecycle,NamespaceExists,LimitRanger
Secu,rityContextDeny,ServiceAccount,ResourceQuota"
查看状态
[root@centos-master ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx 0/1 Image: nginx is not ready on the node 0 56s
进入:
/etc/sysconfig/docker
添加配置:
INSECURE_REGISTRY='--insecure-registry gcr.io'