Kubernetes - simple install on CentOS 7 with Web UI

Posted on Wed 26 October 2016 by Pavlo Khmel

This posts shows working kubernetes setup on CentOS 7.2.1511. Some steps are not covered in other articles on the internet.
Current Kubernetes release version 1.2.0-0.13 in the CentOS default repositories.

0. Install 2 servers

All your kubernetes nodes will be in 3 different subnets at the same time:

  • External interface subnet: 10.0.1.0/24
  • Flannel subnet: 172.17.0.0/16 # Do not use existing subnet
  • Service cluster subnet: 10.10.10.0/24 # Do not use existing subnet

Each server has 1 Ethernet adapter. Example configuration:

kubernetes

1. Install kube-master

Update /etc/hosts file:

cat << 'EOF' > /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
10.0.1.82 kube-master
10.0.1.83 kube-minion-1
EOF

Set hostname, disable firewall, disable selinux, install packages:

hostnamectl set-hostname kube-master
systemctl disable firewalld
systemctl stop firewalld
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
setenforce 0
yum -y install etcd kubernetes flannel

Etcd configuration:

cat << 'EOF' > /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"
ETCD_ADVERTISE_CLIENT_URLS="http://0.0.0.0:2379"
EOF

Start etcd and add configuration for flanneld:

systemctl start etcd
etcdctl mk /atomic.io/network/config '{"Network":"172.17.0.0/16"}'

Kube-apiserver configuration:

cat << 'EOF' > /etc/kubernetes/apiserver
KUBE_API_ADDRESS="--insecure-bind-address=0.0.0.0"
KUBE_API_PORT="--port=8080"
KUBELET_PORT="--kubelet-port=10250"
KUBE_ETCD_SERVERS="--etcd-servers=http://kube-master:2379"
KUBE_SERVICE_ADDRESSES="--service-cluster-ip-range=10.10.10.0/24"
KUBE_ADMISSION_CONTROL="--admission-control=NamespaceLifecycle,NamespaceExists,LimitRanger,SecurityContextDeny,ResourceQuota"
KUBE_API_ARGS=""
EOF

Kubernetes configuration:

cat << 'EOF' > /etc/kubernetes/config
KUBE_LOGTOSTDERR="--logtostderr=true"
KUBE_LOG_LEVEL="--v=0"
KUBE_ALLOW_PRIV="--allow-privileged=false"
KUBE_MASTER="--master=http://kube-master:8080"
EOF

Flanneld configuration:

cat << 'EOF' > /etc/sysconfig/flanneld
FLANNEL_ETCD="http://kube-master:2379"
FLANNEL_ETCD_KEY="/atomic.io/network"
EOF

Enable and start services:

for SERVICES in etcd kube-apiserver kube-controller-manager kube-scheduler kube-proxy docker flanneld; do 
    systemctl restart $SERVICES; 
    systemctl enable $SERVICES; 
    systemctl status $SERVICES; 
done

Reboot master:

reboot

2. Install kube-minion-1

Update /etc/hosts:

cat << 'EOF' > /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
10.0.1.82 kube-master
10.0.1.83 kube-minion-1
EOF

Set hostname, disable firewall, disable selinux, install packages:

hostnamectl set-hostname kube-minion-1
systemctl disable firewalld
systemctl stop firewalld
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
setenforce 0
yum -y install kubernetes flannel

Flannel configuration:

cat << 'EOF' > /etc/sysconfig/flanneld
FLANNEL_ETCD="http://kube-master:2379"
FLANNEL_ETCD_KEY="/atomic.io/network"
EOF

Kubernetes configuration:

cat << 'EOF' > /etc/kubernetes/config
KUBE_LOGTOSTDERR="--logtostderr=true"
KUBE_LOG_LEVEL="--v=0"
KUBE_ALLOW_PRIV="--allow-privileged=false"
KUBE_MASTER="--master=http://kube-master:8080"
EOF

Kubelet configuration:

cat << 'EOF' > /etc/kubernetes/kubelet
KUBELET_ADDRESS="--address=0.0.0.0"
KUBELET_PORT="--port=10250"
KUBELET_HOSTNAME="--hostname-override=kube-minion-1"
KUBELET_API_SERVER="--api-servers=http://kube-master:8080"
KUBELET_ARGS=""
EOF

Enable and start services:

for SERVICES in kube-proxy kubelet flanneld docker; do 
    systemctl restart $SERVICES; 
    systemctl enable $SERVICES; 
    systemctl status $SERVICES; 
done

Reboot minion:

reboot

3. Check setup

On kube-master run this command when both servers are up to check node status:

# kubectl get nodes 
NAME            STATUS    AGE
kube-minion-1   Ready     7m

4. Install Web UI (Dashboard)

Download yaml file and change it:

curl -O https://rawgit.com/kubernetes/dashboard/master/src/deploy/kubernetes-dashboard.yaml
vi kubernetes-dashboard.yaml

Uncomment this line: "- --apiserver-host" and and set:

    - --apiserver-host=http://10.0.1.82:8080 # kube master IP address

Create namespace, create deployment and service:

kubectl create namespace kube-system
kubectl create -f kubernetes-dashboard.yaml

Wait for status: Running

# kubectl get pods -a -o wide --all-namespaces
NAMESPACE     NAME                                   READY     STATUS    RESTARTS   AGE       NODE
kube-system   kubernetes-dashboard-749351892-omi0m   1/1       Running   0          28s       kube-minion-1

Open: http://10.0.1.82:8080/ui

5. Run your first pod:

We'll create pod with nginx and service that opens access from external interface:

Create file pod-nginx.yaml:

cat << 'EOF' > nginx-pod.yaml
apiVersion: v1
kind: Pod
metadata:
  name: nginx
  labels:
    app: nginx
spec:
  containers:
  - name: nginx
    image: nginx
    ports:
    - containerPort: 80
EOF

Create pod from file and check status:

kubectl create -f nginx-pod.yaml
kubectl get pods -a -o wide --all-namespaces

Create file pod-nginx-service.yaml:

cat << 'EOF' > nginx-service.yaml 
apiVersion: v1
kind: Service
metadata:
  name: nginx-service
spec:
  externalIPs:
    - 10.0.1.83 # master or minion external IP
  ports:
    - port: 80
  selector:
    app: nginx
EOF

Create service from file and check:

kubectl create -f nginx-service.yaml
kubectl get services -a -o wide --all-namespaces

Open Nginx default page: http://10.0.1.82/