kubectl get services with count of actively running pods

How can I list all Kubernetes services along with the number of active pods associated with each service? Currently, I can list all services with: kubectl get services I would like to add one additional column to the output, which lists active pod count for each service. >Solution : A service is basically a load… Read More kubectl get services with count of actively running pods

Delete pods using kubectl containing a substring

When I run the command kubectl get pods | grep "apisix", I get the following data apisix-dev-78549978b7-pvh2v 1/1 Running 6 (4m19s ago) 8m14s apisix-dev-dashboard-646df79bf-mwkpc 1/1 Running 6 (4m35s ago) 8m12s apisix-dev-etcd-0 1/1 Running 0 8m12s apisix-dev-etcd-1 1/1 Running 0 8m11s apisix-dev-etcd-2 0/1 CrashLoopBackOff 4 (24s ago) 8m11s apisix-dev-ingress-controller-58f7887759-28cm9 1/1 Running 0 8m11s apisix-dev-ingress-controller-6cc65c7cb5-k6dx2 0/1 Init:0/1… Read More Delete pods using kubectl containing a substring

How to parse a string of a kubectl cmd output in a shell script?

kubectl get nodes -o name gives me the output node/k8s-control.anything node/k8s-worker1.anything I need to get only control worker1 as output and want to iterate through these elements for elm in $(kubectl get nodes -o name); do echo "$elm" >> file.txt; done So the question is how to get the string between node/k8s- and .anything and… Read More How to parse a string of a kubectl cmd output in a shell script?

What is the difference of writing to files using ">>" vs using linefeed character "\n" in a string when loading text to Kubernetes secret?

I have observed that kubectl inserts an additional \ to linefeed characters when using the –from-literal option. It works as expected when loading "the same" content from a file. Clearly, there must be a difference because the stdout looks different but I fail to see why. echo "api_key" >> .tmp echo "api_value" >> .tmp cat… Read More What is the difference of writing to files using ">>" vs using linefeed character "\n" in a string when loading text to Kubernetes secret?

kubectl apply ingress: Unknown field error

I have ingress as: apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: mongoexpress-ingress spec: rules: – host: mylocalmongoexpress.com http: paths: – backend: serviceName: mongoexpress-service servicePort: 8081 When I run ‘kubectl apply -f mongoexpress-ingress.yaml’, I get error: error: error validating "mongoexpress-ingress.yaml": error validating data: [ValidationError(Ingress.spec.rules[0].http.paths[0].backend): unknown field "serviceName" in io.k8s.api.networking.v1.IngressBackend, ValidationError(Ingress.spec.rules[0].http.paths[0].backend): unknown field "servicePort" in io.k8s.api.networking.v1.IngressBackend, ValidationError(Ingress.spec.rules[0].http.paths[0]): missing… Read More kubectl apply ingress: Unknown field error