Showing posts with label Kubernetes. Show all posts
Showing posts with label Kubernetes. Show all posts

Wednesday, May 13, 2020

Kubernetes setup in AWS using KOPS - Mithun Technologies - +91-9980923226

Mithun Technologies            +91-9980923226              devopstrainingblr@gmail.com

                                                       http://mithuntechnologies.com/
                                                       http://mithuntechnologies.co.in/ 
Kubernetes Cluster setup in AWS using KOPS

1) Create Ubuntu EC2 instance

2) Install AWSCLI

 sudo apt update -y
 sudo curl https://s3.amazonaws.com/aws-cli/awscli-bundle.zip -o awscli-bundle.zip
 sudo apt install unzip python -y
 sudo unzip awscli-bundle.zip
 #sudo apt-get install unzip - if you dont have unzip in your system
 sudo ./awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws
 
 
3) Install kops on ubuntu instance:

     #Install wget if not installed
     sudo apt install wget -y
     sudo wget https://github.com/kubernetes/kops/releases/download/v1.16.1/kops-linux-amd64
     sudo chmod +x kops-linux-amd64
     sudo mv kops-linux-amd64 /usr/local/bin/kops
 
4) Install kubectl

 sudo curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl

 sudo chmod +x ./kubectl
 sudo mv ./kubectl /usr/local/bin/kubectl

5) Create an IAM role from Consloe or CLI with below Policies.

    AmazonEC2FullAccess
    AmazonS3FullAccess
    IAMFullAccess
    AmazonVPCFullAccess


Then Attach IAM role to ubuntu server from Console Select KOPS Server --> Actions --> Instance Settings --> Attach/Replace IAM Role --> Select the role which
You Created. --> Save.



6) create an S3 bucket Execute below commond in KOPS Server use unique bucket name if you get bucket name exists error.

    aws s3 mb s3://<bucketname>
   
    ex:
    # S3 bucket name should be unique across AWS
    aws s3 mb s3://balajimtbatch18.k8s.local
    
    Expose environment variable:

    # Add env variables in bashrc
    vi .bashrc
   
    # Give Unique Name And S3 Bucket which you created.
    export NAME=balajimtbatch18.k8s.local
    export KOPS_STATE_STORE=s3://balajimtbatch18.k8s.local
 
    source .bashrc
   
7) Create sshkeys before creating cluster

    ssh-keygen
 

8)Create kubernetes cluster definitions on S3 bucket

    kops create cluster --zones ap-south-1a --networking weave --master-size t2.medium --master-count 1 --node-size t2.micro --node-count=2 ${NAME}
   
   
    kops create secret --name ${NAME} sshpublickey admin -i ~/.ssh/id_rsa.pub

9) Create kubernetes cluser

     kops update cluster ${NAME} --yes

10) Validate your cluster(KOPS will take some time to create cluster ,Execute below commond after 3 or 4 mins)

       kops validate cluster
 
11) To list nodes

      kubectl get nodes
 
 
 
To Delete Cluster

   kops delete cluster --name=${NAME} --state=${KOPS_STATE_STORE} --yes 
  
====================================================================================================


IF you wan to SSH to Kubernates Master or Nodes Created by KOPS. You can SSH From KOPS_Server

ssh  admin@<IPOrDNS>
it above command  is not working
then execute
ssh -i ~/.ssh/id_rsa admin@<IPOrDNS>
 

Monday, November 18, 2019

Kubernetes Setup Using Kubeadm In AWS EC2 Ubuntu Servers - Mithun Technologies - +91-9980923226

Mithun Technologies            +91-9980923226              devopstrainingblr@gmail.com
                                                       http://mithuntechnologies.com/
                                                       http://mithuntechnologies.co.in/ 

Agenda: Kubernetes Setup Using Kubeadm In AWS EC2 Ubuntu Servers
=======================================================


Prerequisite:
==========


3 - Ubuntu Serves

1 - Manager  (4GB RAM , 2 Core) t2.medium

2 - Workers  (1 GB, 1 Core)     t2.micro


Note: Open Required Ports In AWS Security Groups. For now we will open All trafic.

==========COMMON FOR MASTER & SLAVES START ====

