# Share your experience with k8s: how to reduce restarts?

**URL:** <https://erlangforums.com/t/share-your-experience-with-k8s-how-to-reduce-restarts/4422>\
**Category:** Chat / Discussions\
**Tags:** kubernetes\
**Created:** [January 26, 2025, 6:57pm UTC](https://erlangforums.com/t/share-your-experience-with-k8s-how-to-reduce-restarts/4422 "2025-01-26T18:57:21Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![maxlapshin](https://erlangforums.com/user_avatar/erlangforums.com/maxlapshin/32/1593_2.png) [@maxlapshin](https://erlangforums.com/u/maxlapshin)\
**Post date:** [January 26, 2025, 6:57pm UTC](https://erlangforums.com/t/share-your-experience-with-k8s-how-to-reduce-restarts/4422/1 "2025-01-26T18:57:21Z")

</div>

We love erlang in situations, when you have to handle each socket for a very long time: hours, days, weeks. No other ecosystem can give that easiness of debugging leaking sockets, memory, etc.

Kubernetes, being a new operation system instead of linux or windows, brings new approach: no state, nothing persistent, everything temporary. Reconfigure by restart.

How can we deal with this in erlang? Seems that only way is to refuse from long living connections as much as possible. Move reconnect and retransmit logic to client side.

---

<div class="post-metadata">

**Author:** ![rlipscombe](https://erlangforums.com/user_avatar/erlangforums.com/rlipscombe/32/459_2.png) [@rlipscombe](https://erlangforums.com/u/rlipscombe)\
**Post date:** [January 28, 2025, 12:36pm UTC](https://erlangforums.com/t/share-your-experience-with-k8s-how-to-reduce-restarts/4422/2 "2025-01-28T12:36:56Z")

</div>

> [@maxlapshin](#):
>
> How can we deal with this in erlang?

At the moment, we do everything the k8s way, but we’ve been kicking around the idea of writing a BEAM-aware controller that would be used instead of the built-in deployment controller.

We haven’t got past the talking-about-it-over-beers stage, though. We also use a lot of Kafka, so our use case might not generalise very well.

---

<div class="post-metadata">

**Author:** ![maxlapshin](https://erlangforums.com/user_avatar/erlangforums.com/maxlapshin/32/1593_2.png) [@maxlapshin](https://erlangforums.com/u/maxlapshin)\
**Post date:** [January 28, 2025, 2:46pm UTC](https://erlangforums.com/t/share-your-experience-with-k8s-how-to-reduce-restarts/4422/3 "2025-01-28T14:46:27Z")

</div>

Well, “talking-about-it-over-beers” is a very important stage, because it may be used to share experience. And just taking some beer is a good idea.

As far as I understand, the immutable nature of container doesn’t give a chance to mark it “upgraded” without full restart even if code migration was done properly. Correct?

But seems that you plan to postpone restart as far as possible with your own Operator?

---

<div class="post-metadata">

**Author:** ![rlipscombe](https://erlangforums.com/user_avatar/erlangforums.com/rlipscombe/32/459_2.png) [@rlipscombe](https://erlangforums.com/u/rlipscombe)\
**Post date:** [January 28, 2025, 3:09pm UTC](https://erlangforums.com/t/share-your-experience-with-k8s-how-to-reduce-restarts/4422/4 "2025-01-28T15:09:20Z")

</div>

> [@maxlapshin](#):
>
> As far as I understand, the immutable nature of container doesn’t give a chance to mark it “upgraded” without full restart even if code migration was done properly. Correct?

In a sense, yes. But the only thing that cares about whether a container was upgraded is the `Pod` object (and, by extension, the `Deployment` or `StatefulSet` that owns it).

So: if you make all Erlang pods use identical, maybe even empty, BEAM container images, then they don’t need to be upgraded.

At that point, you must use … something that needs inventing … to start the original applications and to track the state of the migrated applications within the BEAM.

> [@maxlapshin](#):
>
> But seems that you plan to postpone restart as far as possible with your own Operator?

Like I say: our use case is different from the general case. We don’t need to avoid restarts; we just need to manage them within a larger context. We might end up going in a different direction.

---

<div class="post-metadata">

**Author:** ![rlipscombe](https://erlangforums.com/user_avatar/erlangforums.com/rlipscombe/32/459_2.png) [@rlipscombe](https://erlangforums.com/u/rlipscombe)\
**Post date:** [January 28, 2025, 3:11pm UTC](https://erlangforums.com/t/share-your-experience-with-k8s-how-to-reduce-restarts/4422/5 "2025-01-28T15:11:04Z")

</div>

> [@rlipscombe](#):
>
> … something that needs inventing …

Remember that Kubernetes is just a bunch of shell scripts in a trench coat. Inventing your own resource types and controllers and operators isn’t _that_ difficult.

---

<div class="post-metadata">

**Author:** ![maxlapshin](https://erlangforums.com/user_avatar/erlangforums.com/maxlapshin/32/1593_2.png) [@maxlapshin](https://erlangforums.com/u/maxlapshin)\
**Post date:** [January 28, 2025, 3:28pm UTC](https://erlangforums.com/t/share-your-experience-with-k8s-how-to-reduce-restarts/4422/6 "2025-01-28T15:28:48Z")

</div>

Yes, we write our own Operators, because it is required. I’m a bit afraid to fall into spaceship building heresy instead of practical things =)

---

<div class="post-metadata">

**Author:** ![eproxus](https://erlangforums.com/user_avatar/erlangforums.com/eproxus/32/452_2.png) [@eproxus](https://erlangforums.com/u/eproxus)\
**Post date:** [January 30, 2025, 7:30pm UTC](https://erlangforums.com/t/share-your-experience-with-k8s-how-to-reduce-restarts/4422/7 "2025-01-30T19:30:51Z")

</div>

There are some nuggets of useful info here (not sure how up-to-date it is though): [Kubernetes | Adopting Erlang](https://adoptingerlang.org/docs/production/kubernetes/)
