K8S(1)SetUpaCustomerCluster

Followingthisdocument

https://jimmysong.io/kubernetes-handbook/practice/install-kubernetes-on-ubuntu-server-16.04-with-kubeadm.html

Ihave2Ubuntumachines

192.168.56.101ubuntu-master

192.168.56.103ubuntu-dev4

MakeSureandInstallDocker

>apt-getinstalldocker.io

Checkversion

>docker--version

Dockerversion18.06.1-ce,builde68fc7a

Installthetools,butfail

>sudoapt-getinstallkubeletkubeadmkubectl

Noaptpackage"kubeadm",butthereisasnapwiththatname.

Try"snapinstallkubeadm"

Solution:

https://kubernetes.io/docs/tasks/tools/install-kubectl/#install-kubectl

>sudoapt-getupdate&&sudoapt-getinstall-yapt-transport-https

>curl-shttps://packages.cloud.google.com/apt/doc/apt-key.gpg|sudoapt-keyadd-

>echo"debhttps://apt.kubernetes.io/kubernetes-xenialmain"|sudotee-a/etc/apt/sources.list.d/kubernetes.list

>sudoapt-getupdate

>sudoapt-getinstallkubeletkubeadmkubectl

UseKubeadmtoinstallK8Scluster

SetUpMasterFirst

>sudokubeadminit--pod-network-cidr=10.244.0.0/16--apiserver-advertise-address=192.168.56.101

[preflight]Runningpre-flightchecks

errorexecutionphasepreflight:[preflight]Somefatalerrorsoccurred:

[ERRORSwap]:runningwithswaponisnotsupported.Pleasedisableswap

Disabletheswap

>sudoswapoff-a

>sudokubeadminit--pod-network-cidr=10.244.0.0/16--apiserver-advertise-address=192.168.56.101

[init]UsingKubernetesversion:v1.13.3

YourKubernetesmasterhasinitializedsuccessfully!

Tostartusingyourcluster,youneedtorunthefollowingasaregularuser:

mkdir-p$HOME/.kube

sudocp-i/etc/kubernetes/admin.conf$HOME/.kube/config

sudochown$(id-u):$(id-g)$HOME/.kube/config

Youshouldnowdeployapodnetworktothecluster.

Run"kubectlapply-f[podnetwork].yaml"withoneoftheoptionslistedat:

https://kubernetes.io/docs/concepts/cluster-administration/addons/

Youcannowjoinanynumberofmachinesbyrunningthefollowingoneachnode

asroot:

kubeadmjoin192.168.56.101:6443--tokenhwg09t.gmd6t2f7s3f18z2t--discovery-token-ca-cert-hashsha256:9eab712056ad59e628e852e40ab5889071865f6f925c8ef54c1a257eaf02f3d9

Followthedocs

>mkdir-p$HOME/.kube

>sudocp-i/etc/kubernetes/admin.conf$HOME/.kube/config

>sudochown$(id-u):$(id-g)/home/carl/.kube/config

SetUpSlaves

>sudoswapoff-a

>sudokubeadmjoin192.168.56.101:6443--tokenhwg09t.gmd6t2f7s3f18z2t--discovery-token-ca-cert-hashsha256:9eab712056ad59e628e852e40ab5889071865f6f925c8ef54c1a257eaf02f3d9

Thisnodehasjoinedthecluster:

*Certificatesigningrequestwassenttoapiserverandaresponsewasreceived.

*TheKubeletwasinformedofthenewsecureconnectiondetails.

Run'kubectlgetnodes'onthemastertoseethisnodejointhecluster.

Wecanruncommandonmastertoseethenodes

>kubectlgetnodes

NAMESTATUSROLESAGEVERSION

ubuntu-dev4NotReady<none>75sv1.13.3

ubuntu-masterNotReadymaster164mv1.13.3

Wecanalsocheckfrommaster

>kubectlgetpod-nkube-system-owide

Installthenetworkplugincanal

>kubectlapply-fhttps://docs.projectcalico.org/v3.0/getting-started/kubernetes/installation/hosted/canal/rbac.yaml

clusterrole.rbac.authorization.k8s.io/calicocreated

clusterrole.rbac.authorization.k8s.io/flannelcreated

