1、规划:

节点:

Master

192.168.88.71

Node

192.168.88.81

 

环境:

[root@localhost ~]# cat /etc/redhat-release

CentOS Linux release 7.2.1511 (Core)

[root@localhost ~]# uname -a               

Linux localhost.localdomain3.10.0-327.el7.x86_64 #1 SMP Thu Nov 19 22:10:57 UTC 2015 x86_64 x86_64 x86_64GNU/Linux

 

禁用防火墙:

systemctl disable firewalld

systemctl stop firewalld

 

2、安装:

Master

yum -y install etcd kubernetes flannel

Slave:

yum -y install docker kubernetes flannel

 

3Master配置:

Master

1etcd配置:

[root@localhost ~]# more/usr/lib/systemd/system/etcd.service

[Unit]

Description=Etcd Server

After=network.target

 

[Service]

Type=simple

WorkingDirectory=/var/lib/etcd/

EnvironmentFile=-/etc/etcd/etcd.conf

ExecStart=/usr/bin/etcd

 

[Install]

WantedBy=multi-user.target

 

[root@localhost ~]# more/etc/etcd/etcd.conf

ETCD_NAME=default

ETCD_DATA_DIR="/var/lib/etcd/default.etcd"

ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379"

 

2flannel配置:

[root@localhost etc]# more/usr/lib/systemd/system/flanneld.service

[Unit]

Description=Flanneld overlay address etcdagent

After=network.target

After=network-online.target

Wants=network-online.target

#After=etcd.service

Before=docker.service

 

[Service]

Type=notify

EnvironmentFile=/etc/sysconfig/flanneld

#EnvironmentFile=-/etc/sysconfig/docker-network

ExecStart=/usr/bin/flanneld-etcd-endpoints=${FLANNEL_ETCD} $FLANNEL_OPTIONS

#ExecStartPost=/usr/libexec/flannel/mk-docker-opts.sh-k DOCKER_NETWORK_OPTIONS -d /run/flannel/docker

#Restart=on-failure

 

[Install]

WantedBy=multi-user.target

RequiredBy=docker.service

 

 

[root@localhost etc]# more/etc/sysconfig/flanneld

FLANNEL_ETCD="http://192.168.88.71:2379"

FLANNEL_ETCD_KEY="/atomic.io/network"

 

etcdctl set /atomic.io/network/config '{"Network": "10.1.0.0/16" }'

 

3apiserver配置:

[root@localhost etc]# more/usr/lib/systemd/system/kube-apiserver.service

[Unit]

Description=Kubernetes API Server

Documentation=https://github.com/GoogleCloudPlatform/kubernetes

After=etcd.service

Wants=etcd.service

 

[Service]

EnvironmentFile=/etc/kubernetes/apiserver

ExecStart=/usr/bin/kube-apiserver \

           $KUBE_API_ARGS

Restart=on-failure

Type=notify

LimitNOFILE=65536

 

[Install]

WantedBy=multi-user.target

 

 

[root@localhost kubernetes]# more/etc/kubernetes/apiserver

KUBE_API_ARGS="--etcd_servers=http://127.0.0.1:2379--insecure-bind-address=0.0.0.0 --insecure-port=8080--service-cluster-ip-range=10.1.0.0/16 --se

rvice-node-port-range=1-65535--admission-control=NamespaceLifecycle,LimitRanger,SecurityContextDeny,ResourceQuota--logtostderr=false --log-dir=/va

r/log/kubernetes --v=2"

 

4controller-manager配置:

[root@localhost etc]# more/usr/lib/systemd/system/kube-controller-manager.service

[Unit]

Description=Kubernetes Controller Manager

Documentation=https://github.com/GoogleCloudPlatform/kubernetes

After=kube-apiserver.service

Requires=kube-apiserver.service

 

[Service]

EnvironmentFile=/etc/kubernetes/controller-manager

ExecStart=/usr/bin/kube-controller-manager\

           $KUBE_CONTROLLER_MANAGER_ARGS

Restart=on-failure

LimitNOFILE=65536

 

[Install]

WantedBy=multi-user.target

 

[root@localhost kubernetes]# more/etc/kubernetes/controller-manager

KUBE_CONTROLLER_MANAGER_ARGS="--master=http://192.168.88.71:8080--logtostderr=false --log-dir=/var/log/kubernetes --v=2"

 

 

5scheduler配置:

[Unit]

Description=Kubernetes Scheduler Plugin

Documentation=https://github.com/GoogleCloudPlatform/kubernetes

After=kube-apiserver.service

Requires=kube-apiserver.service

 

[Service]

EnvironmentFile=-/etc/kubernetes/scheduler

ExecStart=/usr/bin/kube-scheduler$KUBE_SCHEDULER_ARGS

Restart=on-failure

LimitNOFILE=65536

 

[Install]

WantedBy=multi-user.target

 

[root@localhost kubernetes]# more/etc/kubernetes/scheduler

KUBE_SCHEDULER_ARGS="--master=http://192.168.88.71:8080--logtostderr=false --log-dir=/var/log/kubernetes --v=2"

 

 

4Slave配置:

 

1Flannel配置:

[root@localhost ~]# more/usr/lib/systemd/system/flanneld.service

[Unit]

Description=Flanneld overlay address etcdagent

After=network.target

After=network-online.target

Wants=network-online.target

#After=etcd.service

Before=docker.service

 

[Service]

Type=notify

EnvironmentFile=/etc/sysconfig/flanneld

#EnvironmentFile=-/etc/sysconfig/docker-network

ExecStart=/usr/bin/flanneld-etcd-endpoints=${FLANNEL_ETCD} $FLANNEL_OPTIONS

