How to Debug Kubernetes Applications With Ephemeral Containers

  Рет қаралды 11,961

DevOps Toolkit

DevOps Toolkit

Күн бұрын

Пікірлер: 56
@DevOpsToolkit
@DevOpsToolkit Жыл бұрын
How do you debug containers in Kubernetes clusters when observability tools are not enough?
@hugolopes5604
@hugolopes5604 Жыл бұрын
breakglass, and ssh into the container, and do a post mortem for the breakglass
@chrisre2751
@chrisre2751 Жыл бұрын
Thanks!
@DevOpsToolkit
@DevOpsToolkit Жыл бұрын
Thanks a ton!
@maxreuv
@maxreuv Жыл бұрын
Another one of "must haves". Thank you!
@hkupty
@hkupty Жыл бұрын
Thanks for that! I have a label in the pods that is `live = 1`, which I use for taking pods out if want to debug them (setting `live = 0` would cause deployment to spawn a new pod and service to route to the newly created pod). I can safely run kubectl debug on that pod now given it can safely be removed later anyways :)
@javisartdesign
@javisartdesign Жыл бұрын
thanks! really useful, sometimes it's necessary to test communications and other stuff
@IvanRizzante
@IvanRizzante Жыл бұрын
Thanks for another great video! I totally agree on using ephemeral containers for debugging, but for GitOps lovers like me that kubectl debug means that I have to contact Joe, that guy that works in the basement and nobody knows...who's the only one having direct access to the cluster 😅
@DevOpsToolkit
@DevOpsToolkit Жыл бұрын
Not really... Kubectl debug command is just a shortcut that contacts kube api to edit the pod definition. You could modify your manifest by adding ephemeral container spec, push it to git, and get the same result. From there on it all depends on whether you have permissions to sh into that container.
@IvanRizzante
@IvanRizzante Жыл бұрын
@@DevOpsToolkit that's what I thought too, but as you said that would require kubectl exec in the end. I agree with you when you say that even in GitOps world you still need someone authorized to interact directly with the cluster, so I think that Joe would save my day in these corner cases!
@DevOpsToolkit
@DevOpsToolkit Жыл бұрын
To me, ephemeral containers are the last resort when all observability tools )that do not need kubectl) fail to reveal the issue. That's the "break glass" situation which always requires elevated permissions. It's "we do not know what to do so let's dig in" type of situation.
@IvanRizzante
@IvanRizzante Жыл бұрын
@@DevOpsToolkit I totally agree 👍 now I'm waiting for a video on kubearmor 👍
@devxp-tech
@devxp-tech Жыл бұрын
Very helpful, thank you! ❤
@toddfinoch
@toddfinoch Ай бұрын
Curious to know if you ever had a scenario where the debug pod worked but the original did not still? Just an example, you have a DNS resolution issue and want to do an nslookup, but don't have it installed in the original container.
@DevOpsToolkit
@DevOpsToolkit Ай бұрын
Most of the time i don't have anything but the app itself in original containers so the only way to debug issues that cannot be observed from outside pods is to add a debug pod.
@toddfinoch
@toddfinoch Ай бұрын
​@@DevOpsToolkit thanks for the quick reply. Could it be possible that the problem is only in the container?
@DevOpsToolkit
@DevOpsToolkit Ай бұрын
@toddfinoch i don't have any info so anything could be a problem.
@Babbili
@Babbili Жыл бұрын
i keep on saving your videos 😆
@chrisre2751
@chrisre2751 Жыл бұрын
Hi Victor, how do you think about distroless-images from google?
@DevOpsToolkit
@DevOpsToolkit Жыл бұрын
I used them only briefly so I'm not th Best judge of them. What i saw makes me think they're ok.
@devopssimplify9884
@devopssimplify9884 Жыл бұрын
Again a great Video!!! I wanted to implement the same but the problem is my cluster has restriction for specifying resource limit and request for pod. How to mention that with kubectl debug? My debug pod needs to have resource mentioned, please suggest!!!!
@DevOpsToolkit
@DevOpsToolkit Жыл бұрын
The `kubectl debug` command does not allow you to specify resource limits and requests. As a matter of fact, `kubectl create` does not have that option either. The logic behind `kubectl` is that it provides only some of the flags when creating resources. The assumption is that anything more needs to be specified as a YAML file. That is equally valid for `kubectl run` as for `kubectl debug`. What that means is that you'd need to define emphemeral containers as part of your manifest if you need resource limits and/or requests. The spec is in: kubernetes.io/docs/reference/generated/kubernetes-api/v1.27/#ephemeralcontainer-v1-core So, when you want to debug, add ephemeral container to manifest with the Pod (or Deployment or StatefulSet) and execute `kubectl apply --filename ...` or whatever you're using normally.
@DevOpsToolkit
@DevOpsToolkit Жыл бұрын
The alternative solution is to use Mutating Admission Controllers with, let's say, Kyverno. You can configure it to add resource requests and limit every time an ephemeral container is created. That is probably a more elegant and user-friendly solution.
@devopssimplify9884
@devopssimplify9884 Жыл бұрын
@@DevOpsToolkit Wow wonderful! thanks a lot!
@devopssimplify9884
@devopssimplify9884 Жыл бұрын
@@DevOpsToolkit You are really genious!
@lightman8527
@lightman8527 Жыл бұрын
Great video! On a side note, never heard about kubearmor. Are you planning to make a video on it? How mature is the project in your experience?
@DevOpsToolkit
@DevOpsToolkit Жыл бұрын
KubeArmor is on my to-do list. That's why I mentioned it.
@Babbili
@Babbili Жыл бұрын
@@DevOpsToolkit is it an alternative to Falco Sysdig ?
@DevOpsToolkit
@DevOpsToolkit Жыл бұрын
It is :)
@squalazzo
@squalazzo Жыл бұрын
so, it seems like this is not a solution for scenarios like a statefulset with mongodb, with 2 replicas and 1 headless pod for backup, for example... or any statefulset, in the end, as you're working with data which could be already old, and not lively used by the app using that sts... right?
@DevOpsToolkit
@DevOpsToolkit Жыл бұрын
Debugging by entering containers is (should be) the last resort used only when observability fails to show what we're looking for. On top of that, we rarely debug third-party apps like that. That's typically reserved for our own apps. Now, if you do need to debug (like that) third-party apps, and they are stateful, and their containers do not have the tools we need (which they often do), I tend to NOT create a copy but attach ephemeral container directly to one of the STS pods.
@squalazzo
@squalazzo Жыл бұрын
@@DevOpsToolkit thanks!
@abcd-z9u
@abcd-z9u Жыл бұрын
I tried this, but my debug pod is failing with the following error i got from describe: message: '0/7 nodes are available: 1 node(s) didn''t have free ports for the requested pod ports. preemption: 0/7 nodes are available: 1 node(s) didn''t have free ports for the requested pod ports, 6 node(s) didn''t match Pod''s node affinity/selector.'
@GoshaDo
@GoshaDo Жыл бұрын
debugging in production is safe. We are doing it all the time using Rookout dynamic observability tool. much more advanaced tech for debugging then attach containers and stoping the application.
@chasim1982
@chasim1982 Жыл бұрын
Great 👍 Content & Learning, one question can I do same stuff by launching a new pod of my application with debug side car? Please correct me, if I am wrong, thanks for amazing content, learned a lot from you ❤.
@DevOpsToolkit
@DevOpsToolkit Жыл бұрын
You can create a new pod and then attach a debug container but i think it's easier to simply use the --copy arhument.
@chasim1982
@chasim1982 Жыл бұрын
@@DevOpsToolkit I am using eks 1.23
@bhavasarpritesh
@bhavasarpritesh Жыл бұрын
How can we see pods files in debug container?
@DevOpsToolkit
@DevOpsToolkit Жыл бұрын
la commabd should work
@DennisHaney
@DennisHaney Жыл бұрын
Tbh. If I had to resort to this for debugging, the first thing i would afterwards was to delete the pod to see if it came back with no errors
@DevOpsToolkit
@DevOpsToolkit Жыл бұрын
Yeah. That's why creating a copy of a pod is very useful.
@oleksandrsimonov9200
@oleksandrsimonov9200 Жыл бұрын
Still the question how to make a such limited container with Node, Python or Ruby? Ok, you don’t have a shell, but you need an interpreter
@DevOpsToolkit
@DevOpsToolkit Жыл бұрын
For those, i would pick ChainGuard images. They are small, (mostly) without vulnerabilities, abd built daily. You'll find a variation for almost every language.
@oleksandrsimonov9200
@oleksandrsimonov9200 Жыл бұрын
@@DevOpsToolkit yeah... and they using alpine... Its causes a lot of issues with ffi for example, where we need to use glibc instead. For now we using a mulsistage minideb images with removing of dev packages and other not needed things on latest stage.
@DevOpsToolkit
@DevOpsToolkit Жыл бұрын
I thought that ChainGuard fixed that by using glibc instead of musl.
@jemag
@jemag Жыл бұрын
​@@oleksandrsimonov9200they use Wolfi, not alpine. You can use glibc or musl
@PS-xn8ej
@PS-xn8ej Жыл бұрын
you first should show kubectl get pods on what you are working, not end command ...
@testtestlast4306
@testtestlast4306 Жыл бұрын
👀
@iximiuz
@iximiuz 11 ай бұрын
While I fully aggree with the overal sentiment, I'm afraid this video is dangerously misleading in details. 1) Don't build your container images `FROM scratch` - scratch containers lack the vital parts of an OS like /etc/{passwd,group} files and TLS certificates (if you absolutely have to use a minimal image, use a slim/distroless base) 2) Ephemeral containers don't run forever - as soon as the main process exits (of crashes), the ephemeral container stops.
@petermerelis
@petermerelis 5 ай бұрын
this is why Dockerfiles should be multi-stage. build with all necessary bits and then copy to as slimmed down an image as possible for the runtime.
What to Run in Kubernetes? The Ultimate Guide
12:59
DevOps Toolkit
Рет қаралды 9 М.
Secrets Made My Life Miserable - Consume Secrets Easily With Teller
13:48
Quilt Challenge, No Skills, Just Luck#Funnyfamily #Partygames #Funny
00:32
Family Games Media
Рет қаралды 55 МЛН
UFC 310 : Рахмонов VS Мачадо Гэрри
05:00
Setanta Sports UFC
Рет қаралды 1,2 МЛН
Try this prank with your friends 😂 @karina-kola
00:18
Andrey Grechka
Рет қаралды 9 МЛН
How to debug Kubernetes? (Deployments, Services & Ingress)
18:45
Anton Putra
Рет қаралды 10 М.
Do NOT Learn Kubernetes Without Knowing These Concepts...
13:01
Travis Media
Рет қаралды 344 М.
Kubernetes Debugging techniques - Ephemeral containers
30:07
Kubesimplify
Рет қаралды 2,5 М.
Debug Kubernetes with eBPF and Inspektor Gadget
11:01
DevOps Toolkit
Рет қаралды 6 М.
Breakpoints in Your Pod: Interactively Debugging Kubernetes Applications - Daniel Lipovetsky, D2IQ
21:52
CNCF [Cloud Native Computing Foundation]
Рет қаралды 2,2 М.
10 Must-Have Kubernetes Tools
18:53
DevOps Toolkit
Рет қаралды 40 М.
What The Heck Are Kubernetes Resources, CRs, CRDs, Operators, etc.?
21:08
Is eBPF The End Of Kubernetes Sidecar Containers?
16:01
DevOps Toolkit
Рет қаралды 20 М.
Quilt Challenge, No Skills, Just Luck#Funnyfamily #Partygames #Funny
00:32
Family Games Media
Рет қаралды 55 МЛН