# First, login as ‘root’ user because the following set of commands need to be executed with ‘sudo’ permissions.

sudo su -

# Install Required packages and apt keys.

apt-get update -y
apt-get install -y apt-transport-https
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
deb https://apt.kubernetes.io/ kubernetes-xenial main
EOF
apt-get update -y



#Turn Off Swap Space

swapoff -a
sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab

# Install And Enable Docker

apt install docker.io -y
usermod -aG docker ubuntu
systemctl restart docker
systemctl enable docker.service


#Install kubeadm, Kubelet And Kubectl

apt-get install -y kubelet kubeadm kubectl kubernetes-cni

# Enable and start kubelet service

systemctl daemon-reload
systemctl start kubelet
systemctl enable kubelet.service

==========COMMON FOR MASTER & SLAVES END=====



===========In Master Node Start====================
# Steps Only For Kubernetes Master

# Switch to the root user.

sudo su -

# Initialize Kubernates master by executing below commond.

kubeadm init

#exit root user & exeucte as normal user

exit

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


# To verify, if kubectl is working or not, run the following command.

kubectl get pods -o wide --all-namespaces

#You will notice from the previous command, that all the pods are running except one: ‘kube-dns’. For resolving this we will install a # pod network. To install the weave pod network, run the following command:

kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')"

kubectl get nodes

kubectl get pods --all-namespaces


# Get token

kubeadm token create --print-join-command

=========In Master Node End====================


Add Worker Machines to Kubernates Master
=========================================

Copy kubeadm join token from and execute in Worker Nodes to join to cluster



kubectl commonds has to be executed in master machine.

Check Nodes
=============

kubectl get nodes


Deploy Sample Application
==========================

kubectl run nginx-demo --image=nginx --port=80

kubectl expose deployment nginx-demo --port=80 --type=NodePort


Get Node Port details
=====================
kubectl get services

Tuesday, October 22, 2019

Configuration of NFS Server - Mithun Technologies - +91-9980923226

   Mithun Technologies            +91-9980923226              devopstrainingblr@gmail.com
                                                       http://mithuntechnologies.com/
                                                       http://mithuntechnologies.co.in/

                                                          Configuration of NFS Server

Step 1: Install NFS Kernel Server
Before installing the NFS Kernel server, we need to update our system’s repository index with that of the Internet through the following apt command as sudo:

$ sudo apt-get update

The above command lets us install the latest available version of a software through the Ubuntu repositories.

Now, run the following command in order to install the NFS Kernel Server on your system:

$ sudo apt install nfs-kernel-server


Step 2: Create the Export Directory

sudo mkdir -p /mnt/share/

# As we want all clients to access the directory, we will remove restrictive permissions.
sudo chown nobody:nogroup /mnt/share/
sudo chmod 777 /mnt/share/

Step 3: Assign server access to client(s) through NFS export file

sudo vi /etc/exports


#/mnt/share/ <clientIP or Clients CIDR>(rw,sync,no_subtree_check,no_root_squash)
 #Ex:
/mnt/share/ *(rw,sync,no_subtree_check,no_root_squash)


Step 4: Export the shared directory

$ sudo exportfs -a


sudo systemctl restart nfs-kernel-server

Step 5: Open firewall for the client (s) PORT 2049


Configuring the Client Machine


Step 1: Install NFS Common
Before installing the NFS Common application, we need to update our system’s repository index with that of the Internet through the following apt command as sudo:

$ sudo apt-get update


$ sudo apt-get install nfs-common


# Test if we can mount nfs path with client systems folder.

Step 2: Create a mount point for the NFS host’s shared folder

sudo mkdir -p /mnt/sharedfolder_client

Step 3: Mount the shared directory on the client

sudo mount serverIP:/mnt/share/ /mnt/mountfolder_client

Tuesday, July 9, 2019

Jenkins Kubernetes CICD Job - Mithun Technologies - 9980923226



             Mithun Technologies            +91-9980923226              devopstrainingblr@gmail.com
                                                       http://mithuntechnologies.com/
                                                       http://mithuntechnologies.co.in/ 


Ansible Installation in Amazon Linux - Mithun Technologies - 9980923226

  Mithun Technologies            +91-9980923226              devopstrainingblr@gmail.com                                                 ...