kubernetes deployment on "VMware Workstation Pro" or "VirtualBox"
In my lab setup:-
192.168.40.191 kmaster RHEL7.3 CPU_CORE:- 2 192.168.40.192 knode1 RHEL7.3 CPU_CORE:- 1 192.168.40.193 knode2 RHEL7.3 CPU_CORE:- 1
On both (Master and Node)
—————————–
In this example, I am going to disable SELinux on master and node both.
#sed -i -e s/enforcing/disabled/g /etc/sysconfig/selinux; #sed -i -e s/permissive/disabled/g /etc/sysconfig/selinux #setenforce 0 #sed -i --follow-symlinks 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux
Also, disable the firewall.
#systemctl disable firewalld #systemctl stop firewalld
Enable network bridge.
#modprobe br_netfilter #echo '1' > /proc/sys/net/bridge/bridge-nf-call-iptables
Make swap off for installation.
#swapoff -a && sed -i '/swap/d' /etc/fstab
Install requisitory(Docker)
#yum install -y yum-utils device-mapper-persistent-data lvm2 #yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo #yum install -y docker-ce
Add kubernetes repo to install kubernetes
#cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg
https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
EOF
#yum install -y kubelet kubeadm kubectl
#systemctl start docker && systemctl enable docker
#systemctl start kubelet && systemctl enable kubelet
#sed -i 's/cgroup-driver=systemd/cgroup-driver=cgroupfs/g' /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
#systemctl daemon-reload
On master only
——————-
Add network bridge configuration in a file and reload values.
[root@kmaster ~]# cat <<EOF > /etc/sysctl.d/k8s.conf net.bridge.bridge-nf-call-ip6tables = 1 net.bridge.bridge-nf-call-iptables = 1 EOF [root@kmaster ~]# sysctl --system
Put "admin.conf" in ".bash_profile" to load at login time.
[root@kmaster ~]# echo 'export KUBECONFIG=/etc/kubernetes/admin.conf' >> ~/.bash_profile [root@kmaster ~]# source ~/.bash_profile
Note:- If you are using any type of proxy on any node, disable before kubernetes initialization.
[root@kmaster ~]# unset http_proxy [root@kmaster ~]# unset https_proxy
Now launch the initialization script.
[root@kmaster ~]# kubeadm init --ignore-preflight-errors all --pod-network-cidr=10.244.0.0/16 --token-ttl 0 I0209 04:38:11.240261 4481 version.go:94] could not fetch a Kubernetes version from the internet: unable to get URL "https://dl.k8s.io/release/stable-1.txt": Get https://storage.googleapis.com/kubernetes-release/release/stable-1.txt: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers) I0209 04:38:11.240748 4481 version.go:95] falling back to the local client version: v1.13.3 [init] Using Kubernetes version: v1.13.3 [preflight] Running pre-flight checks [WARNING SystemVerification]: this Docker version is not on the list of validated versions: 18.09.0. Latest validated version: 18.06 [preflight] Pulling images required for setting up a Kubernetes cluster [preflight] This might take a minute or two, depending on the speed of your internet connection [preflight] You can also perform this action in beforehand using 'kubeadm config images pull' [kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env" [kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml" . . . [addons] Applied essential addon: CoreDNS [addons] Applied essential addon: kube-proxy Your Kubernetes master has initialized successfully! To start using your cluster, you need to run the following as a regular user: mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config You should now deploy a pod network to the cluster. Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at: https://kubernetes.io/docs/concepts/cluster-administration/addons/ You can now join any number of machines by running the following on each node as root: kubeadm join 192.168.40.184:6443 --token yz06cb.3mtnv1swalusctr1 --discovery-token-ca-cert-hash sha256:ea180f65eb0b8b3e6d0122300fa02d49592d08283c8f9f5091787ff080692c93
Run below command as suggested in the last installation screen.
[root@kmaster ~]# mkdir -p $HOME/.kube [root@kmaster ~]# sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config [root@kmaster ~]# sudo chown $(id -u):$(id -g) $HOME/.kube/config
Check name-spaces
[root@kmaster ~]# kubectl get pods --all-namespaces NAMESPACE NAME READY STATUS RESTARTS AGE kube-system coredns-86c58d9df4-2ftxf 0/1 Pending 0 2m52s kube-system coredns-86c58d9df4-plxft 0/1 Pending 0 2m52s kube-system etcd-kmaster 1/1 Running 0 2m20s kube-system kube-apiserver-kmaster 1/1 Running 0 2m13s kube-system kube-controller-manager-kmaster 1/1 Running 0 2m19s kube-system kube-proxy-fpr6w 1/1 Running 0 2m52s kube-system kube-scheduler-kmaster 1/1 Running 0 2m8s
Install POD network (only one pod network per cluster) to change "coredns" pending to running state.
[root@kmaster ~]# kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/bc79dd1505b0c8681ece4de4c0d86c5cd2643275/Documentation/kube-flannel.yml clusterrole.rbac.authorization.k8s.io/flannel created clusterrolebinding.rbac.authorization.k8s.io/flannel created serviceaccount/flannel created configmap/kube-flannel-cfg created daemonset.extensions/kube-flannel-ds-amd64 created daemonset.extensions/kube-flannel-ds-arm64 created daemonset.extensions/kube-flannel-ds-arm created daemonset.extensions/kube-flannel-ds-ppc64le created daemonset.extensions/kube-flannel-ds-s390x created
Now all are in running state.
[root@kmaster ~]# kubectl get pods --all-namespaces NAMESPACE NAME READY STATUS RESTARTS AGE kube-system coredns-86c58d9df4-2ftxf 1/1 Running 0 7m2s kube-system coredns-86c58d9df4-plxft 1/1 Running 0 7m2s kube-system etcd-kmaster 1/1 Running 0 6m30s kube-system kube-apiserver-kmaster 1/1 Running 0 6m23s kube-system kube-controller-manager-kmaster 1/1 Running 0 6m29s kube-system kube-flannel-ds-amd64-v59nj 1/1 Running 0 3m2s kube-system kube-proxy-fpr6w 1/1 Running 0 7m2s kube-system kube-scheduler-kmaster 1/1 Running 0 6m18s
To join any node with master cluster
[root@knode1 ~]# kubeadm join 192.168.40.184:6443 --token gfjzba.ci5gvqt09lqpspzm --discovery-token-ca-cert-hash sha256:0dfb374c6cc87683c0ff5e8e04e149738934c25ab2bcfb1ca72f501847f06301
To check available joined node on master
[root@kmaster ~]# kubectl get nodes NAME STATUS ROLES AGE VERSION kmaster Ready master 26h v1.13.3 knode1 Ready <none> 26h v1.13.3 knode2 Ready <none> 26h v1.13.3