clusterrolebinding.rbac.authorization.k8s.io/canal-flannelcreated

clusterrolebinding.rbac.authorization.k8s.io/canal-calicocreated

>kubectlapply-fhttps://docs.projectcalico.org/v3.0/getting-started/kubernetes/installation/hosted/canal/canal.yaml

configmap/canal-configcreated

daemonset.extensions/canalcreated

customresourcedefinition.apiextensions.k8s.io/felixconfigurations.crd.projectcalico.orgcreated

customresourcedefinition.apiextensions.k8s.io/bgpconfigurations.crd.projectcalico.orgcreated

customresourcedefinition.apiextensions.k8s.io/ippools.crd.projectcalico.orgcreated

customresourcedefinition.apiextensions.k8s.io/clusterinformations.crd.projectcalico.orgcreated

customresourcedefinition.apiextensions.k8s.io/globalnetworkpolicies.crd.projectcalico.orgcreated

customresourcedefinition.apiextensions.k8s.io/networkpolicies.crd.projectcalico.orgcreated

serviceaccount/canalcreated

Afterapplythesetwocommandsabove,wecheckthestatusagain,itisrunning

>kubectlgetpod-nkube-system-owide

Checknodestatus

>kubectlgetnode

NAMESTATUSROLESAGEVERSION

ubuntu-dev4Ready<none>20mv1.13.3

ubuntu-masterReadymaster3h3mv1.13.3

Enablerunningpodonmasteraswell

>kubectltaintnodes--allnode-role.kubernetes.io/master-

Turnofftheswapevenafterrestart

>sudoswapoff-a

>cat/etc/fstab|grep-v'^#'|grep-v'swap'|sudotee/etc/fstab

Checkingdocuments

https://juejin.im/post/5bb45d63f265da0a9e532128

SetUptheUI

>kubectlapply-fhttps://raw.githubusercontent.com/kubernetes/dashboard/master/aio/deploy/recommended/kubernetes-dashboard.yaml

secret/kubernetes-dashboard-certscreated

secret/kubernetes-dashboard-csrfcreated

serviceaccount/kubernetes-dashboardcreated

role.rbac.authorization.k8s.io/kubernetes-dashboard-minimalcreated

rolebinding.rbac.authorization.k8s.io/kubernetes-dashboard-minimalcreated

deployment.apps/kubernetes-dashboardcreated

service/kubernetes-dashboardcreated

>kubectlgetpods--namespace=kube-system

kubernetes-dashboard-57df4db6b-qs87d1/1Running069s

Checkallthepodrunning

>kubectlgetpods--namespace=kube-system-owide

NAMEREADYSTATUSRESTARTSAGEIPNODENOMINATEDNODEREADINESSGATES

canal-cfbbs3/3Running6125m192.168.56.103ubuntu-dev4<none><none>

canal-vsg6n3/3Running7125m192.168.56.101ubuntu-master<none><none>

coredns-86c58d9df4-9gs9l1/1Running14h53m10.244.0.4ubuntu-master<none><none>

coredns-86c58d9df4-ch28b1/1Running14h53m10.244.0.5ubuntu-master<none><none>

etcd-ubuntu-master1/1Running44h52m192.168.56.101ubuntu-master<none><none>

kube-apiserver-ubuntu-master1/1Running44h52m192.168.56.101ubuntu-master<none><none>

kube-controller-manager-ubuntu-master1/1Running44h52m192.168.56.101ubuntu-master<none><none>

kube-proxy-hp9n21/1Running44h53m192.168.56.101ubuntu-master<none><none>

kube-proxy-nmmvz1/1Running2130m192.168.56.103ubuntu-dev4<none><none>

kube-scheduler-ubuntu-master1/1Running44h52m192.168.56.101ubuntu-master<none><none>

kubernetes-dashboard-57df4db6b-qs87d1/1Running02m5s10.244.1.2ubuntu-dev4<none><none>

StartaProxyonubuntu-master

>kubectlproxy--address='0.0.0.0'--accept-hosts='^*'

https://kubernetes.io/docs/tasks/access-application-cluster/web-ui-dashboard/

Checkingnetwork

https://www.cnblogs.com/xzkzzz/p/9952716.html

