-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable gvisor addon in minikube (#3399)
This PR adds the code for enabling gvisor in minikube. It adds the pod that will run when the addon is enabled, and the code for the image which will run when this happens. When gvisor is enabled, the pod will download runsc and the gvisor-containerd-shim. It will replace the containerd config.toml and restart containerd. When gvisor is disabled, the pod will be deleted by the addon manager. This will trigger a pre-stop hook which will revert the config.toml to it's original state and restart containerd.
- Loading branch information
Showing
19 changed files
with
786 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
Copyright 2018 The Kubernetes Authors All rights reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"log" | ||
"os" | ||
|
||
"k8s.io/minikube/pkg/gvisor" | ||
) | ||
|
||
func main() { | ||
if err := gvisor.Enable(); err != nil { | ||
log.Print(err) | ||
os.Exit(1) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
## gVisor Addon | ||
[gVisor](https://github.com/google/gvisor/blob/master/README.md), a sandboxed container runtime, allows users to securely run pods with untrusted workloads within Minikube. | ||
|
||
### Starting Minikube | ||
gVisor depends on the containerd runtime to run in Minikube. | ||
When starting minikube, specify the following flags, along with any additional desired flags: | ||
|
||
```shell | ||
$ minikube start --container-runtime=containerd \ | ||
--docker-opt containerd=/var/run/containerd/containerd.sock \ | ||
--network-plugin=cni | ||
``` | ||
|
||
### Enabling gVisor | ||
To enable this addon, simply run: | ||
|
||
``` | ||
$ minikube addons enable gvisor | ||
``` | ||
|
||
Within one minute, the addon manager should pick up the change and you should see the `gvisor` pod: | ||
|
||
``` | ||
$ kubectl get pod gvisor -n kube-system | ||
NAME READY STATUS RESTARTS AGE | ||
gvisor 1/1 Running 0 3m | ||
``` | ||
|
||
Once the pod has status `Running`, gVisor is enabled in Minikube. | ||
|
||
### Running pods in gVisor | ||
To run a pod in gVisor, add this annotation to the Kubernetes yaml: | ||
|
||
``` | ||
io.kubernetes.cri.untrusted-workload: "true" | ||
``` | ||
|
||
An example Pod is shown below: | ||
|
||
```yaml | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: nginx-untrusted | ||
annotations: | ||
io.kubernetes.cri.untrusted-workload: "true" | ||
spec: | ||
containers: | ||
- name: nginx | ||
image: nginx | ||
``` | ||
_Note: this annotation will not be necessary once the RuntimeClass Kubernetes feature is available broadly._ | ||
### Disabling gVisor | ||
To disable gVisor, run: | ||
``` | ||
$ minikube addons disable gvisor | ||
``` | ||
|
||
Within one minute, the addon manager should pick up the change. | ||
Once the `gvisor` pod has status `Terminating`, or has been deleted, the gvisor addon should be disabled. | ||
|
||
``` | ||
$ kubectl get pod gvisor -n kube-system | ||
NAME READY STATUS RESTARTS AGE | ||
gvisor 1/1 Terminating 0 5m | ||
``` | ||
|
||
_Note: Once gVisor is disabled, any pod with the `io.kubernetes.cri.untrusted-workload` annotation will fail with a FailedCreatePodSandBox error._ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
root = "/var/lib/containerd" | ||
state = "/run/containerd" | ||
oom_score = 0 | ||
|
||
[grpc] | ||
address = "/run/containerd/containerd.sock" | ||
uid = 0 | ||
gid = 0 | ||
max_recv_message_size = 16777216 | ||
max_send_message_size = 16777216 | ||
|
||
[debug] | ||
address = "" | ||
uid = 0 | ||
gid = 0 | ||
level = "" | ||
|
||
[metrics] | ||
address = "" | ||
grpc_histogram = false | ||
|
||
[cgroup] | ||
path = "" | ||
|
||
[plugins] | ||
[plugins.cgroups] | ||
no_prometheus = false | ||
[plugins.cri] | ||
stream_server_address = "" | ||
stream_server_port = "10010" | ||
enable_selinux = false | ||
sandbox_image = "k8s.gcr.io/pause:3.1" | ||
stats_collect_period = 10 | ||
systemd_cgroup = false | ||
enable_tls_streaming = false | ||
max_container_log_line_size = 16384 | ||
[plugins.cri.containerd] | ||
snapshotter = "overlayfs" | ||
no_pivot = true | ||
[plugins.cri.containerd.default_runtime] | ||
runtime_type = "io.containerd.runtime.v1.linux" | ||
runtime_engine = "" | ||
runtime_root = "" | ||
[plugins.cri.containerd.untrusted_workload_runtime] | ||
runtime_type = "io.containerd.runtime.v1.linux" | ||
runtime_engine = "/usr/local/bin/runsc" | ||
runtime_root = "/run/containerd/runsc" | ||
[plugins.cri.cni] | ||
bin_dir = "/opt/cni/bin" | ||
conf_dir = "/etc/cni/net.d" | ||
conf_template = "" | ||
[plugins.cri.registry] | ||
[plugins.cri.registry.mirrors] | ||
[plugins.cri.registry.mirrors."docker.io"] | ||
endpoint = ["https://registry-1.docker.io"] | ||
[plugins.diff-service] | ||
default = ["walking"] | ||
[plugins.linux] | ||
shim = "gvisor-containerd-shim" | ||
runtime = "runc" | ||
runtime_root = "" | ||
no_shim = false | ||
shim_debug = true | ||
[plugins.scheduler] | ||
pause_threshold = 0.02 | ||
deletion_threshold = 0 | ||
mutation_threshold = 100 | ||
schedule_delay = "0s" | ||
startup_delay = "100ms" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
runc_shim = "/bin/containerd-shim" | ||
[runsc_config] | ||
user-log="/tmp/runsc/user-log-%ID%.log" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# Copyright 2018 The Kubernetes Authors All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: gvisor | ||
namespace: kube-system | ||
labels: | ||
addonmanager.kubernetes.io/mode: Reconcile | ||
kubernetes.io/minikube-addons: gvisor | ||
spec: | ||
hostPID: true | ||
containers: | ||
- name: gvisor | ||
image: gcr.io/k8s-minikube/gvisor-addon:latest | ||
securityContext: | ||
privileged: true | ||
volumeMounts: | ||
- mountPath: /node/ | ||
name: node | ||
- mountPath: /usr/libexec/sudo | ||
name: sudo | ||
- mountPath: /var/run | ||
name: varrun | ||
- mountPath: /usr/bin | ||
name: usrbin | ||
- mountPath: /usr/lib | ||
name: usrlib | ||
- mountPath: /bin | ||
name: bin | ||
- mountPath: /tmp/gvisor | ||
name: gvisor | ||
env: | ||
- name: PATH | ||
value: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/node/bin | ||
- name: SYSTEMD_IGNORE_CHROOT | ||
value: "yes" | ||
volumes: | ||
- name: node | ||
hostPath: | ||
path: / | ||
- name: sudo | ||
hostPath: | ||
path: /usr/libexec/sudo | ||
- name: varrun | ||
hostPath: | ||
path: /var/run | ||
- name: usrlib | ||
hostPath: | ||
path: /usr/lib | ||
- name: usrbin | ||
hostPath: | ||
path: /usr/bin | ||
- name: bin | ||
hostPath: | ||
path: /bin | ||
- name: gvisor | ||
hostPath: | ||
path: /tmp/gvisor | ||
restartPolicy: Never |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Copyright 2016 The Kubernetes Authors All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
FROM ubuntu:18.04 | ||
RUN apt-get update && \ | ||
apt-get install -y kmod gcc wget xz-utils libc6-dev bc libelf-dev bison flex openssl libssl-dev libidn2-0 sudo libcap2 && \ | ||
rm -rf /var/lib/apt/lists/* | ||
COPY out/gvisor-addon /gvisor-addon | ||
CMD ["/gvisor-addon"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.