#Kubernetes in a few steps

Howdy,

There’s a lot online info how to set your kubernetes cluster. This is what I found as the simplest to install your own local one.

I am using my own lab server with Centos7 and qemu-kvm. I’ve created two servers called k8scluster and k8snode01 using centos7 cloud images (check the script here)

./virt-create-centos7.sh k8scluster01 8192 4 20 10.10.10.17
./virt-create-centos7.sh k8snode01 8192 4 20 10.10.10.18

I have a local DNS server based on bind. I’ve created both CNAME registers and their reverse under the domain nuage.lab. I’ve ensured that k8snode01 can be accessed from k8scluster with no password thru ssh.
I will use k8scluster as my ansible node. Before go further. Let’s do an update to both servers and let’s install git on k8scluster.

yum -y update
yum -y install git

Install Ansible

rpm -iUvh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-8.noarch.rpm
yum -y update
yum -y install ansible

Install python-netaddr

yum install -y python-netaddr

Get the kubernetes scripts for installation

git clone https://github.com/kubernetes/contrib

You will see something like this

[root@k8scluster ~]# git clone https://github.com/kubernetes/contrib
Cloning into 'contrib'...
remote: Counting objects: 30900, done.
remote: Total 30900 (delta 0), reused 0 (delta 0), pack-reused 30900
Receiving objects: 100% (30900/30900), 32.66 MiB | 12.22 MiB/s, done.
Resolving deltas: 100% (14903/14903), done.
Checking out files: 100% (16112/16112), done.

Create ~/contrib/ansible/inventory/inventory file under with the following content:

k8scluster.nuage.lab

[etcd:children]
masters

[nodes]
k8snode01.nuage.lab
k8scluster.nuage.lab

And make changes to ~/contrib/ansible/inventory/group_vars/all.yml denpending on what you want. My case I’ve kept everything like it is. However, you will want to change kube_service_addresses to something that can be routed. That way you will access your apps thru this external network.

#this is all.yml file
source_type: packageManager 
cluster_name: cluster.local 
insecure_registrys:
kube_service_addresses: 10.254.0.0/16
networking: flannel
flannel_subnet: 172.16.0.0
flannel_prefix: 12
flannel_host_prefix: 24
cluster_logging: true
cluster_monitoring: true
kube-ui: false
kube-dash: false
dns_setup: true
dns_replicas: 1

Check if you are done:

[root@k8scluster ~]# kubectl cluster-info
Kubernetes master is running at http://localhost:8080
Elasticsearch is running at http://localhost:8080/api/v1/proxy/namespaces/kube-system/services/elasticsearch-logging
Heapster is running at http://localhost:8080/api/v1/proxy/namespaces/kube-system/services/heapster
Kibana is running at http://localhost:8080/api/v1/proxy/namespaces/kube-system/services/kibana-logging
KubeDNS is running at http://localhost:8080/api/v1/proxy/namespaces/kube-system/services/kube-dns
Grafana is running at http://localhost:8080/api/v1/proxy/namespaces/kube-system/services/monitoring-grafana
InfluxDB is running at http://localhost:8080/api/v1/proxy/namespaces/kube-system/services/monitoring-influxdb

Let’s launch our first app to see if everything is ok

[root@k8scluster ~]# kubectl run my-nginx --image=nginx --replicas=2 --port=80
deployment "my-nginx" created
[root@k8scluster ~]# kubectl expose deployment my-nginx --target-port=80 --type=LoadBalancer
service "my-nginx" exposed
[root@k8scluster ~]# kubectl get po
NAME                        READY     STATUS              RESTARTS   AGE
my-nginx-3800858182-8yckb   0/1       ContainerCreating   0          23s
my-nginx-3800858182-u08tn   0/1       ContainerCreating   0          23s
[root@k8scluster ~]# kubectl get service my-nginx
NAME       CLUSTER-IP      EXTERNAL-IP   PORT(S)   AGE
my-nginx   10.254.173.92                 80/TCP    16s
[root@k8scluster ~]# kubectl get po
NAME                        READY     STATUS    RESTARTS   AGE
my-nginx-3800858182-8yckb   1/1       Running   0          1m
my-nginx-3800858182-u08tn   1/1       Running   0          1m

Nice! let’s check our workloads on both servers. what we have into k8scluster:

