My Kubernetes cluster

Here is my Kubernetes cluster configuration :

  • Kubernetes version :
[root@k-master ~]# kubectl version
Client Version: version.Info{Major:"1", Minor:"0.3", GitVersion:"v1.0.3.34+b9a88a7d0e357b", GitCommit:"b9a88a7d0e357be2174011dd2b127038c6ea8929", GitTreeState:"clean"}
Server Version: version.Info{Major:"1", Minor:"0.3", GitVersion:"v1.0.3.34+b9a88a7d0e357b", GitCommit:"b9a88a7d0e357be2174011dd2b127038c6ea8929", GitTreeState:"clean"}
  • Kubernetes master :
[root@k-master ~]# kubectl cluster-info
Kubernetes master is running at http://localhost:8080
  • Kubernetes configuration :
[root@k-master ~]# kubectl config view
apiVersion: v1
clusters: []
contexts: []
current-context: ""
kind: Config
preferences: {}
users: []
  • Kubernetes nodes :
[root@k-master ~]# kubectl get nodes
NAME            LABELS                                 STATUS
192.168.1.131   kubernetes.io/hostname=192.168.1.131   Ready
192.168.1.132   kubernetes.io/hostname=192.168.1.132   Ready
192.168.1.133   kubernetes.io/hostname=192.168.1.133   Ready

And currently, we have no pod and no replication controler :

[root@k-master ~]# kubectl get pods
NAME      READY     STATUS    RESTARTS   AGE
[root@k-master ~]# kubectl get rc
CONTROLLER   CONTAINER(S)   IMAGE(S)   SELECTOR   REPLICAS

Create a “Nginx” pod

Create a “yaml” configuration file :

[root@k-master ~]# mkdir /examples
[root@k-master ~]# cd /examples
[root@k-master examples]# cat my_pod.yaml
apiVersion: v1
kind: ReplicationController
metadata:
  name: nginx
spec:
  replicas: 1
  selector:
    app: nginx
  template:
    metadata:
      name: nginx
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:latest
        ports:
        - hostPort: 8080
          containerPort: 80

Create a “pod” using this configuration file :

[root@k-master examples]# kubectl create -f my_pod.yaml
replicationcontrollers/nginx

Kubernetes is now downloading “nginx” image, then creating Docker container (it will take few minutes) :

[root@k-master examples]# kubectl get pods
NAME          READY     STATUS    RESTARTS   AGE
nginx-d0yop   0/1       Pending   0          1m

A replication controler has been created :

[root@k-master examples]# kubectl get rc
CONTROLLER   CONTAINER(S)   IMAGE(S)       SELECTOR    REPLICAS
nginx        nginx          nginx:latest   app=nginx   1

My “pod” is now running :

[root@k-master examples]# kubectl get pods
NAME          READY     STATUS    RESTARTS   AGE
nginx-d0yop   1/1       Running   0          11m

To get all details in “Json” format :

