Running Kubernetes on AWS EC2

This article will walk-through installing and setting up Kubernetes on AWS instances step by step, This article not for people looking for fully automated command to setup Kubernetes cluster.

Note: This article not setup Kubernetes with SSL, and by default you should know AWS already.

Kubernetes Cluster Details:
1-To start install Kubernetes cluster you will need the below:
2- 3 AWS micro instances.
3- Kubernetes 1.9.0
4- Docker 1.13
5- Etcd 3.2
6- Flanneld 0.7
7- Fedora 27

INSTANCE01-HOSTNAME: kube01
INSTANCE02-HOSTNAME: kube02
INSTANCE03-HOSTNAME: kube03

Steps:
Let’s start first by install all required packages:
dnf install -y flannel etcd kubernetes

By applying the above command you will install Docker, Kubernetes*, etcd, flannel.

Configure Flannel by filling the below line:
FLANNEL_OPTIONS="-iface eth0 -ip-masq"

And please add ETCD prefix:
FLANNEL_ETCD_PREFIX="/atomic.io/network"

The complete file will looks like the below:

# Flanneld configuration options

# etcd url location. Point this to the server where etcd runs
FLANNEL_ETCD_ENDPOINTS=”http://127.0.0.1:2379″

# etcd config key. This is the configuration key that flannel queries
# For address range assignment
FLANNEL_ETCD_PREFIX=”/atomic.io/network”

# Any additional options that you want to pass
FLANNEL_OPTIONS=”-iface eth0 -ip-masq”

Now we need to configure ETCD cluster by adding the below lines into ETCd configuration file in each server:

ETCD_NAME=INSTANCE-HOSTNAME
ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
ETCD_LISTEN_PEER_URLS="http://INSTANCE_IP:2380"
ETCD_LISTEN_CLIENT_URLS="http://INSTANCE_IP:2379,http://localhost:2379"
ETCD_INITIAL_ADVERTISE_PEER_URLS="http://INSTANCE_IP:2380"
ETCD_INITIAL_CLUSTER="kube01=http://INSTANCE01-IP:2380,kube02=http://INSTNACE02-IP:2380,kube03=http://INSTANCE03-IP:2380"
ETCD_INITIAL_CLUSTER_STATE="new"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
ETCD_ADVERTISE_CLIENT_URLS="http://INSTANCE-IP:2379"

Now you can start ETCD:
Systemctl start etcd

Now we need to add flannel network configuration into ETCD, create new file flannel-config.json then import its value to ETCD:

{
"Network": "172.18.0.0/16",
"SubnetLen": 24,
"Backend": {
"Type": "vxlan",
"VNI": 100,
"Port": 8472
}
}

etcdctl set /atomic.io/network/config < fannel-config.json

Now we need to configure docker to not use iptables by adding the below to /etc/sysconfig/docker-network:

DOCKER_NETWORK_OPTIONS="--iptables=false"

Now the final step is configure Kubernetes by editing the below files:
/etc/kubernetes/apiserver
/etc/kubernetes/controller-manager
/etc/kubernetes/kubelet
/etc/kubernetes/scheduler

vim /etc/kubernetes/apiserver

###
# kubernetes system config
#
# The following values are used to configure the kube-apiserver
#

# The address on the local server to listen to.
KUBE_API_ADDRESS=”–insecure-bind-address=127.0.0.1″

# The port on the local server to listen on.
# KUBE_API_PORT=”–port=8080″

# Port minions listen on
# KUBELET_PORT=”–kubelet-port=10250″

# Comma separated list of nodes in the etcd cluster
KUBE_ETCD_SERVERS=”–etcd-servers=http://INSTANCE01:2379,http://INSTNCE02:2379,http://INSTANCE03:2379″

# Address range to use for services
KUBE_SERVICE_ADDRESSES=”–service-cluster-ip-range=10.254.0.0/16″

# default admission control policies
KUBE_ADMISSION_CONTROL=”–admission-control=NamespaceLifecycle,LimitRanger,SecurityContextDeny,ResourceQuota”

# Add your own!
KUBE_API_ARGS=””

vim /etc/kubernetes/controller-manager

###
# The following values are used to configure the kubernetes controller-manager

# defaults from config and apiserver should be adequate

# Add your own!
KUBE_CONTROLLER_MANAGER_ARGS=”–leader-elect=true”

/etc/kubernetes/kubelet

KUBELET_ADDRESS=”–address=0.0.0.0″
and comment the below:
KUBELET_HOSTNAME=”–hostname-override=127.0.0.1″

/etc/kubernetes/scheduler

###
# kubernetes scheduler config

# default config should be adequate

# Add your own!
KUBE_SCHEDULER_ARGS=”–leader-elect=true”

Now it’s time to start kubernetes cluster services:

systemctl enable kube-apiserver kube-controller-manager kube-scheduler kubelet kube-proxy etcd flanneld docker
systemctl start kube-apiserver kube-controller-manager kube-scheduler kubelet kube-proxy etcd flanneld docker

Now we can verify our installation by typing the below commands:

kubectl get nodes

The result will be:
NAME STATUS ROLES AGE VERSION
kube01 Ready 18s v1.9.0
kube02 Ready 18s v1.9.0
kube03 Ready 18s v1.9.0

We can deploy container as we want now 🙂