>kubectlapply-fhttps://docs.projectcalico.org/v3.3/getting-started/kubernetes/installation/hosted/canal/rbac.yaml

>kubectlapply-fhttps://docs.projectcalico.org/v3.3/getting-started/kubernetes/installation/hosted/canal/canal.yaml

Copythefiletomyhostmachine

>scpubuntu-master:/home/carl/.kube/config~/.kube/config-ubuntu

>exportKUBECONFIG=~/.kube/config-ubuntu

ThenIcanrunthesecommandsonmyhostmachineaswell

>kubectlgetpods--namespace=kube-system-owide

>kubectlproxy

Startingtoserveon127.0.0.1:8001

Thiscommandneedtobeonubuntu-master

>kubectlproxy--address='0.0.0.0'--accept-hosts='^*'

TheseURLsdonotwork.

http://localhost:8001/api/v1/namespaces/kube-system/services/kubernetes-dashboard/proxy/#!/overview?namespace=default

http://localhost:8001/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/#!/overview?namespace=default

Ithinkitisrelatedthenetworksettings,thatIcannotping10.244.1.2whichtheadminconsoleisrunning

https://stackoverflow.com/questions/50401355/requests-timing-out-when-accesing-a-kubernetes-clusterip-service

Downloadthe2settingfiles

>wgethttps://docs.projectcalico.org/v3.3/getting-started/kubernetes/installation/hosted/canal/canal.yaml

Changethatfile

canal_iface:"enp0s8"

>kubectlapply-f./canal.yaml

Reboottheubuntu-master,thenitworks.

>ping10.244.1.4

PING10.244.1.4(10.244.1.4)56(84)bytesofdata.

64bytesfrom10.244.1.4:icmp_seq=1ttl=63time=0.739ms

Runtheproxyonmaster

>kubectlproxy--address='0.0.0.0'--accept-hosts='^*'

YEAH,thisUIwillwork

http://ubuntu-master:8001/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/#!/login

CheckTOKEN

>kubectlgetsecret-nkube-system|grepdashboard

kubernetes-dashboard-certsOpaque01h

kubernetes-dashboard-csrfOpaque11h

kubernetes-dashboard-key-holderOpaque21h

kubernetes-dashboard-token-d4p5xkubernetes.io/service-account-token31h

ChecktheDashboardIinstalled

>wgethttps://raw.githubusercontent.com/kubernetes/dashboard/master/aio/deploy/recommended/kubernetes-dashboard.yaml

Iusethiscommandalreadyfindoutthetoken

>kubectl-nkube-systemdescribesecret$(kubectl-nkube-systemgetsecret|grepkubernetes-dashboard-token|awk'{print$1}')|greptoken:|awk'{print$2}'

Giverightstoskip

>cat<<EOF|kubectlcreate-f-

apiVersion:rbac.authorization.k8s.io/v1beta1

kind:ClusterRoleBinding

metadata:

name:kubernetes-dashboard

labels:

k8s-app:kubernetes-dashboard

roleRef:

apiGroup:rbac.authorization.k8s.io

kind:ClusterRole

name:cluster-admin

subjects:

-kind:ServiceAccount

name:kubernetes-dashboard

namespace:kube-system

EOF

clusterrolebinding.rbac.authorization.k8s.io/kubernetes-dashboardcreated

Notworking,checkingthis

https://www.cnblogs.com/RainingNight/p/deploying-k8s-dashboard-ui.html

Itseemsthelatestdocumentsarehere

https://github.com/kubernetes/dashboard

https://github.com/kubernetes/dashboard/wiki/Creating-sample-user

References:

https://kubernetes.io/docs/setup/scratch/

http://docs.kubernetes.org.cn/774.html

https://www.jianshu.com/p/7d1fb03b8925

https://juejin.im/post/5bb45d63f265da0a9e532128

https://my.oschina.net/u/1013857/blog/2991314

https://zhanghongtong.github.io/2018/10/09/ubuntu-%E4%BD%BF%E7%94%A8kubeadm%E5%AE%89%E8%A3%85kubernetes/

https://jimmysong.io/kubernetes-handbook/practice/install-kubernetes-on-ubuntu-server-16.04-with-kubeadm.html