Skip to content
This repository has been archived by the owner on Feb 12, 2021. It is now read-only.

fleet functionality K8s does not have #945

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions kubernetes/deprecated-functionality.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Deprecated functionality

While fleet and Kubernetes are largely similar in functionality, some specific fleet features do not have direct equivalents in Kubernetes.Fortunately, workarounds exist for almost every use-case. Several of these features and workarounds are outlined below.

## Container Dependencies

Fleet uses systemd service dependencies to outline a *limited* dependency graph. When units are co-located then containers may be specified to start in a specific order; only beginning a service *after* others it depends on have begun. This is not really a fleet feature but rather a systemd feature; it is limited by the design and feature-set of systemd

While this has been [discussed at length in the Kubernetes community][pod-deps-discussion] it has not been implemented in Kubernetes as of early 2017. There are two workarounds for this in Kubernetes:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should essentially say most use cases can be solved by crash loops on a pod and init containers. I don't think pod deps will ever be implemented.


1. Grouping related containers in a Pod.
2. [Init containers][k8s-init-containers]

### Grouping containers in Pods

This is the most straight forward to approach the problem. Pods specs can contain multiple containers. By grouping related containers in one Pod then Kubernetes will co-locate them and monitor if all of the containers are functioning correctly.

[comment]: # (TODO: Include an example?)

### Init containers

[Init containers][k8s-init-containers] are containers run before a Pod starts up. They can be used to manage assets, wait for services, and perform general pre-pod setup. A pod is not scheduled until it's init-containers complete.

[comment]: # (TODO: Include an example?)

## Graceful Exit Command (ExecStop)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ExecStop in fleet is somewhat broken, tbh: coreos/fleet#1000. I think this also warrants calling out.


Fleet uses the systemd option [ExecStop][fleet-execstop] to instruct systemd how to stop a service gracefully. **Note** that this feature has worked in fleet in the past, but [has proven to be problematic in practice][fleet-exec-issue].

While this functionality does not exist in Kubernetes, the `ExecPreStop` does have an analogue in the Kubernetes world: `lifecycle.preStop`!

A Pod [lifecycle.preStop][lifecycle-hooks] directive specifies a command run **before** Kubernetes terminates an application with `SIGTERM`. This achieves a similar result of gracefully stopping a container.

Here is an example of using `lifecycle.preStop`, inspired by the Kubernetes docs:

```yaml
apiVersion: v1
kind: Pod
metadata:
name: web-server
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
lifecycle:
preStop:
exec:
# SIGTERM triggers a quick exit; gracefully terminate instead
command: ["/usr/sbin/nginx","-s","quit"]
```

[comment]: # (TODO: Think of a better example for preStop. Need a clearer demo.)

More information can be found at the [Kubernetes Pods user guide][prestop]

**Note:** The `preStop` directive is not a replacement for ExecStop. After a grace-period the container will still be killed via `SIGTERM`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this isn't totally true. You can set the graceful shutdown time to nearly forever terminationGracePeriodSeconds

https://kubernetes.io/docs/api-reference/v1/definitions/#_v1_pod


[fleet-exec-issue]: https://github.com/coreos/fleet/issues/1000
[fleet-execstop]: https://coreos.com/fleet/docs/latest/launching-containers-fleet.html#run-a-container-in-the-cluster
[k8s-init-containers]: http://kubernetes.io/docs/user-guide/pods/init-container/
[lifecycle-hooks]: http://kubernetes.io/docs/user-guide/production-pods/#lifecycle-hooks-and-termination-notice
[pod-deps-discussion]: https://github.com/kubernetes/kubernetes/issues/2385
[prestop]: http://kubernetes.io/docs/user-guide/pods/#termination-of-pods