Kubernetes: Difference between revisions
Obirvalger (talk | contribs) (Created page with "= Kubernetes = [https://en.wikipedia.org/wiki/Kubernetes Kubernetes] is an open source system for managing containerized applications across multiple hosts; providing basic m...") |
(Grammar fixes) |
||
(One intermediate revision by the same user not shown) | |||
Line 16: | Line 16: | ||
<ol> | <ol> | ||
<li> | <li> | ||
The following | The following command initializes cluster when running on master: | ||
: <code># kubeadm init --pod-network-cidr=10.244.0.0/16 --ignore-preflight-errors=SystemVerification</code>. | : <code># kubeadm init --pod-network-cidr=10.244.0.0/16 --ignore-preflight-errors=SystemVerification</code>. | ||
: Flags explanation: | : Flags explanation: | ||
:: <code>--pod-network-cidr=10.244.0.0/16</code> - internal net, this cidr is needed by <tt>Flannel</tt>; | :: <code>--pod-network-cidr=10.244.0.0/16</code> - internal net, this cidr is needed by <tt>Flannel</tt>; | ||
:: <code>--ignore-preflight-errors=SystemVerification</code> - do not fail | :: <code>--ignore-preflight-errors=SystemVerification</code> - do not fail if too new docker version is installed. | ||
: At the end of | : At the end of the previous command output would be next command: | ||
: <code>kubeadm join < | : <code>kubeadm join <ip_address>:<порт> --token <token> --discovery-token-ca-cert-hash sha256:<hash></code>. | ||
</li> | </li> | ||
<li> | <li> | ||
Configuring <tt>kubernetes</tt> to work from user ( | Configuring <tt>kubernetes</tt> to work from user (not from root). | ||
<ol> | <ol> | ||
<li> | <li> | ||
Create | Create directory {{path|~/.kube}}: | ||
: <code>$ mkdir ~/.kube</code>; | : <code>$ mkdir ~/.kube</code>; | ||
</li> | </li> | ||
Line 82: | Line 82: | ||
Note, that <tt>coredns</tt> should be in the <tt>Running</tt> state. | Note, that <tt>coredns</tt> should be in the <tt>Running</tt> state. | ||
Number of <tt>kube-flannel</tt> and <tt>kube-proxy</tt> | Number of <tt>kube-flannel</tt> and <tt>kube-proxy</tt> accords to number of nodes (four in these example). | ||
== Test launch of <tt>nginx</tt> == | == Test launch of <tt>nginx</tt> == | ||
Line 123: | Line 123: | ||
</li> | </li> | ||
<li> | <li> | ||
And verify working of | And verify working of our application: | ||
: <code>$ curl <ip_address>:<port></code>, где | : <code>$ curl <ip_address>:<port></code>, где | ||
: ip_address - is the ip address of any node, and port gets from service. Example of command: <code>curl 10.10.3.120:32336</code>. | : ip_address - is the ip address of any node, and port gets from service. Example of command: <code>curl 10.10.3.120:32336</code>. | ||
</li> | </li> | ||
</ol> | </ol> |
Latest revision as of 16:37, 21 December 2018
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:
# apt-get install docker-ce kubernetes-kubeadm kubernetes-kubelet cri-tools
Full network connectivity among all machines in the cluster should be present.
Cluster deployment
-
The following command initializes cluster when running on master:
# kubeadm init --pod-network-cidr=10.244.0.0/16 --ignore-preflight-errors=SystemVerification
.- Flags explanation:
--pod-network-cidr=10.244.0.0/16
- internal net, this cidr is needed by Flannel;--ignore-preflight-errors=SystemVerification
- do not fail if too new docker version is installed.
- At the end of the previous command output would be next command:
kubeadm join <ip_address>:<порт> --token <token> --discovery-token-ca-cert-hash sha256:<hash>
.
-
Configuring kubernetes to work from user (not from root).
-
Create directory ~/.kube:
$ mkdir ~/.kube
;
-
Copy config:
# cp /etc/kubernetes/admin.conf ~<username>/.kube/config
;
-
Change config owner:
# chown <username>: ~<username>/.kube/config
.
-
Create directory ~/.kube:
-
Then join other nodes to master:
# kubeadm join <ip_address>:<port> --token <token> --discovery-token-ca-cert-hash sha256:<hash> --ignore-preflight-errors=SystemVerification
.- Nodes could be verified via:
$ kubectl get nodes -o wide
- Approximate output:
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME docker1 Ready <none> 4h v1.11.2 10.10.3.23 <none> ALT Regular 4.17.14-un-def-alt1 docker://Unknown docker2 Ready <none> 4h v1.11.2 10.10.3.120 <none> ALT Regular 4.17.14-un-def-alt1 docker://Unknown docker3 Ready <none> 4h v1.11.2 10.10.3.157 <none> ALT Regular 4.17.14-un-def-alt1 docker://Unknown k8s Ready master 4h v1.11.2 10.10.3.227 <none> ALT Regular 4.17.14-un-def-alt1 docker://Unknown
-
Installing pod network addon:
$ kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
.- Verifying network work:
$ kubectl get pods --namespace kube-system
.
- 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
Note, that coredns should be in the Running state. Number of kube-flannel and kube-proxy accords to number of nodes (four in these example).
Test launch of nginx
-
Lets create Deployment:
$ kubectl apply -f https://k8s.io/examples/application/deployment.yaml
;
-
Then create service, to get external access to the our application;
- Save the following configuration to the file nginx-service.yaml:
apiVersion: v1 kind: Service metadata: name: nginx labels: app: nginx spec: type: NodePort ports: - port: 80 targetPort: 80 selector: app: nginx
-
Run the service:
$ kubectl apply -f nginx-service.yaml
.
-
Get its port:
$ kubectl get svc nginx
- Approximate output:
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE nginx NodePort 10.108.199.141 <none> 80:32336/TCP 4h
-
And verify working of our application:
$ curl <ip_address>:<port>
, где- ip_address - is the ip address of any node, and port gets from service. Example of command:
curl 10.10.3.120:32336
.