[root@k8scluster ~]# docker ps
CONTAINER ID        IMAGE                                                 COMMAND                  CREATED             STATUS              PORTS               NAMES
477f0b39ae0d        nginx                                                 "nginx -g 'daemon off"   2 minutes ago       Up 2 minutes                            k8s_my-nginx.94312989_my-nginx-3800858182-8yckb_default_653df6f4-6ec7-11e6-946c-5254005e6a02_d0f8e009
89fce9ac474d        gcr.io/google_containers/pause:2.0                    "/pause"                 3 minutes ago       Up 3 minutes                            k8s_POD.cf58006d_my-nginx-3800858182-8yckb_default_653df6f4-6ec7-11e6-946c-5254005e6a02_dafc30db
439976e37027        gcr.io/google_containers/fluentd-elasticsearch:1.19   "td-agent"               About an hour ago   Up About an hour                        k8s_fluentd-elasticsearch.51dac75b_fluentd-elasticsearch-k8scluster.nuage.lab_kube-system_376c1ce61440747f2227a035bf5bb17b_eb7745cc
98f48c58c474        gcr.io/google_containers/pause:2.0                    "/pause"                 About an hour ago   Up About an hour                        k8s_POD.6059dfa2_fluentd-elasticsearch-k8scluster.nuage.lab_kube-system_376c1ce61440747f2227a035bf5bb17b_08185552

What we have into k8snode01 now:

