節點:node
Master:git
192.168.88.71github
Node:docker
192.168.88.81express
環境:apache
[root@localhost ~]# cat /etc/redhat-releaseapi
CentOS Linux release 7.2.1511 (Core)網絡
[root@localhost ~]# uname -a app
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/Linuxless
禁用防火牆:
systemctl disable firewalld
systemctl stop firewalld
Master:
yum -y install etcd kubernetes flannel
Slave:
yum -y install docker kubernetes flannel
Master:
[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"
[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" }'
[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"
[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"
[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"
[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}
[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"
[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"
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
systemctl start docker
systemctl status docker
systemctl start kubelet
systemctl status kubelet
systemctl start kube-proxy.service
systemctl status kube-proxy.service
kubectl get node
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<this_file>
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