{"id":549,"date":"2019-03-05T04:01:38","date_gmt":"2019-03-05T04:01:38","guid":{"rendered":"http:\/\/www.asianux.org.vn\/?p=549"},"modified":"2019-03-05T04:08:29","modified_gmt":"2019-03-05T04:08:29","slug":"cai-dat-kubernetes-tren-ubuntu","status":"publish","type":"post","link":"https:\/\/www.asianux.org.vn\/index.php\/2019\/03\/05\/cai-dat-kubernetes-tren-ubuntu\/","title":{"rendered":"C\u00e0i \u0111\u1eb7t Kubernetes tr\u00ean Ubuntu"},"content":{"rendered":"\n<p>        Kubernetes l\u00e0 m\u1ed9t h\u1ec7 th\u1ed1ng m\u00e3 ngu\u1ed3n m\u1edf \u0111\u1ec3 t\u1ef1 \u0111\u1ed9ng tri\u1ec3n khai, scaling, qu\u1ea3n l\u00fd c\u00e1c container. Kubernetes \u0111\u01b0\u1ee3c x\u00e2y d\u1ef1ng b\u1edfi Google d\u1ef1a tr\u00ean kinh nghi\u1ec7m qu\u1ea3n l\u00fd s\u1eed d\u1ee5ng c\u00e1c container trong khi tri\u1ec3n khai m\u1ed9t h\u1ec7 th\u1ed1ng qu\u1ea3n l\u00fd g\u1ecdi l\u00e0 Borg ( nhi\u1ec1u l\u00fac g\u1ecdi l\u00e0 Omega). <\/p>\n\n\n\n<p>Chu\u1ea9n b\u1ecb <\/p>\n\n\n\n<p>C\u1ea5u h\u00ecnh \u0111\u1ecba ch\u1ec9 IP t\u0129nh<\/p>\n\n\n\n<p>vim \/etc\/network\/interfaces<\/p>\n\n\n\n<p>iface enp2s0 inet static<br>\n    address 172.16.12.120<br>\n    netmask 255.255.255.0<br>\n    network 172.16.12.0<br>\n    gateway 172.16.12.1<br>\n    dns-nameservers 8.8.8.8<\/p>\n\n\n\n<p>Thi\u1ebft l\u1eadp file host theo y\u00eau c\u1ea7u, ch\u00fa \u00fd thi\u1ebft l\u1eadp c\u1ea3 tr\u00ean master v\u00e0 c\u00e1c node<\/p>\n\n\n\n<p>vim \/etc\/hosts<\/p>\n\n\n\n<p>172.16.12.120   k8s-master<br>\n172.16.12.135   k8s-node1<br>\n172.16.12.136   k8s-node2<\/p>\n\n\n\n<p>service networking restart<\/p>\n\n\n\n<p>C\u1eadp nh\u1eadt c\u00e1c b\u1ea3n v\u00e1<\/p>\n\n\n\n<p>apt update &amp;&amp; apt upgrade -y<\/p>\n\n\n\n<p>Thi\u1ebft l\u1eadp kho c\u00e0i \u0111\u1eb7t k8s<\/p>\n\n\n\n<p>apt-get update &amp;&amp; apt-get install -y apt-transport-https curl<br>\ncurl -s https:\/\/packages.cloud.google.com\/apt\/doc\/apt-key.gpg | apt-key add &#8211;<\/p>\n\n\n\n<p>cat &lt;\/etc\/apt\/sources.list.d\/kubernetes.list<br>\ndeb https:\/\/apt.kubernetes.io\/ kubernetes-xenial main<br>\nEOF<\/p>\n\n\n\n<p>C\u00e0i \u0111\u1eb7t K8s<\/p>\n\n\n\n<p>apt-get update<br>apt-get install -y kubelet kubeadm kubectl docker.io<\/p>\n\n\n\n<p>Ti\u1ebfp theo c\u00e1c b\u1ea1n ch\u1ea1y l\u1ec7nh sau:<\/p>\n\n\n\n<p>kubeadm init &#8211;pod-network-cidr 10.244.0.0\/16<\/p>\n\n\n\n<p>cp -i \/etc\/kubernetes\/admin.conf $HOME\/.kube\/config<br>chown $(id -u):$(id -g) $HOME\/.kube\/confi<br>chown $(id -u):$(id -g) \/root\/.kube\/config<\/p>\n\n\n\n<p>Ti\u1ebfp t\u1ee5c ch\u1ea1y l\u1ec7nh<\/p>\n\n\n\n<p>kubectl apply -f https:\/\/raw.githubusercontent.com\/coreos\/flannel\/master\/Documentation\/kube-flannel.yml<\/p>\n\n\n\n<p>Th\u1ed1ng k\u00ea c\u00e1c namespaces \u0111ang ch\u1ea1y<\/p>\n\n\n\n<p>kubectl get pods &#8211;all-namespaces<br>\nwatch kubectl get pods &#8211;all-namespaces<\/p>\n\n\n\n<p>Kh\u1edfi \u0111\u1ed9ng l\u1ea1i d\u1ecbch v\u1ee5<\/p>\n\n\n\n<p>systemctl daemon-reload<br>\nsystemctl restart kubelet<br>\nkubectl get node<br>\nwatch kubectl get node<\/p>\n\n\n\n<p>C\u00e0i \u0111\u1eb7t Dashboard cho k8s<\/p>\n\n\n\n<p>kubectl apply -f https:\/\/raw.githubusercontent.com\/kubernetes\/dashboard\/v1.10.1\/src\/deploy\/recommended\/kubernetes-dashboard.yaml<\/p>\n\n\n\n<p>Run command <\/p>\n\n\n\n<p>cat &lt; \/root\/khanh1.yml<br>\napiVersion: v1<br>\nkind: ServiceAccount<br>\nmetadata:<br>\n  name: admin-user<br>\n  namespace: kube-system<br>\nEOF<\/p>\n\n\n\n<p>cat &lt; \/root\/khanh2.yml<br>\napiVersion: rbac.authorization.k8s.io\/v1<br>\nkind: ClusterRoleBinding<br>\nmetadata:<br>\n  name: admin-user<br>\nroleRef:<br>\n  apiGroup: rbac.authorization.k8s.io<br>\n  kind: ClusterRole<br>\n  name: cluster-admin<br>\nsubjects:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>kind: ServiceAccount<br>\nname: admin-user<br>\nnamespace: kube-system<\/li><\/ul>\n\n\n\n<p>EOF<\/p>\n\n\n\n<p>Th\u1ef1c hi\u1ec7n ch\u1ea1y l\u1ec7nh \u0111\u1ec3 apply<\/p>\n\n\n\n<p>kubectl apply -f \/root\/khanh1.yml <br>kubectl apply -f \/root\/khanh2.yml<\/p>\n\n\n\n<p>Hi\u1ec3n th\u1ecb token \u0111\u1ec3 \u0111\u0103ng nh\u1eadp v\u00e0o dashboard<\/p>\n\n\n\n<p>kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep admin-user | awk &#8216;{print $1}&#8217;)<\/p>\n\n\n\n<p>kubectl proxy &#8211;address 0.0.0.0 &#8211;accept-hosts=&#8217;^*$&#8217;<\/p>\n\n\n\n<p><a href=\"http:\/\/127.0.0.1:8001\/api\/v1\/namespaces\/kube-system\/services\/https:kubernetes-dashboard:\/proxy\/#!\/login\">http:\/\/127.0.0.1:8001\/api\/v1\/namespaces\/kube-system\/services\/https:kubernetes-dashboard:\/proxy\/#!\/login<\/a><\/p>\n\n\n\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; Install Keepalived &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Install <\/li><\/ol>\n\n\n\n<p>apt-get install keepalived -y<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Create file keepalived.conf<\/li><\/ol>\n\n\n\n<p>vrrp_instance VI_1 {<br>\n    state MASTER<br>\n    interface ens33<br>\n    virtual_router_id 101<br>\n    priority 101<br>\n    advert_int 1<br>\n    authentication {<br>\n        auth_type PASS<br>\n        auth_pass 1111<br>\n    }<br>\n    virtual_ipaddress {<br>\n        172.16.12.123<br>\n    }<br>\n}<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Copy file to node server and start it<\/li><\/ol>\n\n\n\n<p>service keepalived start<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Check <\/li><\/ol>\n\n\n\n<p>ip addr show eth0<\/p>\n\n\n\n<p>result<\/p>\n\n\n\n<p>2: ens33:  mtu 1500 qdisc pfifo_fast state UP group default qlen 1000<br>\n    link\/ether 00:0c:29:a5:ee:89 brd ff:ff:ff:ff:ff:ff<br>\n    inet 172.16.12.120\/24 brd 172.16.12.255 scope global ens33<br>\n       valid_lft forever preferred_lft forever<br>\n    inet 172.16.12.123\/32 scope global ens33<br>\n       valid_lft forever preferred_lft forever<br>\n    inet6 fe80::20c:29ff:fea5:ee89\/64 scope link<br>\n       valid_lft forever preferred_lft forever<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>   Note: Max 20 ip per vip<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n","protected":false},"excerpt":{"rendered":"<p>Kubernetes l\u00e0 m\u1ed9t h\u1ec7 th\u1ed1ng m\u00e3 ngu\u1ed3n m\u1edf \u0111\u1ec3 t\u1ef1 \u0111\u1ed9ng tri\u1ec3n khai, scaling, qu\u1ea3n l\u00fd c\u00e1c container. Kubernetes \u0111\u01b0\u1ee3c x\u00e2y d\u1ef1ng b\u1edfi Google d\u1ef1a tr\u00ean kinh nghi\u1ec7m qu\u1ea3n l\u00fd s\u1eed d\u1ee5ng c\u00e1c container trong&hellip;<\/p>\n","protected":false},"author":1,"featured_media":551,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-549","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/posts\/549","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/comments?post=549"}],"version-history":[{"count":2,"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/posts\/549\/revisions"}],"predecessor-version":[{"id":552,"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/posts\/549\/revisions\/552"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/media\/551"}],"wp:attachment":[{"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/media?parent=549"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/categories?post=549"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/tags?post=549"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}