I need to execute a .cql file inside a kubernetes pod.
I did not try anything
To execute the .cql file inside a pod:
1>copy the file to a pod:
kubectl cp /path/of/the/file/.cql/ -n keyspace-name pod-name:/file/path/inside/the/pod -c name-of-container
2>ssh to cassandra pod:
kubectl exec -it pod-name -n keyspace-name -- bash
3>run the .cql file:
cqlsh -f/file/path/inside/the/pod
Related
Currently if I'm about to inspect my container, I have to do three steps:
kubectl get all -n {NameSpace}
kubectl describe {Podname from step 1} -n {NameSpace}
Find the Node Host and the container ID (My eyes are complaning!)
Switch to the host and execute "docker exec -ti -u root {Container ID} bash"
I am so mad about it right now. Wish somebody could offer some help to me and those who may share the same issue.
Pods are the smallest deployable units of computing that you can
create and manage in Kubernetes.
So, if you want to "enter" a container, you just need to "exec" into the pod in a particular namespace. Kubernetes will get you the shell/command for that pod.
kubectl -n somenamespace exec -it podname -- bash
There is no need to mention the node here as Kubernetes internally knows on which node the pod is scheduled.
If a Pod has more than one container, use --container or -c to specify
a container in the kubectl exec command. For example, suppose you have
a Pod named my-pod, and the Pod has two containers named main-app and
helper-app. The following command would open a shell to the main-app
container.
kubectl exec -it my-pod -c main-app -- /bin/bash
https://kubernetes.io/docs/tasks/debug-application-cluster/get-shell-running-container/
how i acces my namespace: kubens namespace
how i access my pod: acces my container: kubectl exec -it hello-6b588fc8c-jz89q --container test -- bash
i wante to cp a file from the filebeat container. but not work i try
From the kubectl cp --help output, an example is provided for your use case (copying from a remote pod to your local filesystem):
# Copy /tmp/foo from a remote pod to /tmp/bar locally
kubectl cp <some-namespace>/<some-pod>:/tmp/foo /tmp/bar
In your case, I believe the command would be
kubectl cp <namespace-of-pod>/dsp-onboarding-6b588fc8c-jz89q:/app/data/logs/dsp-onboarding.json.log . -c filebeat
Note the -c option is necessary in your case, since you want to cp the file off of a specific container in the pod.
To exec into a container in a pod, I use the following two commands (note the template flag in the first command trims the output to print just the name of the pods):
$ kubectl get pods --template '{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}'
app-api-6421cdf4fd-x9tbk
app-worker-432f86f54-fknxw
app-frontend-87dd65d49c-6b4mn
app-rabbit-413632c874-s2ptw
$ kubectl exec -it app-api-6421cdf4fd-x9tbk -- bash
It would be nice to exec into the container without having to discover the random guid at the end of the pod name every single time. How can I do this?
You can exec into a pod using the deployment
You can use the following command:
kubectl exec -it deploy/<deployment-name> -- bash
Suppose you have a Deployment with the name myadmin and namespace demo. After deploy, you can exec into the deployment's pod by running the below command:
$ export id=( kubectl get pod -n demo | grep 'myadmin' | awk 'END {print $1}' | xargs echo) && kubectl -n demo exec -it $id -- bash
I believe you expect this.
(sed 's/pod\///' is used below because kubectl get pod -o name gives you names like pod/rabbitmq-0 and you should cut first part)
kubectl exec -it $(kubectl get pod -o name | sed 's/pod\///' | grep api) -- bash
Similar to previous one you can use any known commands to find and sort needed objects. Providing version from your initial question
kubectl exec -it $(kubectl get pod --template '{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}'| grep api) -- bash
I run an .NET Core 2.1 in a container. It writes logs to a file within the container. I am able to run a docker exec bash command to inspect the log file, locally.
This application is then deployed with Kubernetes to a pod with more than one container.
How can I inspect the log file within each one of these containers?
You can exec into container within pod:
kubectl -n <namespace> exec -it <pod name> -c <container name> bash
But the better approach is to make your application stream logs to stdout or stderr, so you can access it directly with:
kubectl -n <namespace> logs <pod name> -c <container name>
I have problem login into one container of a multi-container pod.
I get the container id from the kubectl describe pod <pod-name>
kubectl describe pod ipengine-net-benchmark-488656591-gjrpc -c <container id>
When i try:
kubectl exec -ti ipengine-net-benchmark-488656591-gjrpc -c 70761432854f /bin/bash
It says: Error from server: container 70761432854f is not valid for pod ipengine-net-benchmark-488656591-gjrpc
Ah once more detailed reading the man page of kubectl exec :
Flags:
-c, --container="": Container name. If omitted, the first container in the pod will be chosen
-p, --pod="": Pod name
-i, --stdin[=false]: Pass stdin to the container
-t, --tty[=false]: Stdin is a TTY
So i just used the container name from my manifest.yaml and it worked like charm.
Name of the container: ipengine-net-benchmark-iperf-server
kubectl exec -ti ipengine-net-benchmark-488656591-gjrpc -c ipengine-net-benchmark-iperf-server /bin/bash