Tag Archives: DevOps Tools

Mastering kubectl create namespace

Introduction

In the expansive world of Kubernetes, managing multiple applications systematically within the same cluster is made possible with namespaces. This article explores how to efficiently use the kubectl create namespace command and other related functionalities to enhance your Kubernetes management skills.

What is a Namespace?

A namespace in Kubernetes serves as a virtual cluster within a physical cluster. It helps in organizing resources where multiple teams or projects share the cluster, and it limits access and resource consumption per namespace.

Best Practices for Using kubectl create namespace

Adding Labels to Existing Namespaces

Labels are key-value pairs associated with Kubernetes objects, which aid in organizing and selecting subsets of objects. To add a label to an existing namespace, use the command:

kubectl label namespaces <namespace-name> <label-key>=<label-value>

This modification helps in managing attributes or categorizing namespaces based on environments, ownership, or any other criteria.

Simulating Namespace Creation

Simulating the creation of a namespace can be useful for testing scripts or understanding the impact of namespace creation without making actual changes. This can be done by appending --dry-run=client to your standard creation command, allowing you to verify the command syntax without executing it:

kubectl create namespace example --dry-run=client -o yaml

Creating a Namespace Using a YAML File

For more complex configurations, namespaces can be created using a YAML file. Here’s a basic template:

apiVersion: v1
kind: Namespace
metadata:
name: mynamespace

Save this to a file (e.g., mynamespace.yaml) and apply it with:

kubectl apply -f mynamespace.yaml

Creating Multiple Namespaces at Once

To create multiple namespaces simultaneously, you can include multiple namespace definitions in a single YAML file, separated by ---:

apiVersion: v1
kind: Namespace
metadata:
name: dev
---
apiVersion: v1
kind: Namespace
metadata:
name: prod

Then apply the file using the same kubectl apply -f command.

Creating a Namespace Using a JSON File

Similarly, namespaces can be created using JSON format. Here’s how a simple namespace JSON looks:

{
"apiVersion": "v1",
"kind": "Namespace",
"metadata": {
"name": "jsonnamespace"
}
}

This can be saved to a file and applied using:

kubectl apply -f jsonnamespace.json

Best Practices When Choosing a Namespace

Selecting a name for your namespace involves more than just a naming convention. Consider the purpose of the namespace, and align the name with its intended use (e.g., test, development, production), and avoid using reserved Kubernetes names or overly generic terms that could cause confusion.

Conclusion

Namespaces are a fundamental part of Kubernetes management, providing essential isolation, security, and scalability. By mastering the kubectl create namespace command and related functionalities, you can enhance the organization and efficiency of your cluster. Whether you’re managing a few services or orchestrating large-scale applications, namespaces are invaluable tools in your Kubernetes toolkit. I hope will this your helpful. Thank you for reading the DevopsRoles page!

How to Install CNI for Kubernetes: A Comprehensive Guide

Introduction

In this tutorial, How to Install CNI for Kubernetes. Container orchestration has become an indispensable part of modern IT infrastructure management, and Kubernetes stands out as a leading platform in this domain. One of the key components that contribute to Kubernetes’ flexibility and scalability is the Container Networking Interface (CNI). In this comprehensive guide, we’ll delve into the intricacies of installing CNI for Kubernetes, ensuring smooth communication between pods and services within your cluster.

What is CNI and Why is it Important?

Before we delve into the installation process, let’s understand the significance of the Container Networking Interface (CNI) in the Kubernetes ecosystem. CNI serves as a standard interface for configuring networking in Linux containers. It facilitates seamless communication between pods, enabling them to communicate with each other and external resources. By abstracting network configuration, CNI simplifies the deployment and management of containerized applications within Kubernetes clusters.

Preparing for Installation

Before embarking on the installation journey, it’s essential to ensure that you have the necessary prerequisites in place. Firstly, you’ll need access to your Kubernetes cluster, along with appropriate permissions to install CNI plugins. Additionally, familiarity with basic Kubernetes concepts and command-line tools such as kubectl will prove beneficial during the installation process.

Step-by-Step How to Install CNI for Kubernetes

Example: Installing Calico CNI Plugin

Install kubectl: If you haven’t already installed kubectl, you can do so by following the official Kubernetes documentation for your operating system. For example, on a Linux system, you can use the following command:

curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl

Once installed, verify the installation by running:

kubectl version --client

Choose Calico as the CNI Plugin: Calico is a popular CNI plugin known for its simplicity and scalability. To install Calico, you can choose from various deployment methods, including YAML manifests or Helm charts. For this example, we’ll use YAML manifests.

Download the Calico Manifests: Calico provides YAML manifests for easy deployment. Download the manifests using the following command:

curl https://docs.projectcalico.org/manifests/calico.yaml -O

Configure Calico: Before applying the Calico manifests to your Kubernetes cluster, you may need to configure certain parameters, such as the IP pool for pod IPs. Open the calico.yaml file in a text editor and modify the configuration as needed.

vi calico.yaml

Here’s an example configuration snippet specifying an IP pool:

