Below you will find pages that utilize the taxonomy term “Kubectl”
List cluster's images
Kubernetes documentation provides this example but I prefer:
FILTER="{range .items[*].spec['initContainers', 'containers'][*]}{.image}{'\n'}{end}"
CONTEXT="..."
kubectl get pods \
--all-namespaces \
--output=jsonpath="${FILTER} \
--context="${CONTEXT}" \
| sort | uniq -c
kubectl patch'ing keys containing forward slash
I wanted to use kubectl to (JSON) patch an Ingress. The value needing patching is an annotation tailscale.com/funnel.
TL;DR The Stack overflow answer has the solution: replace
/with~1
With apologies for using YAML instead of JSON:
Ingress:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
tailscale.com/funnel: "true"
The solution becomes:
VALUE="true" # Or "false"
# Pretty-printed for clarity
PATCH="
[
{
'op':'replace',
'path':'/metadata/annotations/tailscale.com~1funnel',
'value':'${VALUE}'
}
]"
kubectl patch ingress/${INGRESS} \
--namespace=${NAMESPACE} \
--context=${CONTEXT} \
--type=json \
--patch="${PATCH}"
`kubectl` auth changes in GKE v1.25
I was prompted by a question on Stack overflow “How to remove warning in kubectl with gcp auth plugin?” to try this new mechanism for myself. It’s described by Google in the a post Here’s what to know about changes to kubectl authentciation coming in GKE v1.25.
One question I’d not considered is: how is the change manifest? Thinking about it, I realized it’s probably evident in the users section of kubectl config. A long time, I wrote a blog post Kubernetes Engine: kubectl config that explains how kubectl leverages (!) gcloud to get an access token for GKE.
`kubectl get events`
NAMESPACE=test
kubectl create namespace ${NAMESPACE}
kubectl create deployment kuard \
--image=gcr.io/kuar-demo/kuard-amd64:blue \
--port=8080 \
--namespace=${NAMESPACE}
Typically, I’d then use kubectl describe pod to check the Events section for any issues:
kubectl describe pod \
--selector=app=kuard \
--namespace=test
But, from the Pod’s name (without the pod/ prefix), you can:
NAME=$(\
kubectl get pod \
--selector=app=kuard \
--namespace=test \
--output=name) && \
NAME=${NAME#pod/} && \
echo ${NAME}
kubectl get events \
--field-selector=involvedObject.name=${NAME} \
--namespace=${NAMESPACE} \
--output=jsonpath='{range .items[*]}{.message}{"\n"}{end}'
NOTE
range‘ing over the items permits adding newlines (\n) after each entry. Using{.items[*].message}yields a less manageable result.