[root@k-master examples]# kubectl get pods -o json nginx-d0yop
{
    "kind": "Pod",
    "apiVersion": "v1",
    "metadata": {
        "name": "nginx-d0yop",
        "generateName": "nginx-",
        "namespace": "default",
        "selfLink": "/api/v1/namespaces/default/pods/nginx-d0yop",
        "uid": "4954377b-cb23-11e5-b33b-000c2985de56",
        "resourceVersion": "11738",
        "creationTimestamp": "2016-02-04T09:40:11Z",
        "labels": {
            "app": "nginx"
        },
        "annotations": {
            "kubernetes.io/created-by": "{\"kind\":\"SerializedReference\",\"apiVersion\":\"v1\",\"reference\":{\"kind\":\"ReplicationController\",\"namespace\":\"default\",\"name\":\"nginx\",\"uid\":\"49508740-cb23-11e5-b33b-000c2985de56\",\"apiVersion\":\"v1\",\"resourceVersion\":\"11682\"}}"
        }
    },
    "spec": {
        "containers": [
            {
                "name": "nginx",
                "image": "nginx:latest",
                "ports": [
                    {
                        "hostPort": 8080,
                        "containerPort": 80,
                        "protocol": "TCP"
                    }
                ],
                "resources": {},
                "terminationMessagePath": "/dev/termination-log",
                "imagePullPolicy": "Always"
            }
        ],
        "restartPolicy": "Always",
        "dnsPolicy": "ClusterFirst",
        "nodeName": "192.168.1.133"
    },
    "status": {
        "phase": "Running",
        "conditions": [
            {
                "type": "Ready",
                "status": "True"
            }
        ],
        "hostIP": "192.168.1.133",
        "podIP": "172.17.101.2",
        "startTime": "2016-02-04T09:40:11Z",
        "containerStatuses": [
            {
                "name": "nginx",
                "state": {
                    "running": {
                        "startedAt": "2016-02-04T09:42:20Z"
                    }
                },
                "lastState": {},
                "ready": true,
                "restartCount": 0,
                "image": "nginx:latest",
                "imageID": "docker://2b1e900b514d6358ff6f888622bcfdbe8001862450052b9f4b26c88849d388b4",
                "containerID": "docker://799e43fcbc1f34e37292f142459090435f433c79be805265d7b8ff30a3dc8e2e"
            }
        ]
    }
}

Now, go to node where the “pod” is running :

[root@k-master examples]# kubectl describe pod nginx | grep Node
Node:                           192.168.1.133/192.168.1.133

Logon to this node, and discover I.P. addresses :

[root@k-node3 ~]# hostname -I
192.168.1.133 172.17.101.0 172.17.101.1

Here are downloaded images :

[root@k-node3 ~]# docker images
REPOSITORY                       TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
docker.io/nginx                  latest              2b1e900b514d        8 days ago          134.4 MB
gcr.io/google_containers/pause   0.8.0               2c40b0526b63        10 months ago       241.7 kB

And running containers :

[root@k-node3 ~]# docker ps
CONTAINER ID        IMAGE                                  COMMAND                  CREATED             STATUS              PORTS                  NAMES
799e43fcbc1f        nginx:latest                           "nginx -g 'daemon off"   32 minutes ago      Up 32 minutes                              k8s_nginx.3bd6ec46_nginx-d0yop_default_4954377b-cb23-11e5-b33b-000c2985de56_3a22913b
e8e9d86dea1b        gcr.io/google_containers/pause:0.8.0   "/pause"                 34 minutes ago      Up 34 minutes       0.0.0.0:8080->80/tcp   k8s_POD.def4e8f1_nginx-d0yop_default_4954377b-cb23-11e5-b33b-000c2985de56_300f73bc

My “Nginx” instance works well :

[root@k-node3 ~]# curl -k http://172.17.101.2:80

nginx

 

 

 

 

Adding replicas

Right now, we only have 1 replica :

[root@k-master examples]# kubectl get rc
CONTROLLER   CONTAINER(S)   IMAGE(S)       SELECTOR    REPLICAS
nginx        nginx          nginx:latest   app=nginx   1

And we would like to spread replicas over all 3 nodes :

[root@k-master examples]# kubectl scale rc nginx --replicas=3
scaled

2 new pods are now in creating process :

[root@k-master examples]# kubectl get pods
NAME          READY     STATUS    RESTARTS   AGE
nginx-11xc5   0/1       Pending   0          1m
nginx-d0yop   1/1       Running   0          1h
nginx-u7kd3   0/1       Pending   0          1m

And running after few minutes :

[root@k-master examples]# kubectl get pods
NAME          READY     STATUS    RESTARTS   AGE
nginx-11xc5   1/1       Running   0          3m
nginx-d0yop   1/1       Running   0          1h
nginx-u7kd3   1/1       Running   0          3m

Remove pods

From the Kubernetes master, remove the replication controler :

[root@k-master examples]# kubectl delete rc nginx
replicationcontrollers/nginx

That will stop on nodes all containers used by these pods :

