0% found this document useful (0 votes)
35 views

Instruction Kubernetes

1) The document describes the steps to install Kubernetes on a master node and a worker node. It includes installing Docker, initializing the Kubernetes master, joining a worker node to the cluster, and deploying a pod network. 2) Commands are provided to create a sample pod, check system pods, describe nodes, and work with namespaces in Kubernetes. Creating pods, editing pods, and getting pods by namespace are demonstrated. 3) Useful links are included for changing SELinux modes and installing Kubernetes on CentOS 7.

Uploaded by

Kishore K
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views

Instruction Kubernetes

1) The document describes the steps to install Kubernetes on a master node and a worker node. It includes installing Docker, initializing the Kubernetes master, joining a worker node to the cluster, and deploying a pod network. 2) Commands are provided to create a sample pod, check system pods, describe nodes, and work with namespaces in Kubernetes. Creating pods, editing pods, and getting pods by namespace are demonstrated. 3) Useful links are included for changing SELinux modes and installing Kubernetes on CentOS 7.

Uploaded by

Kishore K
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Kubernetes

Step 1: Install docker first with following command:


root@KubeMaster:~# apt-get install -y docker-ce
Step 2:Login to master machine and execute below commands:
root@KubeMaster:~# curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key
add -
OK
root@KubeMaster:~# touch /etc/apt/sources.list.d/kubernetes.list
root@KubeMaster:~# echo "deb http://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee
-a /etc/apt/sources.list.d/kubernetes.list
sudo: unable to resolve host KubeMaster
deb http://apt.kubernetes.io/ kubernetes-xenial main
root@KubeMaster:~# echo "deb http://apt.kubernetes.io/ kubernetes-xenial main" | tee -a
/etc/apt/sources.list.d/kubernetes.list
deb http://apt.kubernetes.io/ kubernetes-xenial main
root@KubeMaster:~# chmod +x /etc/apt/sources.list.d/kubernetes.list
root@KubeMaster:~# apt-get update
root@KubeMaster:~# apt-get install -y kubectl kubeadm kubelet
Step 3: To hold the automatic updates
root@KubeMaster:~# apt-mark hold docker-ce kubectl kubeadm kubelet
Step 4: To check the network
root@KubeMaster:~# echo "net.bridge-nf-call-iptables=1" | tee -a /etc/sysctl-conf
Step 5:Initialize the kube master with following command
root@KubeMaster:~# kubeadm init --pod-network-cidr=192.168.0.0/16
Step 6: Copy the text for further use
Your Kubernetes control-plane 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/

Then you can join any number of worker nodes by running the following on each as
root:

kubeadm join 172.31.80.149:6443 --token 67s7ld.e4fvnrk4kn6pfslr \


--discovery-token-ca-cert-hash sha256:5330f8fd0e7416c4f0fe68b97499cb42464d99
49a9956c68c8ffea3d2583fecd
Step 7: Run below commands
# mkdir -p $HOME/.kube
# sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
# sudo chown $(id -u):$(id -g) $HOME/.kube/config
# kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/
kube-flannel.yml.
#vim /usr/lib/systemd/system/kubelet.service.d/10-kubeadm.conf
Append in file below
Environment="cgroup-driver=systemd/cgroup-driver=cgroupfs
#systemctl daemon-reload
#systemctl restart kubelet
step 8: install kubernetes on node or worker node(centos 7)
[root@Node_1 ~]# sed -i --follow-symlinks 's/SELINUX=enforcing/SELINUX=disabled/g'
/etc/sysconfig/selinux
[root@Node_1 ~]# setenforce 0
[root@Node_1 ~]# modprobe br_netfilter
[root@Node_1 ~]# echo '1' > /proc/sys/net/bridge/bridge-nf-call-iptables
[root@Node_1 ~]# vi /etc/yum.repos.d/kubernetes.repo
Insert below.

[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

[root@Node_1 ~]# yum install kubeadm kubelet kubectl -y


[root@Node_1 centos]# systemctl enable kubelet
Created symlink from /etc/systemd/system/multi-user.target.wants/kubelet.service to
/usr/lib/systemd/system/kubelet.service.
[root@Node_1 centos]# systemctl start kubelet
Step 9: Note: don’t put “_” in the hostname
Step 10: [root@Node1 ~]# cat > /etc/docker/daemon.json <<EOF
{
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m"
},
"storage-driver": "overlay2",
"storage-opts": [
"overlay2.override_kernel_check=true"
]
}
EOF

Step 11: [root@Node1 ~]# mkdir -p /etc/systemd/system/docker.service.d


[root@Node1 ~]# systemctl daemon-reload
[root@Node1 ~]# systemctl restart docker

Useful links:
https://www.linode.com/docs/quick-answers/linux/how-to-change-selinux-modes/

https://www.linuxtechi.com/install-kubernetes-1-7-centos7-rhel7/

Kubernetes API Primitives


root@KubeMaster:~# kubectl api-resources -o name

To check the system pods run the below commands:


root@KubeMaster:~# kubectl get pods -n kube-system
root@KubeMaster:~# kubectl get node node1.ec2.internal -o yml
root@KubeMaster:~# kubectl describe node node1.ec2.internal

Creating POD
Create the yaml file for pod as
root@KubeMaster:~/kuberentespract# vi my-pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: my-pod
labels:
app: myapp
spec:
containers:
- name: myapp-conatiner
image: busybox
command: ['sh','-c', 'echo hello kubernetes! && sleep 3600']
root@KubeMaster:~/kuberentespract# kubectl create -f my-pod.yml
pod/my-pod created
root@KubeMaster:~/kuberentespract#
root@KubeMaster:~/kuberentespract# kubectl get pod
NAME READY STATUS RESTARTS AGE
my-pod 1/1 Running 0 96s
root@KubeMaster:~/kuberentespract#
To edit the pod use below commands
root@KubeMaster:~/kuberentespract# vi my-pod.yml
root@KubeMaster:~/kuberentespract# kubectl apply -f my-pod.yml
root@KubeMaster:~/kuberentespract# kubectl edit pod my-pod

Namespaces
root@KubeMaster:~/kuberentespract# vi my-pod-ns.yml
root@KubeMaster:~/kuberentespract# kubectl create -f my-pod-ns.yml

root@KubeMaster:~/kuberentespract# kubectl get pod -n my-ns


NAME READY STATUS RESTARTS AGE
my-pod 1/1 Running 0 18m
my-pod-ns 1/1 Running 0 7m29s
root@KubeMaster:~/kuberentespract#
root@KubeMaster:~/kuberentespract# kubectl describe pod my-pod-ns -n my-ns

You might also like