Here is the shell script I want to execute. for example, I have 100 kubernetes pods with 100 different vehicles.
I want a list to be generated of cars and choose 10 particular cars from the list.
My goal is to deploy a new image into the selected car's pod.
I am able to generate a list of cars through the array and grep.
#!/bin/bash
array=$(kubectl get pods -n ns -o=name | grep "cars" )
declare array
INDEX=1
for i in ${array[@]}; do
echo ${INDEX} $i
INDEX=$(expr $INDEX + 1) ## this will make a numbered list.
done
sample output
1 cars-bmw
2 cars-audi
3 cars-volkswagen
4 cars-jaguar
5 cars-ferrari
6 cars-toyota
7 cars-honda
How to achieve selection of cars through either name or just selecting the number of the car?
Please suggest if there is another way to do this. or suggest a better practice for the shell script.
while [[ read -p {array[@]} ]]; do
echo "choosing car " {array[@]}
kubectl edit pod -n ns $podname -o yaml
done
exit 1
array=($(kubectl get pods -n ns -o=name | grep "cars" ))And there is no need to declare it afterwards as assigning does declare.