#ExecStartPost=/usr/libexec/flannel/mk-docker-opts.sh-k DOCKER_NETWORK_OPTIONS -d /run/flannel/docker

#Restart=on-failure

 

[Install]

WantedBy=multi-user.target

RequiredBy=docker.service

 

[root@localhost ~]# more/etc/sysconfig/flanneld

FLANNEL_ETCD="http://192.168.88.71:2379"

FLANNEL_ETCD_KEY="/atomic.io/network"

 

注:

启动flanneld服务之前,需要在master etcd中添加一条网络配置记录,该配置用于flanneld分配给每个docker的虚拟IP地址段。

etcdctl set /atomic.io/network/config '{"Network": "10.1.0.0/16" }'

flannel将覆盖docker0网桥,故先停止docker服务。设置docker0的网桥IP地址:

mk-docker-opts.sh -i

source /run/flannel/subnet.env

ifconfig docker0 ${FLANNEL_SUBNET}

 

 

2Kubelet配置:

[root@localhost ~]# more/usr/lib/systemd/system/kubelet.service

[Unit]

Description=Kubernetes Kubelet Server

Documentation=https://github.com/GoogleCloudPlatform/kubernetes

After=docker.service

Requires=docker.service

 

[Service]

WorkingDirectory=/var/lib/kubelet

#EnvironmentFile=-/etc/kubernetes/config

EnvironmentFile=-/etc/kubernetes/kubelet

ExecStart=/usr/bin/kubelet \

           $KUBELET_ARGS

Restart=on-failure

 

[Install]

WantedBy=multi-user.target

 

 

[root@localhost ~]# more/etc/kubernetes/kubelet

KUBELET_ARGS="--api-servers=http://192.168.88.71:8080--hostname-override=192.168.88.10 --cluster_dns=10.1.0.100 --cluster_domain=cluster.local--log

tostderr=false--log-dir=/var/log/kubernetes --v=2--pod_infra_container_image=index.tenxcloud.com/google_containers/pause-amd64:3.0"

 

 

3kube-proxy配置:

[root@localhost ~]# more/usr/lib/systemd/system/kube-proxy.service

[Unit]

Description=Kubernetes Kube-Proxy Server

Documentation=https://github.com/GoogleCloudPlatform/kubernetes

After=network.target

Requires=network.service

 

[Service]

EnvironmentFile=-/etc/kubernetes/proxy

ExecStart=/usr/bin/kube-proxy \

           $KUBE_PROXY_ARGS

Restart=on-failure

LimitNOFILE=65536

 

[Install]

WantedBy=multi-user.target

 

 

[root@localhost ~]# more/etc/kubernetes/proxy

KUBE_PROXY_ARGS="--master=http://192.168.88.71:8080--logtostderr=false --log-dir=/var/log/kubernetes --v=2"

 

5、启动:

1master

systemctl start flanneld

systemctl status flanneld

systemctl start etcd

systemctl status etcd

systemctl start kube-apiserver.service

systemctl status kube-apiserver.service

systemctl startkube-controller-manager.service

systemctl status kube-controller-manager.service

systemctl start kube-scheduler.service

systemctl status kube-scheduler.service

 

2slave:

systemctl start docker

systemctl status docker

systemctl start kubelet

systemctl status kubelet

systemctl start kube-proxy.service

systemctl status kube-proxy.service

 

3)测试:

kubectl get node

 

 

6Dashboard:

kubectl create -f kubernetes-dashboard.yaml

 

more kubernetes-dashboard.yaml

# Copyright 2015 Google Inc. All RightsReserved.

#

# Licensed under the Apache License,Version 2.0 (the "License");

# you may not use this file except incompliance with the License.

# You may obtain a copy of the License at

#

#    http://www.apache.org/licenses/LICENSE-2.0

#

# Unless required by applicable law oragreed to in writing, software

# distributed under the License isdistributed on an "AS IS" BASIS,

# WITHOUT WARRANTIES OR CONDITIONS OF ANYKIND, either express or implied.

# See the License for the specific languagegoverning permissions and

# limitations under the License.

 

# Configuration to deploy release versionof the Dashboard UI.

#

# Example usage: kubectl create -f

 

kind: Deployment

apiVersion: extensions/v1beta1

metadata:

 labels:

   app: kubernetes-dashboard

   version: v1.1.1

 name: kubernetes-dashboard

 namespace: kube-system

spec:

 replicas: 1

 selector:

   matchLabels:

     app: kubernetes-dashboard

 template:

   metadata:

     labels:

       app: kubernetes-dashboard

   spec:

     containers:

     - name: kubernetes-dashboard

       image: index.tenxcloud.com/google_containers/kubernetes-dashboard-amd64:v1.4.1

       imagePullPolicy: Always

       ports:

       - containerPort: 9090

         protocol: TCP

       args:

         # Uncomment the following line to manually specify Kubernetes API serverHost

          # If not specified, Dashboard willattempt to auto discover the API server and connect

         # to it. Uncomment only if the default does not work.

       - --apiserver-host=http://192.168.88.71:8080 

       livenessProbe:

         httpGet:

            path: /

           port: 9090

         initialDelaySeconds: 30

         timeoutSeconds: 30

---

kind: Service

apiVersion: v1

metadata:

 labels:

   app: kubernetes-dashboard

 name: kubernetes-dashboard

 namespace: kube-system

spec:

 type: NodePort

 ports:

  -port: 80

   targetPort: 9090

 selector:

   app: kubernetes-dashboard

 

 

访问:

http://192.168.88.71:8080/ui