[root@k-node1 ~]# docker ps -a
CONTAINER ID        IMAGE                                  COMMAND                  CREATED             STATUS                     PORTS               NAMES
161f07e0b100        nginx:latest                           "nginx -g 'daemon off"   9 minutes ago       Exited (0) 2 minutes ago                       k8s_nginx.3bd6ec46_nginx-11xc5_default_2815faee-cb2c-11e5-b33b-000c2985de56_68c39237
8301f308aa85        gcr.io/google_containers/pause:0.8.0   "/pause"                 12 minutes ago      Exited (0) 2 minutes ago                       k8s_POD.def4e8f1_nginx-11xc5_default_2815faee-cb2c-11e5-b33b-000c2985de56_08f396e6
[root@k-node2 ~]# docker ps -a
CONTAINER ID        IMAGE                                  COMMAND                  CREATED             STATUS                     PORTS               NAMES
d8f4c4a0c0f1        nginx:latest                           "nginx -g 'daemon off"   10 minutes ago      Exited (0) 3 minutes ago                       k8s_nginx.3bd6ec46_nginx-u7kd3_default_28167b28-cb2c-11e5-b33b-000c2985de56_53c8e861
3c8f08e58927        gcr.io/google_containers/pause:0.8.0   "/pause"                 13 minutes ago      Exited (0) 3 minutes ago                       k8s_POD.def4e8f1_nginx-u7kd3_default_28167b28-cb2c-11e5-b33b-000c2985de56_80f31cc7
[root@k-node3 ~]# docker ps -a
CONTAINER ID        IMAGE                                  COMMAND                  CREATED             STATUS                     PORTS               NAMES
799e43fcbc1f        nginx:latest                           "nginx -g 'daemon off"   About an hour ago   Exited (0) 4 minutes ago                       k8s_nginx.3bd6ec46_nginx-d0yop_default_4954377b-cb23-11e5-b33b-000c2985de56_3a22913b
e8e9d86dea1b        gcr.io/google_containers/pause:0.8.0   "/pause"                 About an hour ago   Exited (0) 4 minutes ago                       k8s_POD.def4e8f1_nginx-d0yop_default_4954377b-cb23-11e5-b33b-000c2985de56_300f73bc

So, remove unused containers :

[root@k-node1 ~]# docker rm 161f07e0b100 8301f308aa85
161f07e0b100
8301f308aa85
[root@k-node2 ~]# docker rm d8f4c4a0c0f1 3c8f08e58927
d8f4c4a0c0f1
3c8f08e58927
[root@k-node3 ~]# docker rm 799e43fcbc1f e8e9d86dea1b
799e43fcbc1f
e8e9d86dea1b

And unused images :

