Pages

Monday, April 10, 2023

Kubernetes(k8s) Sample Commands - 02

Following are a few of the  kubectl commands for managing Kubernetes clusters:

  • kubectl get nodes -o=jsonpath='{XX}'
    • This command retrieves information about the nodes in the cluster using the jsonpath output format. Replace {XX} with the desired path.
  • kubectl get nodes -o=custom-columns=<Column name>
    • This command retrieves information about the nodes in the cluster using custom columns output format. Replace <Column name> with the desired column name
  • --sort-by=
    • This option is used to sort the output based on a specified field.
  • kubectl get node node01 -o json > /opt/outputs/node01.json
    • This command retrieves information about a specific node and saves it as a JSON file.
  • kubectl get nodes -o jsonpath='{.items[*].status.nodeInfo.osImage}' > /opt/outputs/nodes_os.txt
    • This command retrieves the OS image of all the nodes in the cluster and saves it in a text file.
  • kubectl config view --kubeconfig=my-kube-config -o jsonpath="{.users[*].name}" > /opt/outputs/users.txt
    • This command retrieves the names of all users in the kubeconfig file and saves it in a text file.
  • kubectl get pv --sort-by=.spec.capacity.storage > /opt/outputs/storage-capacity-sorted.txt
    • This command retrieves the capacity of all persistent volumes and sorts the output by storage capacity.
  • kubectl config view --kubeconfig=my-kube-config -o jsonpath="{.contexts[?(@.context.user=='aws-user')].name}" > /opt/outputs/aws-context-name
    • This command retrieves the context name for a specific user in the kubeconfig file.
  • kubectl run test-nslookup --image=busybox:1.28 --rm -it --restart=Never -- nslookup nginx-resolver-service
    • This command creates a pod named test-nslookup and runs a DNS lookup on nginx-resolver-service.
  • kubectl run test-nslookup --image=busybox:1.28 --rm -it --restart=Never -- nslookup nginx-resolver-service > /root/CKA/nginx.svc
    • This command creates a pod named test-nslookup and redirects the output of the DNS lookup to a file.
  • K get nodes -o jason | jq -c paths |grep type
    • This command retrieves the paths of all fields in the node objects in the cluster that contain the word "type".
  • kubectl create deployment --image=nginx nginx --replicas=4 --dry-run=client -o yaml > nginx-deployment.yaml
    • This command creates a deployment named nginx with 4 replicas and saves the deployment manifest as a YAML file. The --dry-run=client flag is used to simulate the deployment without actually creating it.

Monday, November 7, 2022

Updated Metallb 0.13.7 Configuration for K8s 1.25

In the new Metallb 0.13.7 configuration for Kubernetes 1.25, there is a new step that needs to be taken before configuring the address pool. You need to enable the ARP (Address Resolution Protocol) to ensure that the load balancer can correctly route traffic between pods.

To enable the ARP, you need to run the following command:

kubectl get configmap kube-proxy -n kube-system -o yaml | \
sed -e "s/strictARP: false/strictARP: true/" | \
kubectl apply -f - -n kube-system

This command fetches the kube-proxy configuration map, updates the "strictARP" option from "false" to "true" and applies the updated map to the kube-system namespace.

Once ARP is enabled, you can apply the new Metallb configuration file by running the following command:

kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.13.7/config/manifests/metallb-native.yaml
This command fetches the Metallb configuration file and applies it to your cluster.

Next, you need to create an IP address pool that Metallb can use to assign IP addresses to services. To do this, you can create a YAML file with the following contents:

apiVersion: metallb.io/v1beta1
kind: IPAddressPool
metadata:
  name: first-pool
  namespace: metallb-system
spec:
  addresses:
  - 172.16.2.80-172.16.2.90
This YAML file creates an IP address pool named "first-pool" in the "metallb-system" namespace. The pool has a range of IP addresses between 172.16.2.80 and 172.16.2.90 that Metallb can use to assign to services.

You can apply this YAML file to your cluster using the following command:

kubectl apply -f <filename>.yaml


With these steps, you have successfully configured Metallb 0.13.7 for Kubernetes 1.25 and set up an IP address pool that Metallb can use to assign IP addresses to services. This will help you improve the load balancing capabilities of your Kubernetes cluster and make it more scalable and reliable.

Updation for the below setup
https://www.adminz.in/2022/01/setting-up-metallb-load-balancer-with.html


Tuesday, September 13, 2022

Dynamic DNS with noip Solution

Dynamic DNS is an essential tool for those who want to connect to their network remotely or run a server from home. The issue with most residential ISPs is that their IP addresses change frequently, making it difficult to connect to your network or server from the internet. One solution to this issue is to use a dynamic DNS service like noip.
noip is a free dynamic DNS service provider that allows you to assign a domain name to your changing IP address. In this guide, we will show you how to set up dynamic DNS with noip on a Linux machine.

Step 1: Create a free account on noip.com

Visit noip.com and sign up for a free account. During the registration process, you will need to choose a hostname (domain name) that you want to use for your dynamic DNS. You will also need to verify your email address.


Step 2: Install noip DUC on your Linux machine

noip provides a Dynamic Update Client (DUC) that runs on your machine and updates your hostname with the latest IP address. Download the DUC package from noip.com, extract it, and install it by running the following commands:

cd /usr/local/src
wget https://www.noip.com/client/linux/noip-duc-linux.tar.gz
tar xzf noip-duc-linux.tar.gz
cd noip-2.1.9-1/
make install

Step 3: Configure noip DUC
After the installation, you need to configure the noip DUC with your account details. Run the following command to start the configuration wizard:

/usr/local/bin/noip2 -C
Step 4: Create a systemd unit file for noip2 Create the file /etc/systemd/system/noip2.service with the following content:

[Unit] Description=noip2 service [Service] Type=forking ExecStart=/usr/local/bin/noip2 Restart=always [Install] WantedBy=default.target

Step 5: Reload systemd and start the noip2 service
Reload systemd to make it aware of the new unit file:

sudo systemctl daemon-reload
Start the noip2 service:
sudo systemctl start noip2

Step 6: Enable the noip2 service at boot time
To have the noip2 service started at boot time, enable it:

sudo systemctl enable noip2