From b35cf4043d4f12bdac5ff25765230c8ec773f684 Mon Sep 17 00:00:00 2001 From: Mihir Date: Sun, 12 Jul 2020 16:10:44 -0700 Subject: [PATCH] added exec and set namespace commands --- tools/kubernetes.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tools/kubernetes.sh b/tools/kubernetes.sh index c6690fb..b3d9da7 100644 --- a/tools/kubernetes.sh +++ b/tools/kubernetes.sh @@ -23,6 +23,8 @@ kubectl config view -o jsonpath='{.users[?(@.name == "k8s")].user.password}' # Set credentials for foo.kuberntes.com kubectl config set-credentials kubeuser/foo.kubernetes.com --username=kubeuser --password=kubepassword +# Set active namespace +kubectl config set-context --current --namespace=namespace_name ############################################################################## # VIEWING, FINDING RESOURCES @@ -115,3 +117,21 @@ kubectl logs pod_name # Stream pod container logs (stdout, multi-container case) kubectl logs -f pod_name -c my-container + + +############################################################################## +# INTERACTING WITH RUNNING PODS +############################################################################## + + +# Run command in pod +kubectl exec pod_name -- command_name + +# Run command in pod with multiple containers +kubectl exec pod_name -c container_name -- command_name + +# Get terminal of pod +kubectl exec -it pod_name /bin/sh + +# Get terminal of a container running in pod with multiple containers +kubectl exec -it pod_name -c container_name /bin/sh