[root@k-node1 ~]# docker images
REPOSITORY                       TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
docker.io/nginx                  latest              2b1e900b514d        8 days ago          134.4 MB
gcr.io/google_containers/pause   0.8.0               2c40b0526b63        10 months ago       241.7 kB
[root@k-node1 ~]# docker rmi 2b1e900b514d 2c40b0526b63
Untagged: docker.io/nginx:latest
Deleted: 2b1e900b514d6358ff6f888622bcfdbe8001862450052b9f4b26c88849d388b4
Deleted: d4202c2d289cbad1a4cf2e3e98122c680aedab4f9cf069f7d9916be8be8750c4
Deleted: 6fbf62f05bafcb42588259cb0ff94e6bb5a38e3d36052537d00abdb875a02097
Deleted: 9b35f2e19927961e2bfd792267cf99a2dbaff721533a6f7769e14fecb26d6d1f
Deleted: cc87edc856dec9698594b923777b6080f1279f358419ca019ca092d1bab605f9
Deleted: 2f4509f0578a716b5876332d3f9a4aff6edcbf57b2a710a71c5f6ae0cf634d73
Deleted: 5eb1402f041415f4d72ec331c9388e4981420dfe88ef4e9bdf904d4687e4de09
Deleted: 77e39ee8211729e81d1f83f0c64fdef97979b930a97ddc8194b8ea46d49f7b50
Untagged: gcr.io/google_containers/pause:0.8.0
Deleted: 2c40b0526b6358710fd09e7b8c022429268cc61703b4777e528ac9d469a07ca1
Deleted: 56ba5533a2dbf18b017ed12d99c6c83485f7146ed0eb3a2e9966c27fc5a5dd7b
Deleted: 511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158
[root@k-node2 ~]# docker images
REPOSITORY                       TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
docker.io/nginx                  latest              2b1e900b514d        8 days ago          134.4 MB
gcr.io/google_containers/pause   0.8.0               2c40b0526b63        10 months ago       241.7 kB
[root@k-node2 ~]# docker rmi 2b1e900b514d 2c40b0526b63
Untagged: docker.io/nginx:latest
Deleted: 2b1e900b514d6358ff6f888622bcfdbe8001862450052b9f4b26c88849d388b4
Deleted: d4202c2d289cbad1a4cf2e3e98122c680aedab4f9cf069f7d9916be8be8750c4
Deleted: 6fbf62f05bafcb42588259cb0ff94e6bb5a38e3d36052537d00abdb875a02097
Deleted: 9b35f2e19927961e2bfd792267cf99a2dbaff721533a6f7769e14fecb26d6d1f
Deleted: cc87edc856dec9698594b923777b6080f1279f358419ca019ca092d1bab605f9
Deleted: 2f4509f0578a716b5876332d3f9a4aff6edcbf57b2a710a71c5f6ae0cf634d73
Deleted: 5eb1402f041415f4d72ec331c9388e4981420dfe88ef4e9bdf904d4687e4de09
Deleted: 77e39ee8211729e81d1f83f0c64fdef97979b930a97ddc8194b8ea46d49f7b50
Untagged: gcr.io/google_containers/pause:0.8.0
Deleted: 2c40b0526b6358710fd09e7b8c022429268cc61703b4777e528ac9d469a07ca1
Deleted: 56ba5533a2dbf18b017ed12d99c6c83485f7146ed0eb3a2e9966c27fc5a5dd7b
Deleted: 511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158
[root@k-node3 ~]# docker images
REPOSITORY                       TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
docker.io/nginx                  latest              2b1e900b514d        8 days ago          134.4 MB
gcr.io/google_containers/pause   0.8.0               2c40b0526b63        10 months ago       241.7 kB
[root@k-node3 ~]# docker rmi 2b1e900b514d 2c40b0526b63
Untagged: docker.io/nginx:latest
Deleted: 2b1e900b514d6358ff6f888622bcfdbe8001862450052b9f4b26c88849d388b4
Deleted: d4202c2d289cbad1a4cf2e3e98122c680aedab4f9cf069f7d9916be8be8750c4
Deleted: 6fbf62f05bafcb42588259cb0ff94e6bb5a38e3d36052537d00abdb875a02097
Deleted: 9b35f2e19927961e2bfd792267cf99a2dbaff721533a6f7769e14fecb26d6d1f
Deleted: cc87edc856dec9698594b923777b6080f1279f358419ca019ca092d1bab605f9
Deleted: 2f4509f0578a716b5876332d3f9a4aff6edcbf57b2a710a71c5f6ae0cf634d73
Deleted: 5eb1402f041415f4d72ec331c9388e4981420dfe88ef4e9bdf904d4687e4de09
Deleted: 77e39ee8211729e81d1f83f0c64fdef97979b930a97ddc8194b8ea46d49f7b50
Untagged: gcr.io/google_containers/pause:0.8.0
Deleted: 2c40b0526b6358710fd09e7b8c022429268cc61703b4777e528ac9d469a07ca1
Deleted: 56ba5533a2dbf18b017ed12d99c6c83485f7146ed0eb3a2e9966c27fc5a5dd7b
Deleted: 511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158

 

 

tools.pdf24.org    Send article as PDF   

Leave a Reply

Your email address will not be published. Required fields are marked *


*