- name: CALICO_IPV4POOL_CIDR
  value: "192.168.0.0/16"

Apply Calico Manifests to Kubernetes: Once you’ve configured Calico according to your requirements, apply the manifests to your Kubernetes cluster using kubectl:

kubectl apply -f calico.yaml

This command will create the necessary Kubernetes resources, including Custom Resource Definitions (CRDs), Pods, Services, and ConfigMaps, to deploy Calico within your cluster.

Verify Installation: After applying the Calico manifests, verify the successful installation by checking the status of Calico pods and related resources:

kubectl get pods -n kube-system

Conclusion

Installing Container Network Interface (CNI) plugins for Kubernetes is a critical step towards enabling seamless communication between containers within a Kubernetes cluster. This process, while it might seem intricate at first, can significantly streamline and secure network operations, providing the flexibility to choose from a wide array of CNI plugins that best fit the specific requirements of your environment. By following the best practices and steps outlined for the installation process, users can ensure that their Kubernetes cluster is equipped with a robust and efficient networking solution.

This not only enhances the performance of applications running on the cluster but also leverages Kubernetes’ capabilities to the fullest, ensuring a scalable, manageable, and highly available system. Whether you’re deploying on-premise or in the cloud, understanding and implementing CNI effectively can profoundly impact your Kubernetes ecosystem’s efficiency and reliability. . Thank you for reading the DevopsRoles page!

How to Simplify Your Linux and Docker Commands with Bash Completion

Introduction

Bash Completion: Are you spending too much time typing out lengthy Linux commands or struggling to remember Docker command options? Boost your terminal productivity with Bash Completion! This powerful tool helps automate your workflow by filling in partially typed commands and arguments with a simple tap of the tab key. Let’s dive into how you can set up and leverage for a more efficient command line experience.

Installing Bash Completion

First, ensure Bash Completion is installed on your system.

For Debian/Ubuntu users, execute

sudo apt-get install bash-completion

CentOS/RHEL folks can type

sudo yum install bash-completion

and Fedora users are likely all set but can ensure installation with

sudo dnf install bash-completion

After installation, restart your terminal to enable the feature.

Enabling Bash Completion

In most cases, it will activate automatically. If not, add source /etc/bash_completion to your .bashrc or .bash_profile file to kick things off. This ensures that every time you open your terminal, It is ready to assist you.

How to Use it

Simply start typing a command or file name and press the Tab key. If there’s only one completion, Bash fills it in for you. If there are several options, a second Tab press will display them. This function works with file names, command options, and more, streamlining your terminal navigation.

Docker Command Completion

Docker users, rejoice! Bash Completion extends to Docker commands, too. Installation may vary, but generally, you can place the Docker completion script /etc/bash_completion.d/ or /usr/share/bash-completion/completions/. Source the script or restart your terminal to apply. Now, managing Docker containers and images is faster than ever.

Customizing Bash Completion

Feeling adventurous? Create your own Bash completion scripts for commands that lack them. By examining existing scripts in /etc/bash_completion.d/ or /usr/share/bash-completion/completions/, you can learn how they’re constructed and customize your own for any command.

Conclusion

By integrating Bash Completion into your workflow, you’ll not only save time but also enhance your terminal’s functionality. It’s an essential tool for anyone looking to streamline their command line experience. So, give it a try, and watch your productivity soar! I hope will this your helpful. Thank you for reading the DevopsRoles page!

For Example

Here’s a simple example to illustrate the power: Suppose you’re using Docker and want to check the logs of a container.

Instead of typing docker container logs [container_id], simply type docker con and press Tab twice to see all possible commands starting with “con“. Continue with logs and another Tab to list your containers. Pick the right one, and you’re done in a fraction of the time!

Vagrant No VirtualBox Guest Additions installation found [Fixed]

Introduction

In this tutorial, How to fix the error Vagrant No VirtualBox Guest Additions installation is found. I use a laptop and run the command vagrant up for the NFS server then the error “umount: /mnt: not mounted

ERROR umount: /mnt: not mounted

E:\Vagrant_VMS\NFS_server>vagrant up 

Error: Nothing to do
Unmounting Virtualbox Guest Additions ISO from: /mnt
umount: /mnt: not mounted
==> servernfs: Checking for guest additions in VM...
    servernfs: No guest additions were detected on the base box for this VM! Guest
    servernfs: additions are required for forwarded ports, shared folders, host only
    servernfs: networking, and more. If SSH fails on this machine, please install
    servernfs: the guest additions and repackage the box to continue.
    servernfs:
    servernfs: This is not an error message; everything may continue to work properly,
    servernfs: in which case you may ignore this message.
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!

umount /mnt

Stdout from the command:



Stderr from the command:

umount: /mnt: not mounted

Vagrant No VirtualBox Guest Additions installation found fixed

I have uninstalled vagrant-vbguest and installed vagrant-vbguest.

vagrant plugin uninstall vagrant-vbguest
vagrant plugin install vagrant-vbguest --plugin-version 0.21

The output uninstall and install vagrant-vbguest as below

