Kubernetes quickstart on CentOS7
目录

1.实验环境

  • 三台KVM虚拟机
  • Centos7.3 x64

Kubernetes1.4.0

IP Address Role Service
192.168.122.100 Master kube-apiserver,kube-scheduler,kube-controller-manager,etcd,flannel
192.168.122.101 Minion1 kubelet,kube-proxy,docker,flannel
192.168.122.102 Minion2 kubelet,kube-proxy,docker,flannel

2.环境准备

在所有节点上执行以下命令:

# yum update -y

# systemctl stop firewalld
# systemctl disable firewalld

# yum -y install ntp
# systemctl start ntpd
# systemctl enable ntpd
  1. 软件安装

master节点:

# yum -y install etcd kubernetes-master flannel

minion节点:

# yum -y install docker flannel kubernetes-node
  1. 环境配置

master节点:

# egrep -v '^#' /etc/etcd/etcd.conf | grep -v '^$'
ETCD_NAME=default
ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379"
ETCD_ADVERTISE_CLIENT_URLS="http://localhost:2379"
# egrep -v '^#' /etc/kubernetes/apiserver | grep -v '^$'
KUBE_API_ADDRESS="--insecure-bind-address=0.0.0.0"
KUBE_ETCD_SERVERS="--etcd-servers=http://127.0.0.1:2379"
KUBE_SERVICE_ADDRESSES="--service-cluster-ip-range=10.254.0.0/16"
KUBE_ADMISSION_CONTROL="--admission-control=NamespaceLifecycle,NamespaceExists,LimitRanger,SecurityContextDeny,ResourceQuota"
KUBE_API_ARGS=""  # delete ServiceAccount
egrep -v '^#' /etc/sysconfig/flanneld | grep -v '^$'
FLANNEL_ETCD_ENDPOINTS="http://192.168.122.100:2379"
FLANNEL_ETCD_PREFIX="/atomic.io/network"

minion节点(IP_OF_MINION_NODE替换为minion节点的IP):

# egrep -v '^#' /etc/kubernetes/kubelet | grep -v '^$'
KUBELET_ADDRESS="--address=0.0.0.0"
KUBELET_HOSTNAME="--hostname-override=IP_OF_MINION_NODE"
KUBELET_API_SERVER="--api-servers=http://192.168.122.100:8080"
KUBELET_POD_INFRA_CONTAINER="--pod-infra-container-image=registry.access.redhat.com/rhel7/pod-infrastructure:latest"
KUBELET_ARGS=""
  1. 服务启动

master节点:

# for SERVICES in etcd kube-apiserver kube-controller-manager kube-scheduler flanneld; do
systemctl restart $SERVICES
systemctl enable $SERVICES
systemctl status $SERVICES
done
# etcdctl mk /atomic.io/network/config '{"Network":"172.17.0.0/16"}'

minion节点:

# for SERVICES in kube-proxy kubelet docker flanneld; do
systemctl restart $SERVICES
systemctl enable $SERVICES
systemctl status $SERVICES
done
  1. 服务验证
# kubectl get nodes
NAME              STATUS    AGE
192.168.122.101   Ready     2m
192.168.122.102   Ready     2m
  1. 安装Dashboard
# kubectl create -f https://rawgit.com/kubernetes/dashboard/master/src/deploy/kubernetes-dashboard.yaml
# kubectl get deployments --all-namespaces
NAMESPACE     NAME                   DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
kube-system   kubernetes-dashboard   1         0         0            0           28m
# kubectl proxy
Starting to serve on 127.0.0.1:8001

这里可能需要打开kubernetes-dashboard.yaml中以下一行的注释:

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

稍后等dashboard安装完毕,访问http://127.0.0.1:8001/ui 即可访问dashboard

参考:

  • https://severalnines.com/blog/installing-kubernetes-cluster-minions-centos7-manage-pods-services
  • http://www.fangyunlin.com/?p=54

发表评论