You are on page 1of 6

1.

kubectl get nodes


2. kubectl config user-context "minikube"
3. kubectl get cs
4. kubectl get pods

deploying the applciations

5. kubectl run my-web --image-nginx --port=80

kubectl get deployments ==> shows the deployments


kubectl get pods ==> random names

kubectl expose deployment my-web --target-port=80 --type=NodePort

OR

kubectl expose deployment webserver --type=Loadbalancer --port=80

kubectl get services

To know the URL of the web server


minikube service webserver --url

mikube

kubectl get svs

PORT=$(kubectl get svc my-web -o go-template={{(index .spec.ports 0).nodePort}}')

echo port

minikube ip

mikube dashboard
minikube ip

================================

To initialize the master node:


=====================================

To initialize the cluster on the master node:


kubeadm init --apiserver-advertise-address=<Ip address of the host>
--pod-network-cidr=192.168.0.0/16

While excuting the above command , if any error we need to reset the cluster again.

kubeadm reset
minkube
kubectl

=============================
kubernet installations:
=================================

- Install Docker CE
=====================
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
http://mirror.centos.org/centos/7/extras/x86_64/Packages/container-selinux-2.68-1.el7.noarch.rp
m

yum install -y docker-ce

======================
- Install Kubernetes

The following things create the repository:


------------------------------------------

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
------------------------------------------------
- install the kebernetes:
--------------------------------------------

yum install -y kubelet kubeadm kubectl

reboot the server. Once the server is on start the sevices. reboot or init 6

systemctl start docker && systemctl enable docker


systemctl start kubelet && systemctl enable kubelet

systemctl start docker && systemctl enable docker


systemctl start kubelet && systemctl enable kubelet

- Change the cgroup-driver


=======================

[root@ip-172-31-18-189 ~]# docker info | grep -i cgroup


Cgroup Driver: cgroupfs
[root@ip-172-31-18-189 ~]#

docker is using the cgroupfs same thing need to be updated in the kubernetes as well.

sed -i 's/cgroup-driver=systemd/cgroup-driver=cgroupfs/g'
/etc/systemd/system/kubelet.service.d/10-kubeadm.conf

==> With this kubernetes is installed. Cluster initialization starts from here:

kubeadm init --apiserver-advertise-address=172.31.24.132 --pod-network-cidr=172.31.16.0/20


--ignore the error and execute below command

on master sever

kubeadm init --apiserver-advertise-address=172.31.24.132 --pod-network-cidr=172.31.16.0/20


--ignore-preflight-errors=NumCPU

Note: minimum 2 cpus required otherwise the above command does not work.

To skip the error user this option : --ignore-preflight-errors=NumCPU

kubeadm init --apiserver-advertise-address=172.31.13.85 --pod-network-cidr=172.31.16.0/20


--ignore-preflight-errors=NumCPU
Copy the admin.conf to the local directory: copy paste in master server
================================

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

then copy paste 2 token key in clent and check connection

Network confgirations: ---check snapshot in phone for more details


============================

kubectl apply -f
https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

wget https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
---- to download this file

vi kube-flannel.yml and
go to /10 network change the subnet id
wait for sometime and check the nodes and pods:
=============================================

kubectl get nodes ----- to check connected nodes


kubectl get pods --all-namespaces

The above command list the cluster node status ( ready ) and the cluster pod informations.

to deploy the image in master

kubectl run my-web --image=nginx --port=80


--imagename--

Add the nodes in the cluster:


-------------------------------

copy paste the commands from the kubeadm command output( when initializing the commands
will give to add the nodes to the cluster).

Once adding the nodes we can check the status again:


kubectl get nodes
kubectl get pods --all-namespaces

Displays the 2 nodes and the pod details:

==> Create a pod.

(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.)

Run the below command on the kubernetes

==> kubectl create deployment nginx --image=nginx

To see the details of the nginix deployment.

==> kubectl describe deployment nginx

Create application server:

kubectl create service nodeport nginx --tcp=80:80

==> Verify the port and IP:

kubectl get pods


kubectl get svc

This gives the port and IP of the ngnix service.

Cluster IP of the nignix: 80:<node port>

we can access the from the cluster master:

curl node1:<node port>


curl node2:<node port>

The above commands give the output.

we can access fromt he browser as well:


===================================

https://IPaddressed:<port>

You might also like