cop file from remote conatiner to localmachine? - kubernetes

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.

Related

How to create a pod and attach with a terminal later on

I want to run a multi-container pod, and interactuate with it via a terminal.
With kubectl run -ti I can run a monocontainer pod and attach easily to it.
I think I have to kubectl apply to create a complex pod, and later attach to it.
I've tried this and it doesn't work:
 kubectl run alpine --image alpine pod/alpine created
 kubectl attach -i alpine If you don't see a command prompt, try pressing enter.
error: unable to upgrade connection: container alpine not found in pod alpine
I'm using latest k3s v1.25.4+k3s1 under a Linux host (Ubuntu 22.04).
This does work:
 kubectl run alpine --image alpine --command sleep -- 999d
pod/alpine created
 kubectl exec -ti alpine -- ash
/ #
I need an auxiliary sleep.
You need attach interactively first:
kubectl run -it alpine --image alpine
Then detach by using CTRL-P, then CTRL-Q
To reattach, you then use:
kubectl attach alpine -c alpine -i -t
Note that if you close the shell at any point, you terminate the pod, and it will restart

How to execute a .cql file inside a kubernetes pod?

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

Not able to run kubectl cp command in Argo workflow

I am trying to run this command in my Argo workflow
kubectl cp /tmp/appendonly.aof redis-node-0:/data/appendonly.aof -c redis -n redis
but I get this error
Error from server (InternalError): an error on the server ("invalid upgrade response: status code 200") has prevented the request from succeeding (get pods redis-node-0)
surprisingly when I am copying the file from a pod to local system then it is working, like this command kubectl cp redis-node-0:/data/appendonly.aof tmp/appendonly.aof -c redis -n redis
Any idea what might be causing it?
Solution -
Not sure what was causing this issue but found this command in the docs that worked fine
tar cf - appendonly.aof | kubectl exec -i -n redis redis-node-0 -- tar xf - -C /data

How can I enter a Kubernetes managed container faster?

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 to inspect the contents of a container of a pod deployed with Kubernetes

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>