Install kubernetes with kubeadm

Add repo to pull required packages in all nodes

cat << /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 kubeadm kubelet kubectl -y

Installed:
kubeadm.x86_64 0:1.13.4-0 kubectl.x86_64 0:1.13.4-0 kubelet.x86_64 0:1.13.4-0

Dependency Installed:
conntrack-tools.x86_64 0:1.4.4-4.el7 cri-tools.x86_64 0:1.12.0-0 kubernetes-cni.x86_64 0:0.6.0-0 libnetfilter_cthelper.x86_64 0:1.0.0-9.el7 libnetfilter_cttimeout.x86_64 0:1.0.0-6.el7 libnetfilter_queue.x86_64 0:1.0.2-2.el7_2
socat.x86_64 0:1.7.3.2-2.el7

swapoff -a

yum install docker -y

docker –version
Docker version 1.13.1, build 07f3374/1.13.1

systemctl start docker

systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.

[root@gcpnode ~]# kubeadm init –pod-network-cidr=192.168.0.0/16 –apiserver-advertise-address=172.16.189.129
[init] Using Kubernetes version: v1.13.4
[preflight] Running pre-flight checks
[WARNING Hostname]: hostname “gcpnode” could not be reached
[WARNING Hostname]: hostname “gcpnode”: lookup gcpnode on 172.16.189.2:53: no such host
[WARNING Service-Kubelet]: kubelet service is not enabled, please run ‘systemctl enable kubelet.service’
error execution phase preflight: [preflight] Some fatal errors occurred:
[ERROR FileContent–proc-sys-net-bridge-bridge-nf-call-iptables]: /proc/sys/net/bridge/bridge-nf-call-iptables contents are not set to 1
[preflight] If you know what you are doing, you can make a check non-fatal with `–ignore-preflight-errors=…`
[root@gcpnode ~]# cat /proc/sys/net/bridge/bridge-nf-call-iptables
0
[root@gcpnode ~]# echo “1” >> /proc/sys/net/bridge/bridge-nf-call-iptables
[root@gcpnode ~]# cat /proc/sys/net/bridge/bridge-nf-call-iptables
1

