- 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, April 10, 2023
Kubernetes(k8s) Sample Commands - 02
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
kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.13.7/config/manifests/metallb-native.yaml
apiVersion: metallb.io/v1beta1kind: IPAddressPoolmetadata:name: first-poolnamespace: metallb-systemspec:addresses:- 172.16.2.80-172.16.2.90
kubectl apply -f <filename>.yaml
Tuesday, September 13, 2022
Dynamic DNS with noip Solution
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
/usr/local/bin/noip2 -C
/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
sudo systemctl daemon-reloadStart the noip2 service:sudo systemctl start noip2
sudo systemctl enable noip2