Kubernetes

= Kubernetes =

Kubernetes is an open source system for managing containerized applications across multiple hosts; providing basic mechanisms for deployment, maintenance, and scaling of applications.

All following tasks could be done with ansible from playbook repositories: http://git.altlinux.org/people/obirvalger/public/ansible-k8s.git, http://git.altlinux.org/people/obirvalger/public/ansible-test-nginx.git.

Preparing
Need one master node and some (three in this example) slave nodes. The following packages should be installed on the nodes:

Full network connectivity among all machines in the cluster should be present.

Cluster deployment
  The following command initializes cluster when running on master:
 * Flags explanation:
 * - internal net, this cidr is needed by Flannel;
 * - do not fail if too new docker version is installed.
 * At the end of the previous command output would be next command:
 * At the end of the previous command output would be next command:

  Configuring kubernetes to work from user (not from root).   Create directory :

  Copy config:

  Change config owner:

</li> </ol> </li>  Then join other nodes to master:
 * Nodes could be verified via:
 * Approximate output:
 * Approximate output:
 * Approximate output:

NAME     STATUS    ROLES     AGE       VERSION   INTERNAL-IP   EXTERNAL-IP   OS-IMAGE      KERNEL-VERSION        CONTAINER-RUNTIME docker1  Ready        4h        v1.11.2   10.10.3.23           ALT Regular   4.17.14-un-def-alt1   docker://Unknown docker2  Ready        4h        v1.11.2   10.10.3.120          ALT Regular   4.17.14-un-def-alt1   docker://Unknown docker3  Ready        4h        v1.11.2   10.10.3.157          ALT Regular   4.17.14-un-def-alt1   docker://Unknown k8s      Ready     master    4h        v1.11.2   10.10.3.227          ALT Regular   4.17.14-un-def-alt1   docker://Unknown </li>  Installing pod network addon:
 * Verifying network work:
 * Approximate output:
 * Approximate output:
 * Approximate output:

NAME                         READY     STATUS    RESTARTS   AGE coredns-78fcdf6894-6trk7     1/1       Running   0          2h coredns-78fcdf6894-nwt5l     1/1       Running   0          2h etcd-k8s                     1/1       Running   0          2h kube-apiserver-k8s           1/1       Running   0          2h kube-controller-manager-k8s  1/1       Running   0          2h kube-flannel-ds-894bt        1/1       Running   0          2h kube-flannel-ds-kbngw        1/1       Running   0          2h kube-flannel-ds-n7h45        1/1       Running   0          2h kube-flannel-ds-tz2rc        1/1       Running   0          2h kube-proxy-6f4lm             1/1       Running   0          2h kube-proxy-f92js             1/1       Running   0          2h kube-proxy-qkh54             1/1       Running   0          2h kube-proxy-szvlt             1/1       Running   0          2h kube-scheduler-k8s           1/1       Running   0          2h </li> </ol>

Note, that coredns</tt> should be in the Running</tt> state. Number of kube-flannel</tt> and kube-proxy</tt> accords to number of nodes (four in these example).

Test launch of nginx</tt>
<ol>  Lets create Deployment:

</li>  Then create service, to get external access to the our application;
 * Save the following configuration to the file :

apiVersion: v1 kind: Service metadata: name: nginx labels: app: nginx spec: type: NodePort ports: - port: 80 targetPort: 80 selector: app: nginx </li>  Run the service:

</li>  Get its port:
 * Approximate output:
 * Approximate output:

NAME     TYPE       CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGE nginx    NodePort   10.108.199.141          80:32336/TCP   4h </li>  And verify working of our application:
 * , где
 * ip_address - is the ip address of any node, and port gets from service. Example of command:.

</li> </ol>