[root@gcpnode ~]# kubeadm init –pod-network-cidr=192.168.0.0/16 –apiserver-advertise-address=172.16.189.129
[init] Using Kubernetes version: v1.13.4
[preflight] Running pre-flight checks
[WARNING Hostname]: hostname “gcpnode” could not be reached
[WARNING Hostname]: hostname “gcpnode”: lookup gcpnode on 172.16.189.2:53: no such host
[WARNING Service-Kubelet]: kubelet service is not enabled, please run ‘systemctl enable kubelet.service’
[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”
[kubelet-start] Activating the kubelet service
[certs] Using certificateDir folder “/etc/kubernetes/pki”
[certs] Generating “etcd/ca” certificate and key
[certs] Generating “etcd/server” certificate and key
[certs] etcd/server serving cert is signed for DNS names [gcpnode localhost] and IPs [172.16.189.129 127.0.0.1 ::1]
[certs] Generating “apiserver-etcd-client” certificate and key
[certs] Generating “etcd/peer” certificate and key
[certs] etcd/peer serving cert is signed for DNS names [gcpnode localhost] and IPs [172.16.189.129 127.0.0.1 ::1]
[certs] Generating “etcd/healthcheck-client” certificate and key
[certs] Generating “ca” certificate and key
[certs] Generating “apiserver” certificate and key
[certs] apiserver serving cert is signed for DNS names [gcpnode kubernetes kubernetes.default kubernetes.default.svc kubernetes.default.svc.cluster.local] and IPs [10.96.0.1 172.16.189.129]
[certs] Generating “apiserver-kubelet-client” certificate and key
[certs] Generating “front-proxy-ca” certificate and key
[certs] Generating “front-proxy-client” certificate and key
[certs] Generating “sa” key and public key
[kubeconfig] Using kubeconfig folder “/etc/kubernetes”
[kubeconfig] Writing “admin.conf” kubeconfig file
[kubeconfig] Writing “kubelet.conf” kubeconfig file
[kubeconfig] Writing “controller-manager.conf” kubeconfig file
[kubeconfig] Writing “scheduler.conf” kubeconfig file
[control-plane] Using manifest folder “/etc/kubernetes/manifests”
[control-plane] Creating static Pod manifest for “kube-apiserver”
[control-plane] Creating static Pod manifest for “kube-controller-manager”
[control-plane] Creating static Pod manifest for “kube-scheduler”
[etcd] Creating static Pod manifest for local etcd in “/etc/kubernetes/manifests”
[wait-control-plane] Waiting for the kubelet to boot up the control plane as static Pods from directory “/etc/kubernetes/manifests”. This can take up to 4m0s
[kubelet-check] Initial timeout of 40s passed.
[apiclient] All control plane components are healthy after 72.504800 seconds
[uploadconfig] storing the configuration used in ConfigMap “kubeadm-config” in the “kube-system” Namespace
[kubelet] Creating a ConfigMap “kubelet-config-1.13” in namespace kube-system with the configuration for the kubelets in the cluster
[patchnode] Uploading the CRI Socket information “/var/run/dockershim.sock” to the Node API object “gcpnode” as an annotation
[mark-control-plane] Marking the node gcpnode as control-plane by adding the label “node-role.kubernetes.io/master=””
[mark-control-plane] Marking the node gcpnode as control-plane by adding the taints [node-role.kubernetes.io/master:NoSchedule]
[bootstrap-token] Using token: tatn25.lt0s1pgxns3kpapb
[bootstrap-token] Configuring bootstrap tokens, cluster-info ConfigMap, RBAC Roles
[bootstraptoken] configured RBAC rules to allow Node Bootstrap tokens to post CSRs in order for nodes to get long term certificate credentials
[bootstraptoken] configured RBAC rules to allow the csrapprover controller automatically approve CSRs from a Node Bootstrap Token
[bootstraptoken] configured RBAC rules to allow certificate rotation for all node client certificates in the cluster
[bootstraptoken] creating the “cluster-info” ConfigMap in the “kube-public” namespace
[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 172.16.189.129:6443 –token tatn25.lt0s1pgxns3kpapb –discovery-token-ca-cert-hash sha256:c65b9ed09b8c4e35f7e7faf7d936c12b3e4f5548cb150fd5d0e8c6388ba8bc9f

[root@gcpnode ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
k8s.gcr.io/kube-proxy v1.13.4 fadcc5d2b066 10 days ago 80.3 MB
k8s.gcr.io/kube-apiserver v1.13.4 fc3801f0fc54 10 days ago 181 MB
k8s.gcr.io/kube-controller-manager v1.13.4 40a817357014 10 days ago 146 MB
k8s.gcr.io/kube-scheduler v1.13.4 dd862b749309 10 days ago 79.6 MB
k8s.gcr.io/coredns 1.2.6 f59dcacceff4 4 months ago 40 MB
k8s.gcr.io/etcd 3.2.24 3cab8e1b9802 5 months ago 220 MB
k8s.gcr.io/pause 3.1 da86e6ba6ca1 14 months ago 742 kB

[root@gcpnode ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
83ee38953403 40a817357014 “kube-controller-m…” 23 seconds ago Up 22 seconds k8s_kube-controller-manager_kube-controller-manager-gcpnode_kube-system_b30ce9858497a34dadbe52741470ee5b_1
becce82038ed fadcc5d2b066 “/usr/local/bin/ku…” 24 seconds ago Up 23 seconds k8s_kube-proxy_kube-proxy-594sn_kube-system_443c5a8f-433e-11e9-b180-000c29dffc37_1
a349f28837bb k8s.gcr.io/pause:3.1 “/pause” 24 seconds ago Up 23 seconds k8s_POD_kube-proxy-594sn_kube-system_443c5a8f-433e-11e9-b180-000c29dffc37_1
97e7191b61d7 k8s.gcr.io/pause:3.1 “/pause” 24 seconds ago Up 24 seconds k8s_POD_kube-controller-manager-gcpnode_kube-system_b30ce9858497a34dadbe52741470ee5b_0
6e444e33c90d 3cab8e1b9802 “etcd –advertise-…” 34 seconds ago Up 34 seconds k8s_etcd_etcd-gcpnode_kube-system_faa722c754b9780d7e6f8b9119f5636e_1
20ffed9b9d5b k8s.gcr.io/pause:3.1 “/pause” 34 seconds ago Up 34 seconds k8s_POD_etcd-gcpnode_kube-system_faa722c754b9780d7e6f8b9119f5636e_1
32cbf600f14e fc3801f0fc54 “kube-apiserver –…” 34 seconds ago Up 34 seconds k8s_kube-apiserver_kube-apiserver-gcpnode_kube-system_79ccb4a130ffa06785f1a4797fc93771_2
362143ce4ee0 dd862b749309 “kube-scheduler –…” 49 seconds ago Up 49 seconds k8s_kube-scheduler_kube-scheduler-gcpnode_kube-system_4b52d75cab61380f07c0c5a69fb371d4_1
d68b7f5e05e5 k8s.gcr.io/pause:3.1 “/pause” 49 seconds ago Up 49 seconds k8s_POD_kube-scheduler-gcpnode_kube-system_4b52d75cab61380f07c0c5a69fb371d4_1
c33e4164f384 k8s.gcr.io/pause:3.1 “/pause” About a minute ago Up About a minute k8s_POD_kube-apiserver-gcpnode_kube-system_79ccb4a130ffa06785f1a4797fc93771_1

[root@gcpnode ~]# mkdir -p $HOME/.kube

[root@gcpnode ~]# cp -i /etc/kubernetes/admin.conf $HOME/.kube/config

[root@gcpnode ~]# chown $(id -u):$(id -g) $HOME/.kube/config

[root@gcpnode ~]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
gcpnode NotReady master 18m v1.13.4

[root@gcpnode ~]# kubectl get ns
NAME STATUS AGE
default Active 14m
kube-public Active 14m
kube-system Active 14m

[root@gcpnode ~]# kubectl get pods –all-namespaces
NAMESPACE NAME READY STATUS RESTARTS AGE
kube-system coredns-86c58d9df4-8fcsx 0/1 Pending 0 12m
kube-system coredns-86c58d9df4-v66wh 0/1 Pending 0 12m
kube-system etcd-gcpnode 1/1 Running 1 12m
kube-system kube-apiserver-gcpnode 1/1 Running 2 13m
kube-system kube-controller-manager-gcpnode 1/1 Running 1 4m5s
kube-system kube-proxy-594sn 1/1 Running 1 12m
kube-system kube-scheduler-gcpnode 1/1 Running 1 12m

[root@gcpnode ~]# wget https://git.io/weave-kube-1.6

[root@gcpnode ~]# kubectl apply -f weave-kube-1.6
serviceaccount/weave-net created
clusterrole.rbac.authorization.k8s.io/weave-net created
clusterrolebinding.rbac.authorization.k8s.io/weave-net created
role.rbac.authorization.k8s.io/weave-net created
rolebinding.rbac.authorization.k8s.io/weave-net created
daemonset.extensions/weave-net created

[root@gcpnode ~]# kubectl get pods -o wide –all-namespaces
NAMESPACE NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
kube-system coredns-86c58d9df4-8fcsx 1/1 Running 0 25m 10.32.0.3 gcpnode
kube-system coredns-86c58d9df4-v66wh 1/1 Running 0 25m 10.32.0.2 gcpnode
kube-system etcd-gcpnode 1/1 Running 1 25m 172.16.189.129 gcpnode
kube-system kube-apiserver-gcpnode 1/1 Running 2 25m 172.16.189.129 gcpnode
kube-system kube-controller-manager-gcpnode 1/1 Running 1 16m 172.16.189.129 gcpnode
kube-system kube-proxy-594sn 1/1 Running 1 25m 172.16.189.129 gcpnode
kube-system kube-scheduler-gcpnode 1/1 Running 1 25m 172.16.189.129 gcpnode
kube-system weave-net-z68f9 2/2 Running 0 86s 172.16.189.129 gcpnode

[root@gcpnode ~]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
gcpnode Ready master 27m v1.13.4

[root@gcpnode ~]# kubeadm token list
TOKEN TTL EXPIRES USAGES DESCRIPTION EXTRA GROUPS
eohqh6.sf7f60eq47tazy73 23h 2019-03-11T19:49:15+05:30 authentication,signing The default bootstrap token generated by ‘kubeadm init’. system:bootstrappers:kubeadm:default-node-token
tatn25.lt0s1pgxns3kpapb 23h 2019-03-11T19:40:15+05:30 authentication,signing The default bootstrap token generated by ‘kubeadm init’. system:bootstrappers:kubeadm:default-node-token

Adding WORKER-NODE

[root@node1 ~]# free -m
total used free shared buff/cache available
Mem: 1821 598 574 9 648 1037
Swap: 2047 0 2047

remove swap space

[root@node1 ~]# vim /etc/fstab

[root@node1 ~]# swapoff -a
[root@node1 ~]# mount -a
[root@node1 ~]# yum install kubeadm kubelet docker -y

[root@node1 ~]# systemctl start docker

[root@node1 ~]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.

[root@node1 ~]# kubeadm join 172.16.189.129:6443 –token tatn25.lt0s1pgxns3kpapb –discovery-token-ca-cert-hash sha256:c65b9ed09b8c4e35f7e7faf7d936c12b3e4f5548cb150fd5d0e8c6388ba8bc9f
[preflight] Running pre-flight checks
[WARNING Hostname]: hostname “node1” could not be reached
[WARNING Hostname]: hostname “node1”: lookup node1 on 172.16.189.2:53: no such host
[WARNING Service-Kubelet]: kubelet service is not enabled, please run ‘systemctl enable kubelet.service’
[discovery] Trying to connect to API Server “172.16.189.129:6443”
[discovery] Created cluster-info discovery client, requesting info from “https://172.16.189.129:6443&#8221;
[discovery] Requesting info from “https://172.16.189.129:6443&#8221; again to validate TLS against the pinned public key
[discovery] Cluster info signature and contents are valid and TLS certificate validates against pinned roots, will use API Server “172.16.189.129:6443”
[discovery] Successfully established connection with API Server “172.16.189.129:6443”
[join] Reading configuration from the cluster…
[join] FYI: You can look at this config file with ‘kubectl -n kube-system get cm kubeadm-config -oyaml’
[kubelet] Downloading configuration for the kubelet from the “kubelet-config-1.13” ConfigMap in the kube-system namespace
[kubelet-start] Writing kubelet configuration to file “/var/lib/kubelet/config.yaml”
[kubelet-start] Writing kubelet environment file with flags to file “/var/lib/kubelet/kubeadm-flags.env”
[kubelet-start] Activating the kubelet service
[tlsbootstrap] Waiting for the kubelet to perform the TLS Bootstrap…
[patchnode] Uploading the CRI Socket information “/var/run/dockershim.sock” to the Node API object “node1” as an annotation

This node has joined the cluster:
* Certificate signing request was sent to apiserver and a response was received.
* The Kubelet was informed of the new secure connection details.

Run ‘kubectl get nodes’ on the master to see this node join the cluster.

[root@gcpnode ~]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
gcpnode Ready master 44m v1.13.4
node1 NotReady 11s v1.13.4

[root@gcpnode ~]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
gcpnode Ready master 46m v1.13.4
node1 Ready 2m10s v1.13.4

Deploy a Pod

root@gcpnode ~]# kubectl run nginx –image=nginx –port 80
kubectl run –generator=deployment/apps.v1 is DEPRECATED and will be removed in a future version. Use kubectl run –generator=run-pod/v1 or kubectl create instead.
deployment.apps/nginx created

[root@gcpnode ~]# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
nginx-57867cc648-46r4m 1/1 Running 0 45s 10.44.0.1 node1

[root@gcpnode ~]# kubectl delete pod nginx-57867cc648-46r4m
pod “nginx-57867cc648-46r4m” deleted

[root@gcpnode ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-57867cc648-rq6j9 1/1 Running 0 25s

[root@gcpnode ~]# kubectl get deployment
NAME READY UP-TO-DATE AVAILABLE AGE
nginx 1/1 1 1 7m12s

[root@gcpnode ~]# kubectl expose deployment nginx –type=NodePort –name=expose-nginx
service/expose-nginx exposed

[root@gcpnode ~]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
expose-nginx NodePort 10.111.123.237 80:31332/TCP 16s
kubernetes ClusterIP 10.96.0.1 443/TCP 75m

 

On this node pod is scheduled and exposed on node port  http://172.16.189.130:31332/

nginx

 

 

 

Leave a comment