E:\Vagrant_VMS\NFS_server>vagrant plugin uninstall vagrant-vbguest
Uninstalling the 'vagrant-vbguest' plugin...
Successfully uninstalled micromachine-3.0.0
Successfully uninstalled vagrant-vbguest-0.27.0

E:\Vagrant_VMS\NFS_server>vagrant plugin install vagrant-vbguest --plugin-version 0.21
Installing the 'vagrant-vbguest --version '0.21'' plugin. This can take a few minutes...
Fetching micromachine-3.0.0.gem
Fetching vagrant-vbguest-0.21.0.gem
Installed the plugin 'vagrant-vbguest (0.21.0)'!

As a result, I have to fix it!

E:\Vagrant_VMS\NFS_server>vagrant reload
==> servernfs: Attempting graceful shutdown of VM...
==> servernfs: Checking if box 'centos/7' version '2004.01' is up to date...
==> servernfs: Clearing any previously set forwarded ports...
==> servernfs: Clearing any previously set network interfaces...
==> servernfs: Preparing network interfaces based on configuration...
    servernfs: Adapter 1: nat
    servernfs: Adapter 2: hostonly
==> servernfs: Forwarding ports...
    servernfs: 22 (guest) => 2222 (host) (adapter 1)
==> servernfs: Booting VM...
==> servernfs: Waiting for machine to boot. This may take a few minutes...
    servernfs: SSH address: 127.0.0.1:2222
    servernfs: SSH username: vagrant
    servernfs: SSH auth method: private key
    servernfs: Warning: Connection aborted. Retrying...
==> servernfs: Machine booted and ready!
[servernfs] GuestAdditions 6.1.14 running --- OK.
==> servernfs: Checking for guest additions in VM...
==> servernfs: Configuring and enabling network interfaces...
==> servernfs: Rsyncing folder: /cygdrive/e/MyData/Vagrant_VMS/NFS_server/ => /vagrant
==> servernfs: Rsyncing folder: /cygdrive/e/MyData/Vagrant_VMS/NFS_server/NFS_Volumn/ => /home/vagrant/nfs_test
==> servernfs: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> servernfs: flag to force provisioning. Provisioners marked to run always will still run.

Youtube Vagrant No VirtualBox Guest Additions installation found [Fixed]

Conclusion

You have fixed Vagrant No VirtualBox. I hope will this your helpful. Thank you for reading the DevopsRoles page!

Linux command tips and tricks

Introduction

In this tutorial, I system admin. Linux the essential for DevOps Roles.

Begin with an engaging introduction that explains the importance of mastering Linux commands for DevOps professionals. Highlight how these commands enhance productivity and streamline operations in a Linux environment.

Linux command tips and tricks

How to return to the previous directory

$ cd -

The display headers and footers in FileName.

$ cat filename | sed -e '$d' | awk 'NR > 1 {print}'

Search files under arbitrary directories

$ find ./ -name '*'|xargs grep 'devopsroles.com'

Empty the file.

$ cat /dev/null > filename.txt

Move to thereafter create the folder

$ mkdir dir_name ; cd $_

To count the number of files in any directory.

$ ls -F |grep -v / |wc -l

or count the number of folders in any directory.

$ ls -F |wc -l

Convert all extensions

$ for filename in *.txt; do mv $filename ${filename%.txt}.txt.old; done

To create serial number files.

$ touch foo_{1..4}.csv
$ touch {A..X}.csv

Delete “.DS_store” in bash

$ find . -name '.DS_Store' -type f -ls -delete

How to delete the last slash of the path.

$ MYDIR=${MYDIR%/}

Extract processes that use a lot of physical memory

$ ps aux | sort -n -k 6 | tail -n 10

Find processes with high CPU utilization

$ vmstat 1 | awk '{print strftime("%y/%m/%d %H:%M:%S"), $0}

lsof command list of ports in Listen

$ lsof -Pan -i tcp -i udp

Generate random passwords using the head command and tr command.

$ head /dev/urandom | tr -dc A-Za-z0-9 | head -c 13 ; echo ''

Extract a character string

$ echo 'devopsroles.com' | awk '{print substr($0, 2)}'

the mount command the display formatting with column

$ mount | column -t

To See CPU utilization per user

$ ps aux | awk  '{if (NR> 1) {p [$1] +=$3; n [$ 1] ++}} END {for (i in p) print p [i], n [i], i }'

How much RAM is installed on this system?

[huupv@huupv devopsroles]$ sudo dmidecode -t 17 | grep "Size.*MB" | awk '{s+=$2} END {print s / 1024 "GB"}'

Awk command line

Character count (wc – c)

$ awk '{n+=length($0)} END{print n}' filename

Word count (wc – w)

$ awk '{n+=NF} END{print n}' filename

Row count (wc – l)

$ awk 'END{print NR}' filename

Display from specified line to specified line

$ awk 'NR==3,NR==10'

Kill bulk by process name

$ kill $(ps aux | grep  "jenkins" | awk '{print $2;}')

Conclusion

Throughout this article, we’ve explored various Linux command tips and tricks. I hope you find these insights useful for your tasks. Thanks for visiting the DevopsRoles page.