1. 二进制文件添加

cp  kube-apiserver kube-controller-manager   kube-scheduler   /opt/kubernetes/bin/  &&  chmod +x /opt/kubernetes/bin/*

2.token添加  token是在制作bootstrap.kubeconfig 和  kube-proxy.kubeconfig生成的

 cp token.csv   /opt/kubernetes/cfg/

3.二进制包下载

https://dl.k8s.io/v1.9.10/kubernetes-server-linux-amd64.tar.gz

4.部署master节点的脚本 生成api-server 以及controller-manager  scheduler的配置文件 以及启动文件

https://github.com/kubernetes/kubernetes/tree/master/cluster/centos

https://github.com/kubernetes/kubernetes/tree/master/cluster/centos/master/scripts

5.部署apiserver

[root@k8s-master master_pkg]# cat apiserver.sh 
#!/bin/bash

MASTER_ADDRESS=${1:-"192.168.56.10"}
ETCD_SERVERS=${2:-"https://192.168.56.10:2379,https://192.168.56.11:2379,https://192.168.56.12:2379"}

cat </opt/kubernetes/cfg/kube-apiserver

KUBE_APISERVER_OPTS="--logtostderr=true \\
--v=4 \\
--etcd-servers=${ETCD_SERVERS} \\
--insecure-bind-address=127.0.0.1 \\
--bind-address=${MASTER_ADDRESS} \\
--insecure-port=8080 \\
--secure-port=6443 \\
--advertise-address=${MASTER_ADDRESS} \\
--allow-privileged=true \\
--service-cluster-ip-range=10.10.10.0/24 \\
--admission-control=NamespaceLifecycle,LimitRanger,SecurityContextDeny,ServiceAccount,ResourceQuota,NodeRestriction \
--authorization-mode=RBAC,Node \\
--kubelet-https=true \\
--enable-bootstrap-token-auth \\
--token-auth-file=/opt/kubernetes/cfg/token.csv \\
--service-node-port-range=30000-50000 \\
--tls-cert-file=/opt/kubernetes/ssl/server.pem  \\
--tls-private-key-file=/opt/kubernetes/ssl/server-key.pem \\
--client-ca-file=/opt/kubernetes/ssl/ca.pem \\
--service-account-key-file=/opt/kubernetes/ssl/ca-key.pem \\
--etcd-cafile=/opt/kubernetes/ssl/ca.pem \\
--etcd-certfile=/opt/kubernetes/ssl/server.pem \\
--etcd-keyfile=/opt/kubernetes/ssl/server-key.pem"

EOF

cat </usr/lib/systemd/system/kube-apiserver.service
[Unit]
Description=Kubernetes API Server
Documentation=https://github.com/kubernetes/kubernetes

[Service]
EnvironmentFile=-/opt/kubernetes/cfg/kube-apiserver
ExecStart=/opt/kubernetes/bin/kube-apiserver \$KUBE_APISERVER_OPTS
Restart=on-failure

[Install]
WantedBy=multi-user.target
EOF

systemctl daemon-reload
systemctl enable kube-apiserver
systemctl restart kube-apiserver
[root@k8s-master master_pkg]#

部署controller-manager  master的地址写成127.0.0.1就行了

#!/bin/bash

MASTER_ADDRESS=${1:-"127.0.0.1"}

cat </opt/kubernetes/cfg/kube-controller-manager


KUBE_CONTROLLER_MANAGER_OPTS="--logtostderr=true \\
--v=4 \\
--master=${MASTER_ADDRESS}:8080 \\
--leader-elect=true \\
--address=127.0.0.1 \\
--service-cluster-ip-range=10.10.10.0/24 \\
--cluster-name=kubernetes \\
--cluster-signing-cert-file=/opt/kubernetes/ssl/ca.pem \\
--cluster-signing-key-file=/opt/kubernetes/ssl/ca-key.pem  \\
--service-account-private-key-file=/opt/kubernetes/ssl/ca-key.pem \\
--root-ca-file=/opt/kubernetes/ssl/ca.pem"

EOF

cat </usr/lib/systemd/system/kube-controller-manager.service
[Unit]
Description=Kubernetes Controller Manager
Documentation=https://github.com/kubernetes/kubernetes

[Service]
EnvironmentFile=-/opt/kubernetes/cfg/kube-controller-manager
ExecStart=/opt/kubernetes/bin/kube-controller-manager \$KUBE_CONTROLLER_MANAGER_OPTS
Restart=on-failure

[Install]
WantedBy=multi-user.target
EOF

systemctl daemon-reload
systemctl enable kube-controller-manager
systemctl restart kube-controller-manager

部署scheduler  

scheduler  地址也写成127.0.0.1 因为apiserver写的不安全地址是127.0.0.1  直接用内网地址就行 用ip的画还得用证书

#!/bin/bash

MASTER_ADDRESS=${1:-"127.0.0.1"}

cat </opt/kubernetes/cfg/kube-scheduler

KUBE_SCHEDULER_OPTS="--logtostderr=true \\
--v=4 \\
--master=${MASTER_ADDRESS}:8080 \\
--leader-elect"

EOF

cat </usr/lib/systemd/system/kube-scheduler.service
[Unit]
Description=Kubernetes Scheduler
Documentation=https://github.com/kubernetes/kubernetes

[Service]
EnvironmentFile=-/opt/kubernetes/cfg/kube-scheduler
ExecStart=/opt/kubernetes/bin/kube-scheduler \$KUBE_SCHEDULER_OPTS
Restart=on-failure

[Install]
WantedBy=multi-user.target
EOF

systemctl daemon-reload
systemctl enable kube-scheduler
systemctl restart kube-scheduler

测试下

[root@k8s-master master_pkg]# kubectl  get cs

NAME                 STATUS    MESSAGE              ERROR

controller-manager   Healthy   ok                   

scheduler            Healthy   ok                   

etcd-2               Healthy   {"health": "true"}   

etcd-1               Healthy   {"health": "true"}   

etcd-0               Healthy   {"health": "true"}   

[root@k8s-master master_pkg]# 



备注:

每个docker容器配置的ip地址在flanneld中定义的

flanneld的会从etcd的配置找出来网段 分配node节点一个子网


service的ip地址是在apiserver和controller-manager的配置文件中定义的