Saturday, 29 January 2022

KUBERNETES - How to enable autocompletion Kubernetes commands

In order to perform autocompletion of Kubernetes commands




  • First check the shell - echo $SHELL




  • Install the package:-  apt-get install bash-completion 

Now try typing the command kubectl and press tab, it will auto-complete.


Recommended Books:-


Mastering Kubernetes: Level up your container orchestration skills with Kubernetes to build, run, secure, and observe large-scale distributed apps, 3rd Edition Paperback







 

KUBERNETES - The kubernetes nodes were reporting in not ready state after restart of ubuntu worker nodes

Kubernetes - The kubernetes nodes were reporting in not ready state after restart of ubuntu worker nodes.


Today after restarting the worker nodes (ubuntu2 and ubuntu3) they were showing in not-ready state.




In order to solve the issue I ran the command:- sudo  swapoff -a on the worker node - ubuntu2



After running the command, I checked the status of the nodes on the master node - ubuntu1



Please note that the  node - ubuntu2 shows in ready state where as node - ubuntu3 is in not ready state.

Now I will run the command - sudo swapoff -a command on the worder node to disable the swap on it.



Now if we check the status of the nodes from the master node:- ubuntu1, both the nodes are in ready state.


KUBERNETES - The connection to the server 192.168.181.11:6443 was refused - did you specify the right host or port?

Today when I started by Kubernetes setup (ubuntu1-master node) and ran the command kubectl get nodes I received the below error:-


Error:- The connection to the server 192.168.181.11:6443 was refused - did you specify the right host or port?




In order to solve the issue I ran the below commands on the master node:-

Sunday, 16 January 2022

ANSIBLE - HOW TO DELETE FOLDER FROM REMOTE SERVERS

How to delete folder from Remote Servers

I have created 3 Ubuntu servers with the names:-

Server1 - Installed Ansible

Server2 - Client Node1

Server3- Client Node2

Note:- I installed ansible on Server1.

I have created a file :- vi remove-dir.yml

This will delete the folder /oracle from the app group [Server2 and Server3]


Recommended Books:-

Implementing DevOps with Ansible 2 Paperback

Automation with Ansible Paperback

Ansible for DevOps: Server and configuration management for humans

Ansible: From Beginner to Pro Paperback

Ansible: Up and Running- Automating Configuration Management and Deployment the Easy Way Paperback


ANSIBLE - HOW TO GET THE DISK DETAILS FROM REMOTE SERVERS

 How to get the disk details from Remote Servers

I have created 3 Ubuntu servers with the names:-

Server1 - Installed Ansible

Server2 - Client Node1

Server3- Client Node2

Note:- I installed ansible on Server1.

I have created a file :- vi disk-details.yml

This will gather the disk details from the app group [Server2 and Server3]


Print the disk space details from the servers



ANSIBLE - HOW TO CREATE A FOLDER AND CREATE A FILE NAMED WELCOME USING ANSIBLE FILE/COPY MODULE

How to create a folder using Ansible File Module and create a file named welcome

I have created 3 Ubuntu servers with the names:-

Server1 - Installed Ansible

Server2 - Client Node1

Server3- Client Node2

Note:- I installed ansible on Server1.

I have created a file :- vi create-file.yml

This will create the directory oracle on the / partition and welcome file under it 

for app group [Server2 and Server3]




Now we will run the playbook with the command:- ansible-playbook create-file.yml



The above task has been completed successfully. We can validate the folder and file creation.
 
Server2




Server3



ANSIBLE - HOW TO RUN THE ANSIBLE PLAYBOOK IN SIMULATION MODE

How to run the ansible playbook in Simulation Mode.

In order to run the playbook in simulation mode, we can run the command - ansible-playbook  -C [Name of the playbook].

In my example, I am running it for the playbook - create-dir-oracle.yml


Recommended Books:-

Implementing DevOps with Ansible 2 Paperback

Automation with Ansible Paperback

Ansible for DevOps: Server and configuration management for humans

Ansible: From Beginner to Pro Paperback

Ansible: Up and Running- Automating Configuration Management and Deployment the Easy Way Paperback

ANSIBLE - HOW TO CHECK THE SYNTAX/ERRORS IN ANSIBLE PLAYBOOK

 How to check the syntax/errors in Ansible Playbook

