How to install Kubernetes
Using your editor edit hosts
sudo vi /etc/hostsAdd your node and master example
192.168.1.1 kubemaster
192.168.1.2 kubenode
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomainIn this tutorial, we will not cover about SELinux configuration for Docker, so we will disable it.
setenforce 0
sed -i --follow-symlinks 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinuxmodprobe br_netfilter
echo '1' > /proc/sys/net/bridge/bridge-nf-call-iptablesswapoff -athen comment your fstab example
#/dev/mapper/centos_localhost--live-swap swap swap defaults 0 0yum install -y yum-utils device-mapper-persistent-data lvm2Add the docker repository to the system and install docker-ce using the yum command.
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum install -y docker-ceAdd the kubernetes repository to the centos 7 system by running the following command.
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
EOFthen
yum install -y kubelet kubeadm kubectlreboot your master and node
rebootLog in again to the server and start the services, docker and kubelet.
systemctl start docker && systemctl enable docker
systemctl start kubelet && systemctl enable kubeletdocker info | grep -i cgroupAnd you see the docker is using 'cgroupfs' as a cgroup-driver.
Now run the command below to change the kuberetes cgroup-driver to 'cgroupfs'.
sed -i 's/cgroup-driver=systemd/cgroup-driver=cgroupfs/g' /etc/systemd/system/kubelet.service.d/10-kubeadm.confNow we're ready to configure the Kubernetes Cluster.
kubeadm init --apiserver-advertise-address=<master_ip> --pod-network-cidr=<your_cidr>Note:
Copy the 'kubeadm join ... ... ...' command to your text editor. The command will be used to register new nodes to the kubernetes cluster.
Now in order to use Kubernetes, we need to run some commands as on the result.
Create new '.kube' configuration directory and copy the configuration 'admin.conf'.
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/configNext, deploy the flannel network to the kubernetes cluster using the kubectl command.
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.ymlWait for a minute and then check kubernetes node and pods using commands below.
kubectl get nodes
kubectl get pods --all-namespacesYou Rember in kubeadm join..... copy from your editor then exec from your nodes example :
kubeadm join 192.168.1.1:6443 --token vzau5v.vjiqyxq26lzsf28e --discovery-token-ca-cert-hash sha256:e6d046ba34ee03e7d55e1f5ac6d2de09fd6d7e6959d16782ef0778794b94c61eWait for some minutes and back to the 'master' master cluster server check the nodes and pods using the following command.
Check your node from master
kubectl get nodes
kubectl get pods --all-namespacesSee Next Time
You can execute the run.sh file
sudo ./run.shSelect the List of Functions that exist then execute each step from 1-11
In this step, we will do a test by deploying the Nginx pod to the kubernetes cluster. A pod is a group of one or more containers with shared storage and network that runs under Kubernetes. A Pod contains one or more containers, such as Docker container.
Login to the 'master' server and create new deployment named 'nginx' using the kubectl command.
kubectl create deployment nginx --image=nginxTo see details of the 'nginx' deployment sepcification, run the following command.
kubectl describe deployment nginxAnd you will get the nginx pod deployment specification.
Next, we will expose the nginx pod accessible via the internet. And we need to create new service NodePort for this.
Run the kubectl command below.
kubectl create service nodeport nginx --tcp=80:80Make sure there is no error. Now check the nginx service nodeport and IP using the kubectl command below.
kubectl get pods
kubectl get svcfrom your master curl on port (remember port from your service | kubectl get svc)
curl node:30691then from your browser open url : node_ip:30691