k8s lab on Atomic

Hostnames

192.168.1.125  atomic01
192.168.1.126  atomic02
192.168.1.127  atomic03

atomic01 will be the master atomic02, atomic03 will be the minions

Creating Virtual Machines

  • download the atomic kvm image -> link
  • create 3 virtual machines using that qcow2 as the primary disk and the following
  • add an addition 10GB black disk to each
  • attach a cloud-init iso to each VM

Creating the cloud-init iso

For each VM we have to create a cloud-init iso to set the network paramaters and password. For some good reading check out link

mkdir -p cloud-init/atomic01

cd cloud-init/atomic01

vi meta-data

instance-id: atomic01
local-hostname: atomic01
network-interfaces: |
  iface eth0 inet static
  address 192.168.1.123
  network 192.168.1.0
  netmask 255.255.255.0
  broadcast 192.168.1.255
  gateway 192.168.1.1
bootcmd:
  - ifdown eth0
  - ifup eth0

vi user-data

#cloud-config
password: atomic
chpasswd: {expire: False}
ssh_pwauth: True
ssh_authorized_keys:
  - ssh-rsa AAAAB3N......
  • use your id_rsa.pub for the ssh-rsa line

genisoimage -output atomic01-cidata.iso -volid cidata -joliet -rock user-data meta-data

Repeat for each atomic VM and attach the iso to the appropriate VM

Once booted you can now login to each VM with user name fedora and the password or ssh key you selected

Configure your atomic hosts

FYI, I got all this information from here link and here link2

run an update on all of your atomic hosts

sudo atomic host upgrade

add /dev/vdb to the volume group

sudo DEVS=/dev/vdb docker-storage-setup

expand root, you don't want root to fill up, very bad things happen

sudo lvextend -r -L +3GB /dev/atomicos/root

reboot each atomic host

sudo systemctl reboot

Configuring the kubernetes master

sudo vi /etc/etcd/etcd.conf

the following lines should be the only uncommented lines

ETCD_NAME=default
ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
ETCD_LISTEN_PEER_URLS="http://localhost:2380,http://localhost:7001"
ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:4001,http://0.0.0.0:2379"
ETCD_ADVERTISE_CLIENT_URLS="http://0.0.0.0:4001,http://0.0.0.0:2379"

sudo vi /etc/kubernetes/config

edit the following value

KUBE_MASTER="--master=http://atomic01:8080"

sudo vi /etc/kubernetes/apiserver

edit the following values

KUBE_API_ADDRESS="--address=0.0.0.0"
KUBE_ETCD_SERVERS="--etcd_servers=http://atomic01:4001"
KUBE_SERVICE_ADDRESSES="--service-cluster-ip-range=10.254.0.0/16"

enable and restart services

for SERVICES in etcd kube-apiserver kube-controller-manager kube-scheduler; do 
  sudo systemctl restart $SERVICES
  sudo systemctl enable $SERVICES
  sudo systemctl status $SERVICES 
done
configure kubernetes minions

sudo vi /etc/kubernetes/config

KUBE_MASTER="--master=http://atomic01:8080"

sudo vi /etc/kubernetes/kubelet

change the following lines and be sure to use the KUBELET_HOSTNAME of the system you're currently configuring

KUBELET_ADDRESS="--address=0.0.0.0"
KUBELET_HOSTNAME="--hostname_override=atomic02"
KUBELET_API_SERVER="--api_servers=http://atomic01:8080"
KUBELET_ARGS="--register-node=true"

sudo vi /etc/kubernetes/proxy

KUBE_PROXY_ARGS="--master=http://atomic01:8080"

restart kubelet and enable kubelet services

for SERVICES in docker kube-proxy.service kubelet.service; do 
  sudo systemctl restart $SERVICES
  sudo systemctl enable $SERVICES
  sudo systemctl status $SERVICES 
done
flannel network

on the master (atomic01)

sudo vi flannel-config.json

{
  "Network": "10.20.0.0/16",
  "SubnetLen": 24,
  "Backend": {
    "Type": "vxlan",
    "VNI": 1
  }  
}

upload the flannel config

etcdctl set coreos.com/network/config < flannel-config.json

check to make sure it worked

etcdctl get coreos.com/network/config

on all of your nodes edit the flanneld config

sudo vi /etc/sysconfig/flanneld

set the following value

FLANNEL_ETCD="http://atomic01:4001"

restart and enable the flanneld service

sudo systemctl restart flanneld.service
sudo systemctl enable flanneld.service
sudo systemctl status flanneld.service

reboot

sudo systemctl reboot

now remember to do that on all of your nodes

creating some containers

on the master (atomic01)

vi ghost.yaml

apiVersion: v1
id: ghost
kind: Pod
metadata:
  name: ghost
  labels:
    name: ghost
spec:
  containers:
    - name: ghost
      image: ghost:latest
      ports:
       - containerPort: 2368

vi ghostservice.yaml

apiVersion: v1
kind: Service
metadata:
  labels:
    name: ghost-service
  name: ghost-service
spec:
  ports:
  - port: 30061
    protocol: TCP
    targetPort: 2368
    nodePort: 30061
  selector:
    name: ghost
  type: NodePort

kubectl create -f ghost.yaml

kubectl create -f ghostservice.yaml

you can now access your ghost blog by connecting to any minion IP at port 30061