In order to check the syntax for the playbook, we can run the command - ansible-playbook  --syntax-check [Name of the playbook].

In my example, I am checking the errors for the playbook - create-dir-oracle.yml.



After executing the check, no errors were found in the playbook.

ANSIBLE - HOW TO CREATE A FOLDER USING FILE MODULE

 How to create a folder using File Module

I have created 3 Ubuntu servers with the names:-

Server1 - Installed Ansible

Server2 - Client Node1

Server3- Client Node2

Note:- I installed ansible on Server1.

I have created a file :- vi create-dir-oracle.yml


This will create the directory oracle on the / partition


Now we will run the playbook with the command:- ansible-playbook create-dir-oracle.yml



The above task has been completed successfully.

We can validate the folder creation by checking the / partition of server2 and server3.

Server2


Server3




Note:- To check the syntax - ansible-playbook  --syntax-check create-dir-oracle.yml


      
We can also run the ansible-playbook in an simulation mode - ansible-playbook  -C  [Name of the playbook]. This will not execute the desired task mentioned in the playbook.



ANSIBLE - HOW TO SETUP ANSIBLE ENVIRONMENT

 Ansible - How to setup Ansible Environment

In my example, I will should you how to setup your ansible environment and run the ping module.

1) I have created 3 Ubuntu servers with the names:-

Server1 - Installed Ansible

Server2 - Client Node1

Server3- Client Node2

Note:- I installed ansible on Server1 by running the below commands on ubuntu:-

sudo apt-add-repository ppa:ansible/ansible

sudo apt update

sudo apt install ansible

Once ansible is installed on the server1, we can check it by running the command:- ansible --version


2) Then I generated ssh-keys on the server1 by running the command:= ssh-keygen -t rsa


3) Then I copied the keygen to all servers by running the command:- ssh-copy-id <IP Address>
For Example:-

ssh-copy-id 192.168.181.11
ssh-copy-id 192.168.181.12
ssh-copy-id 192.168.181.13

Server1


Server2



Server3


This is to make sure, we can run the ansible playbooks from the ansible server. I will be using root user to execute the playbooks.

4) Then I created a folder scripts which will be used for keeping all my playbooks, inventory files etc.



5) Then I created my inventory file in the same folder as inv


I defined hosts in my inv file with 2 groups:- all and app

The all group is having all the 3 hosts - server1, server2 and server3 and the app group is having 2 hosts:- server2 and server3 as shown below


6) I also created a file ansible.cfg in the same folder - scripts and defined the name of my inventory file.
In my example, it is inv




7) Now we can check the connectivity between the servers with the help of ping module.
Command:- ansible -m ping [Name of the group defined in inventory file - inv)
In my example, I am running it on app group 


Now I am running the ping module for the all group defined in the inv file.


The above screenshots refers successfully connectivity between all the servers from the ansible server -server1.

LINUX - HOW TO VIEW THE LAST FILE ENTRIES USING THE TAIL COMMAND

How to view the last file entries using the last command

In linux we can view the top file entries using the command: head

For example:-

1) Command:- tail /test1/file1 - This will show the top 10 lines of the file




2) Command:- tail -1 /test1/file1 - This will show the last line of the file





3) Command:- tail -3 /test1/file1 - This will show the last 3 lines of the file


Recommended Books:-

LINUX - HOW TO VIEW THE FILE ENTRIES USING THE HEAD COMMAND

 How to view the top file entries using the head command

In linux we can view the top file entries using the command: head

For example:-

1) Command:- head /test1/file1 - This will show the top 10 lines of the file


2) Command:- head -1 /test1/file1 - This will show the top 1 line of the file



3) Command:- head -3 /test1/file1 - This will show the top 3 lines of the file



Recommended Books:-




LINUX - HOW TO CHANGE IP ADDRESS IN UBUNTU

 How to change IP address in ubuntu.

In order to change IP address in ubuntu, we can use the command:- nmtui



Now edit the connection:-


And choose the interface for which the IP address is required to be changed



In my example, the IP address is allocated as 192.168.181.14. 



I will change the IP address to 192.168.181.11 and click OK and choose back.


Now choose Exit option



 You would come back to the original prompt as shown below:-