[root@k8snode01 ~]# docker ps
CONTAINER ID        IMAGE                                                 COMMAND                  CREATED             STATUS              PORTS               NAMES
bc608aa29e2e        nginx                                                 "nginx -g 'daemon off"   2 minutes ago       Up 2 minutes                            k8s_my-nginx.94312989_my-nginx-3800858182-u08tn_default_6542ee6a-6ec7-11e6-946c-5254005e6a02_31e8f6a5
c658b776e20f        gcr.io/google_containers/pause:2.0                    "/pause"                 3 minutes ago       Up 3 minutes                            k8s_POD.cf58006d_my-nginx-3800858182-u08tn_default_6542ee6a-6ec7-11e6-946c-5254005e6a02_ddeadd38
77e8b8fdcb41        gcr.io/google_containers/kibana:1.3                   "/run.sh"                57 minutes ago      Up 57 minutes                           k8s_kibana-logging.80b4be80_kibana-logging-v1-tr7gz_kube-system_cf01c929-6ebd-11e6-946c-5254005e6a02_5d93fb99
de16f0337cc7        gcr.io/google_containers/exechealthz:1.0              "/exechealthz '-cmd=n"   59 minutes ago      Up 59 minutes                           k8s_healthz.ea531445_kube-dns-v11-rlt2r_kube-system_cf1fec49-6ebd-11e6-946c-5254005e6a02_9628ffa7
4f444be782a1        gcr.io/google_containers/skydns:2015-10-13-8c72f8c    "/skydns -machines=ht"   About an hour ago   Up About an hour                        k8s_skydns.24fb3a98_kube-dns-v11-rlt2r_kube-system_cf1fec49-6ebd-11e6-946c-5254005e6a02_4bd8d957
3a09f30dd267        gcr.io/google_containers/kube2sky:1.14                "/kube2sky --domain=c"   About an hour ago   Up About an hour                        k8s_kube2sky.7d240133_kube-dns-v11-rlt2r_kube-system_cf1fec49-6ebd-11e6-946c-5254005e6a02_7c38394d
96807c8d4455        gcr.io/google_containers/heapster_grafana:v2.6.0-2    "/bin/sh -c /run.sh"     About an hour ago   Up About an hour                        k8s_grafana.1848ba5c_monitoring-influxdb-grafana-v3-7en7m_kube-system_ceec7cba-6ebd-11e6-946c-5254005e6a02_0a28dbca
00d14bd0e4c6        gcr.io/google_containers/heapster:v1.0.2              "/heapster --source=k"   About an hour ago   Up About an hour                        k8s_heapster.a26e01fd_heapster-v1.0.2-1708347466-lf034_kube-system_cd39989b-6ebd-11e6-946c-5254005e6a02_a5351837
f6216bf7a16f        gcr.io/google_containers/addon-resizer:1.0            "/pod_nanny --cpu=100"   About an hour ago   Up About an hour                        k8s_eventer-nanny.8f2cc828_heapster-v1.0.2-1708347466-lf034_kube-system_cd39989b-6ebd-11e6-946c-5254005e6a02_3a71361e
8fb90fba2478        gcr.io/google_containers/addon-resizer:1.0            "/pod_nanny --cpu=100"   About an hour ago   Up About an hour                        k8s_heapster-nanny.9bd7c896_heapster-v1.0.2-1708347466-lf034_kube-system_cd39989b-6ebd-11e6-946c-5254005e6a02_d31a75d1
652a39c4b6c5        gcr.io/google_containers/elasticsearch:1.8            "/run.sh"                About an hour ago   Up About an hour                        k8s_elasticsearch-logging.99ece1ea_elasticsearch-logging-v1-ze2qu_kube-system_cf06f4d7-6ebd-11e6-946c-5254005e6a02_d38a078b
aa244cf22bed        gcr.io/google_containers/elasticsearch:1.8            "/run.sh"                About an hour ago   Up About an hour                        k8s_elasticsearch-logging.99ece1ea_elasticsearch-logging-v1-dvlpp_kube-system_cf09c6e7-6ebd-11e6-946c-5254005e6a02_a3a35e15
3416beba5e4f        gcr.io/google_containers/etcd-amd64:2.2.1             "/usr/local/bin/etcd "   About an hour ago   Up About an hour                        k8s_etcd.2bcc34f7_kube-dns-v11-rlt2r_kube-system_cf1fec49-6ebd-11e6-946c-5254005e6a02_9a144f9c
931a1e1536f1        gcr.io/google_containers/heapster_influxdb:v0.5       "influxd --config /et"   About an hour ago   Up About an hour                        k8s_influxdb.a62d4047_monitoring-influxdb-grafana-v3-7en7m_kube-system_ceec7cba-6ebd-11e6-946c-5254005e6a02_d82b2ded
a1877c5ffd04        gcr.io/google_containers/fluentd-elasticsearch:1.19   "td-agent"               About an hour ago   Up About an hour                        k8s_fluentd-elasticsearch.51dac75b_fluentd-elasticsearch-k8snode01.nuage.lab_kube-system_376c1ce61440747f2227a035bf5bb17b_a691a8f2
a50553d32497        gcr.io/google_containers/heapster:v1.0.2              "/eventer --source=ku"   About an hour ago   Up About an hour                        k8s_eventer.90caf32a_heapster-v1.0.2-1708347466-lf034_kube-system_cd39989b-6ebd-11e6-946c-5254005e6a02_f7742136
efc7d81a02bd        gcr.io/google_containers/pause:2.0                    "/pause"                 About an hour ago   Up About an hour                        k8s_POD.558027c8_elasticsearch-logging-v1-ze2qu_kube-system_cf06f4d7-6ebd-11e6-946c-5254005e6a02_16e51798
941a3f1de554        gcr.io/google_containers/pause:2.0                    "/pause"                 About an hour ago   Up About an hour                        k8s_POD.558027c8_elasticsearch-logging-v1-dvlpp_kube-system_cf09c6e7-6ebd-11e6-946c-5254005e6a02_b1d84cd6
108a66b1700f        gcr.io/google_containers/pause:2.0                    "/pause"                 About an hour ago   Up About an hour                        k8s_POD.7e0801af_kibana-logging-v1-tr7gz_kube-system_cf01c929-6ebd-11e6-946c-5254005e6a02_31b6ed7c
5cfa71d299a0        gcr.io/google_containers/pause:2.0                    "/pause"                 About an hour ago   Up About an hour                        k8s_POD.55c42327_monitoring-influxdb-grafana-v3-7en7m_kube-system_ceec7cba-6ebd-11e6-946c-5254005e6a02_7da9e87e
4001bac015e8        gcr.io/google_containers/pause:2.0                    "/pause"                 About an hour ago   Up About an hour                        k8s_POD.e2764897_kube-dns-v11-rlt2r_kube-system_cf1fec49-6ebd-11e6-946c-5254005e6a02_0470156f
5173e4b465b5        gcr.io/google_containers/pause:2.0                    "/pause"                 About an hour ago   Up About an hour                        k8s_POD.6059dfa2_heapster-v1.0.2-1708347466-lf034_kube-system_cd39989b-6ebd-11e6-946c-5254005e6a02_4cfc7a00
23b2330f25ad        gcr.io/google_containers/pause:2.0                    "/pause"                 About an hour ago   Up About an hour                        k8s_POD.6059dfa2_fluentd-elasticsearch-k8snode01.nuage.lab_kube-system_376c1ce61440747f2227a035bf5bb17b_b5e949e6

Let’s clean this app up.

[root@k8scluster ~]# kubectl delete deployment,service my-nginx
deployment "my-nginx" deleted
service "my-nginx" deleted
[root@k8scluster ~]# kubectl get po
[root@k8scluster ~]# 

See ya!

2 thoughts on “#Kubernetes in a few steps

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s