147 points · by alexellisuk · 5y ago · 78 comments
Not that it is an alternative to K8s in every scenario, but it should have gotten at least a mention in the intro section.
This does makes me want to build "kilx" k8s inside lxd heh
https://github.com/ochinchina/supervisord
You can configure it like supervisord with a single config file,
https://riptutorial.com/docker/example/14132/dockerfile-plus...
But the golang version is much smaller / less deps and can be installed as a static binary.
With an LXC client on my laptop I am able to launch instances without using local resources. The instance has profiles setup to add the containers to my local lan for ease of access.
Launching a new machines is only a few commands away.
If I'm writing a docker compose file, maybe I write something with a DB container, and 3x backend containers, and 2x frontend containers. If I'm using Docker Swarm, then that's probably what I deploy as a "stack."
But there's no immediate analogue of this in Kubernetes. Are my DB, backend, and frontend containers grouped in the same pod? ("Just like you can do with docker compose" as you say.) No, absolutely not! Otherwise I'm scaling up DBs when I scale up my frontend/backend. The DB is only finally grouped with them at the namespace level.
OK, so split off the DB. Do I also split the frontend/backend? Well, maybe not. Both for performance reasons that don't exist in compose/swarm and for practicality of scaling, maybe I tie those together so there's always 1:1 frontend:backend, even if I'm wasting some resources. Or maybe I don't, and put all three as separate workloads in a namespace so I can scale each appropriately.
But is a namespace like a Docker Swarm stack? Oh dear no, it's also the basis for access control (sometimes) and resource discovery (sometimes) and for service discovery (almost always, at least).
How many namespaces do I need? Where should I split stuff? Are namespaces for isolating different environments (staging, prod, feature branches)? For isolating business units? For isolating all the way down to the workload level, with only one deployment + configmap + serviceaccount + etc? To this day I don't know, even talking to the same ops folks I see their opinions change over time, and not consistently in the same direction.
So in the end there's nothing in Kubernetes that really looks like a Docker compose file / Docker swarm "stack", and that kind of sucks because that's really the "project" or "application" level a lot of developers outside microservice hellworld or FAANG hyperspecialization work with on a day-to-day basis. And there doesn't seem to be a congealing best practice over how to structure full applications in spite of this. So for anyone who just wants to orchestrate a couple dozen containers for a 10 person team, you're really just throwing YAML in a despair hole and hoping the next tool you want doesn't have a different opinion than the five you already have.
In a large organization, you might see:
- a cluster per environment (staging, dev, prod, ...)
- a namespace per team (or business unit)
- some more namespaces for operators like cert-manager, tekton, ...
- an Helm chart for each application deployed in the team's namespace
If you're building a SaaS product, you might see: - a namespace per client
- an helm chart for your product deployed in each namespace
But basically, you'll often have the following: - one "service" per container (frontend, backend, db, ...)
- one container per pod + sidecar containers like kube-proxy, or vault (to refresh secrets as they change)
- a deployment/statefulset/daemonset to scale the pods
- a service resource to access the pods (DNS resolution)
- maybe an Ingres resource to expose your services to outside trafic
Your Helm chart (or any other packaging solution) may group multiple Deployments/StatefulSets/DaemonSets and Services into a single package, describing your application. Then you deploy however you want this package.Personally, I use namespaces to split things by features:
- one namespace for monitoring (kubirds, prometheus, ...)
- one namespace for secrets (cert-manager, kubevault, ...)
- one namespace for databases (kubedb, ...)
- one namespace for cicd (tekton, kapp-controller, ...)
- etc...
Then one namespace per "project" (a set of applications and resources provided by the operators running in the "feature" namespaces).TL;DR: There is no "one true solution/pattern", only what fits your needs.
> Kubernetes is a framework... There is no "one true solution/pattern", only what fits your needs.
Right, this is the opposite of what "framework" means in the rest of software development. If I choose RoR or Spring, it's because I want someone else to have made these decisions, reasonably, for me.
Kubernetes is instead like a random pile of tools, most of which are not directly useful to developers, with minimal guidance on which you should use or how you should put them together. All the sharp edges of the Unix shell, and none of the composability or fluency.
If you want security with containers, use Firecracker. It uses Micro VMs rather than just kernel-level restrictions, so even a Linux kernel security bug shouldn't be able to jump out to the host or other containers/Firecrackers.
These things force the application to run in restricted environments where capabilities are reduced, system calls are filtered, apparmor profiles and selinux labels are applied, among other things.
These are the same sort of things that chrome, for instance, does to make it harder to do bad things from the browser. They are hardening techniques. Images are automatically checksummed on download, and for certain things even signatures are checked (more of this soon).
Just because they do not protect you from a kernel exploit (also actually not true, seccomp filters have prevented a number of kernel exploits from inside the container) does not mean they are not added security.
The important thing to know what your attack surface is and what is acceptable risk for the workloads you are running. And yes, it is important to understand that containers do not isolate you completely from kernel exploits.
It is also important to understand the control plane (runtime up to the orchestrator) is much more likely to introduce security issues than the container itself.
There are multiple independent projects involved in securing a standard orchestrated docker style container (some of the set of Linux kernel/Linux distro/runc/containerd/docker/k8s) and no obvious owner of overall security configuration and problems.
we've seen examples of this, e.g. k8s disabling Docker's seccomp filter, or more recently the difficulty in how to handle clone(3) and seccomp filters.
For me it's that comparison with dedicated security sandboxes, is that in other projects there's a single team handling the whole security picture , which is likely to make things easier to manage.
This characterisation is too charitable, without qualifications. It depends a lot on the container runtime and configuration. Out of the box with Docker you don't get AppArmor or SELinux, and apps run as root where they normally wouldn't (because uid remapping, aka user namespaces is disabled by default, and people rarely bother to set up non-root users in containers).
As a bonus, applying security updates is left as an exercise to you, meaning it often doesn't happen.
Also, complexity is the enemy of secutity. Containers are yet another added layer that you have to juggle in your head when trying to make sense of the whole system you're building and operating. If used wisely and with good understanding, monitoring and processes, they can be a net positive despite this, but not necessarily so.
I don't recall why we don't turn on selinux when it is available.
And docker at least has an update delivery story (same as microVMs as well) compared to traditional ops where there are patching cycles and anything that can't be yum/apt updated is basically ignored and updated on quarter/year time. Build a base image in your CI pipeline, update it every night, have your app build against it, smoketest deploys, and largely forget that patching exists.
There are a ton of security mechanisms that are enabled by the ecosystem itself, even if it does introduce new complexities and does have certain weaknesses against full hardware virtualization. It also has significant and meaningful security strengths (namely in availability via lower resource usage) against exclusively using hardware virtualization.
Completely disagree. How much experience/exposure do you have to kernel security that you say is crap?
> It uses Micro VMs rather than just kernel-level restrictions, so even a Linux kernel security bug shouldn't be able to jump out to the host or other containers/Firecrackers.
You realize that firecracker uses KVM, which is part of the "crap" kernel that you don't trust? A "Linux kernel security bug" could absolutely allow a Firecracker VM to jump to the host or other containers/Firecrackers.
The hypervisor isolates guest kernel bugs from the host by nature of strictly controlling resource use from the lowest level. There are of course hypervisor bugs that allow breakouts, but they are a couple orders of magnitude rarer than the typical Linux privesc bug.
Say what you want about kernel security, but most side channel attacks are statistically using syscalls which are highly unusual for a regular, hosted application to make. Using a combination of SecComp and LSM apps (SELinux/AppArmor) you can defend against most of these attacks.
You are right that containers alone are not sandboxes, but namespacing does help in terms of isolation. If you want to sacrifice performance for some further security you can use an application kernel, which further defends the host kernel. Additionally, you can try to sandbox with host and node level isolation for services, which refines the application syscall profile to be very consistent and predictable. Then if something unusual occurs on the host (like writing to disk) then you can take definitive action like shutting the host down. That's some of the principles Bottle rocket was written on, among others.
Microsoft ignores security reports related to container escape vulnerabilities because they don’t consider it to be a security boundary!
Every time there's a container escape or privilege escalation, it's treated as serious and patched. I look forward to the day when we can confidently say that containers are in fact a security boundary.
Good for you, seriously.
But that's not why people use containers. People use containers because they want to deploy random crap from the internet at the press of a button. I'd wager "rootless" is a bug, not a feature in this scenario.
Edit: Please tell me down voter how to do this with Docker..
Edit: Nothing in the article mentions Docker Swarm you sillies..
If you want to understand things at a deeper level, you have to cut through the cruft. You can put linux distributions into tar files and run them without Docker (see systemd-nspawn). You can use cgroups to run ordinary Linux binaries. You can make a group of processes run on a fake private network. You can build OCI-compliant container images without ever running a single thing in a container. Docker conflates all of this and confuses people. Don't be confused, realize that "Docker" does a lot.
Edit: Lol @ comments. ...could mean... I don't think anybody talks about orchestrating containers without meaning it includes scheduling and so on. What Kubernetes, Nomad, Service Fabric and so on does. The tools we use. We can include Docker Swarm for courtesy if you want...