1
1
# How to use Kata Containers and CRI (containerd plugin) with Kubernetes
2
2
3
- This document describes how to set up a single-machine Kubernetes cluster.
4
- The Kubernetes cluster will use the CRI containerd plugin and Kata Containers to launch untrusted workloads.
3
+ * [ Requirements] ( #requirements )
4
+ * [ Install containerd with CRI plugin enabled] ( #install-containerd-with-cri-plugin-enabled )
5
+ * [ Install Kata Containers] ( #install-kata-containers )
6
+ * [ Install Kubernetes] ( #install-kubernetes )
7
+ * [ Configure containerd to use Kata Containers] ( #configure-containerd-to-use-kata-containers )
8
+ * [ Define the Kata runtime as the untrusted workload runtime] ( #define-the-kata-runtime-as-the-untrusted-workload-runtime )
9
+ * [ Configure Kubelet to use containerd] ( #configure-kubelet-to-use-containerd )
10
+ * [ Configure proxy - OPTIONAL] ( #configure-proxy---optional )
11
+ * [ Start Kubernetes] ( #start-kubernetes )
12
+ * [ Install a Pod Network] ( #install-a-pod-network )
13
+ * [ Allow pods to run in the master node] ( #allow-pods-to-run-in-the-master-node )
14
+ * [ Create an unstrusted pod using Kata Containers] ( #create-an-unstrusted-pod-using-kata-containers )
15
+ * [ Delete created pod] ( #delete-created-pod )
16
+
17
+ This document describes how to set up a single-machine Kubernetes (k8s) cluster.
18
+
19
+ The Kubernetes cluster will use the
20
+ [ CRI containerd plugin] ( https://github.com/containerd/cri ) and
21
+ [ Kata Containers] ( https://katacontainers.io ) to launch untrusted workloads.
22
+
23
+ ## Requirements
5
24
6
- ## Requirements
7
25
- Kubernetes, kubelet, kubeadm
8
26
- cri-containerd
9
27
- Kata Containers
10
28
11
- For information about the supported version of these components see
12
- Kata Containers [ versions.yaml] ( https://github.com/kata-containers/runtime/blob/master/versions.yaml ) file.
29
+ ** Note:** For information about the supported versions of these components,
30
+ see the Kata Containers
31
+ [ versions.yaml] ( https://github.com/kata-containers/runtime/blob/master/versions.yaml )
32
+ file.
13
33
14
- ## Install containerd( with CRI plugin enabled)
34
+ ## Install containerd with CRI plugin enabled
15
35
16
- Follow the instructions from [ CRI installation guide] ( http://github.com/containerd/cri/blob/master/docs/installation.md )
36
+ - Follow the instructions from the
37
+ [ CRI installation guide] ( http://github.com/containerd/cri/blob/master/docs/installation.md ) .
17
38
18
- <!-- -
19
- ```bash
20
- # Check if containerd is installed
21
- $ command -v containerd
22
- ```
23
- --->
24
-
25
- ## Install Kata Containers
39
+ - Check if ` containerd ` is now available
40
+ ``` bash
41
+ $ command -v containerd
42
+ ```
26
43
27
- Follow the instructions to [ install Kata] ( https://github.com/kata-containers/documentation/blob/master/install/README.md ) .
44
+ ## Install Kata Containers
28
45
29
- <!-- -
30
- ```bash
31
- # Check if kata-runtime is installed
32
- $ command -v kata-runtime
33
- # Check kata is well configured
34
- $ kata-runtime kata-env
35
- ```
36
- --->
46
+ Follow the instructions to
47
+ [ install Kata Containers] ( https://github.com/kata-containers/documentation/blob/master/install/README.md ) .
37
48
38
49
## Install Kubernetes
39
- Install Kubernetes in your host. See kubeadm [ installation] ( https://kubernetes.io/docs/tasks/tools/install-kubeadm/ )
40
- <!-- -
41
- ```bash
42
- # Check if kubadm is installed
43
- $ command -v kubeadm
44
- ```
45
- --->
46
50
47
- ### Configure containerd to use Kata Containers
51
+ - Follow the instructions for
52
+ [ kubeadm installation] ( https://kubernetes.io/docs/setup/independent/install-kubeadm/ ) .
53
+
54
+ - Check ` kubeadm ` is now available
55
+
56
+ ``` bash
57
+ $ command -v kubeadm
58
+ ```
59
+
60
+ ## Configure containerd to use Kata Containers
61
+
62
+ The CRI ` containerd ` plugin supports configuration for two runtime types.
48
63
49
- The CRI containerd plugin support configuration for two runtime types.
64
+ - ** Default runtime: **
50
65
51
- - Default runtime: A runtime that is used by default to run workloads.
52
- - Untrusted workload runtime: A runtime that will be used run untrusted workloads.
66
+ A runtime that is used by default to run workloads.
53
67
54
- #### Define the Kata runtime as ` untrusted_workload_runtime `
68
+ - ** Untrusted workload runtime: **
55
69
56
- Configure the Kata runtime for untrusted workload with the [ config option] ( https://github.com/containerd/cri/blob/v1.0.0-rc.0/docs/config.md )
57
- ` plugins.cri.containerd.untrusted_workload_runtime ` .
70
+ A runtime that will be used to run untrusted workloads. This is appropriate
71
+ for workloads that require a higher degree of security isolation.
72
+
73
+ #### Define the Kata runtime as the untrusted workload runtime
74
+
75
+ Configure ` containerd ` to use the Kata runtime to run untrusted workloads by
76
+ setting the ` plugins.cri.containerd.untrusted_workload_runtime `
77
+ [ config option] ( https://github.com/containerd/cri/blob/v1.0.0-rc.0/docs/config.md ) :
58
78
59
- Unless configured otherwise, the default runtime is set to ` runc ` .
60
79
``` bash
61
- # Configure containerd to use Kata as untrusted_workload_runtime
62
80
$ sudo mkdir -p /etc/containerd/
63
81
$ cat << EOT | sudo tee /etc/containerd/config.toml
64
82
[plugins]
@@ -69,28 +87,33 @@ $ cat << EOT | sudo tee /etc/containerd/config.toml
69
87
EOT
70
88
```
71
89
72
- ### Configure Kubelet to use containerd
90
+ ** Note: ** Unless configured otherwise, the default runtime is set to ` runc ` .
73
91
74
- In order to allow kubelet use containerd (using CRI interface) configure the service to
75
- point to containerd socket.
92
+ ## Configure Kubelet to use containerd
76
93
77
- ``` bash
78
- # Configure k8s to use containerd
79
- $ sudo mkdir -p /etc/systemd/system/kubelet.service.d/
80
- $ cat << EOF | sudo tee /etc/systemd/system/kubelet.service.d/0-containerd.conf
81
- [Service]
82
- Environment="KUBELET_EXTRA_ARGS=--container-runtime=remote --runtime-request-timeout=15m --container-runtime-endpoint=unix:///run/containerd/containerd.sock"
83
- EOF
84
- $ sudo systemctl daemon-reload
85
- ```
94
+ In order to allow kubelet to use containerd (using the CRI interface), configure the service to point to the ` containerd ` socket.
86
95
87
- ### Optional: Configure proxy
96
+ - Configure Kubernetes to use ` containerd `
88
97
89
- If you are behind a proxy this script will configure your proxy for docker
90
- kubelet and containerd.
98
+ ``` bash
99
+ $ sudo mkdir -p /etc/systemd/system/kubelet.service.d/
100
+ $ cat << EOF | sudo tee /etc/systemd/system/kubelet.service.d/0-containerd.conf
101
+ [Service]
102
+ Environment="KUBELET_EXTRA_ARGS=--container-runtime=remote --runtime-request-timeout=15m --container-runtime-endpoint=unix:///run/containerd/containerd.sock"
103
+ EOF
104
+ ` ` `
105
+
106
+ - Inform systemd about the new configuration
107
+
108
+ ` ` ` bash
109
+ $ sudo systemctl daemon-reload
110
+ ` ` `
111
+
112
+ # # Configure proxy - OPTIONAL
113
+
114
+ If you are behind a proxy, use the following script to configure your proxy for docker, kubelet, and containerd:
91
115
92
116
` ` ` bash
93
- # Set proxys
94
117
$ services=(
95
118
'kubelet'
96
119
'containerd'
@@ -99,115 +122,134 @@ $ services=(
99
122
100
123
$ for s in "${services[@]} "; do
101
124
102
- service_dir=" /etc/systemd/system/${s} .service.d/"
103
- sudo mkdir -p ${service_dir}
125
+ service_dir="/etc/systemd/system/${s} .service.d/"
126
+ sudo mkdir -p ${service_dir}
104
127
105
- cat << EOT | sudo tee "${service_dir} /proxy.conf"
128
+ cat << EOT | sudo tee "${service_dir} /proxy.conf"
106
129
[Service]
107
130
Environment="HTTP_PROXY=${http_proxy} "
108
131
Environment="HTTPS_PROXY=${https_proxy} "
109
132
Environment="NO_PROXY=${no_proxy} "
110
133
EOT
111
134
done
135
+
112
136
$ sudo systemctl daemon-reload
113
137
` ` `
114
138
115
- ### Start Kubernetes with kubeadm
139
+ # # Start Kubernetes
116
140
117
- ``` bash
118
- # Mark sure containerd is up and running
119
- $ sudo systemctl restart containerd
120
- $ sudo systemctl status containerd
141
+ - Make sure ` containerd` is up and running
121
142
122
- # Prevent docker iptables rules conflict with k8s pod communication
123
- $ sudo iptables -P FORWARD ACCEPT
143
+ ` ` ` bash
144
+ $ sudo systemctl restart containerd
145
+ $ sudo systemctl status containerd
146
+ ` ` `
124
147
125
- # Start cluster using kubeadm
126
- $ sudo kubeadm init --skip-preflight-checks \
127
- --cri-socket /run/containerd/containerd.sock --pod-network-cidr=10.244.0.0/16
148
+ - Prevent conflicts between ` docker` iptables (packet filtering) rules and k8s pod communication
128
149
129
- $ export KUBECONFIG=/etc/kubernetes/admin.conf
150
+ ` ` ` bash
151
+ $ sudo iptables -P FORWARD ACCEPT
152
+ ` ` `
130
153
131
- $ sudo -E kubectl get nodes
132
- $ sudo -E kubectl get pods
133
- ```
154
+ - Start cluster using ` kubeadm`
134
155
135
- ### Install a pod network
136
- Install a pod network plugin is needed to allow pods communicate with each other.
156
+ ` ` ` bash
157
+ $ sudo kubeadm init --skip-preflight-checks --cri-socket /run/containerd/containerd.sock --pod-network-cidr=10.244.0.0/16
137
158
138
- Install flannel plugging, by following the instructions in the section * Installing a pod network*
139
- from [ Using kubeadm to Create a Cluster ] ( https://kubernetes.io/docs/setup/independent/create-cluster-kubeadm/ )
140
- guide.
159
+ $ export KUBECONFIG=/etc/kubernetes/admin.conf
141
160
142
- <!-- -
143
- ```bash
144
- # Install a pod network using flannel
145
- # There is not a programmatic way to know last what flannel commit use
146
- # See https://github.com/coreos/flannel/issues/995
147
- $ sudo -E kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
148
- ```
149
- --->
161
+ $ sudo -E kubectl get nodes
162
+ $ sudo -E kubectl get pods
163
+ ` ` `
150
164
165
+ # # Install a Pod Network
151
166
152
- ``` bash
153
- # wait for pod network
154
- $ timeout_dns=0
155
- $ until [ " $timeout_dns " -eq " 420" ]; do
156
- if sudo -E kubectl get pods --all-namespaces | grep dns | grep Running; then
157
- break
158
- fi
159
- sleep 1s
160
- (( timeout_dns+= 1 ))
161
- done
162
-
163
- # check pod network is running
164
- $ sudo -E kubectl get pods --all-namespaces | grep dns | grep Running && echo " OK" || ( echo " FAIL" && false )
165
- ```
167
+ A pod network plugin is needed to allow pods to communicate with each other.
166
168
167
- ### Allow run pods in master node
169
+ - Install the ` flannel` plugin by following the
170
+ [Using kubeadm to Create a Cluster](https://kubernetes.io/docs/setup/independent/create-cluster-kubeadm/# instructions)
171
+ guide, starting from the ** Installing a pod network** section.
168
172
169
- By default, the cluster will not schedule pods in the master node to allow that run:
173
+ - Create a pod network using flannel
170
174
171
- ``` bash
172
- # allow master node run pods
173
- $ sudo -E kubectl taint nodes --all node-role.kubernetes.io/master-
174
- ```
175
+ ** Note:** There is not a programmatic way to know last what flannel commit use. See https://github.com/coreos/flannel/issues/995.
175
176
177
+ ` ` ` bash
178
+ $ sudo -E kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
179
+ ` ` `
176
180
177
- ### Create a unstrusted pod using Kata Containers
181
+ - Wait for the pod network to become available
178
182
179
- By default, all pods are created with the default runtime configured in CRI containerd plugin.
180
- If a pod has the ` io.kubernetes.cri.untrusted-workload annotation ` set as
181
- ` "true" ` , the CRI plugin will run the pod with the Kata Containers runtime.
183
+ ` ` ` bash
184
+ # number of seconds to wait for pod network to become available
185
+ $ timeout_dns=420
182
186
183
- ``` bash
184
- # Create untrusted pod configuration
185
- $ cat << EOT | tee nginx-untrusted.yaml
186
- apiVersion: v1
187
- kind: Pod
188
- metadata:
189
- name: nginx-untrusted
190
- annotations:
191
- io.kubernetes.cri.untrusted-workload: "true"
192
- spec:
193
- containers:
194
- - name: nginx
195
- image: nginx
196
-
197
- EOT
187
+ $ while [ " $timeout_dns " -gt 0 ]; do
188
+ if sudo -E kubectl get pods --all-namespaces | grep dns | grep Running; then
189
+ break
190
+ fi
191
+
192
+ sleep 1s
193
+ (( timeout_dns-= 1 ))
194
+ done
195
+ ` ` `
198
196
199
- # Create untrusted pod
200
- $ sudo -E kubectl apply -f nginx-untrusted.yaml
197
+ - Check the pod network is running
198
+ ` ` ` bash
199
+ $ sudo -E kubectl get pods --all-namespaces | grep dns | grep Running && echo " OK" || ( echo " FAIL" && false )
200
+ ` ` `
201
201
202
- # Check pod is running
203
- $ sudo -E kubectl get pods
202
+ # # Allow pods to run in the master node
204
203
205
- # Check qemu is running
206
- $ ps aux | grep qemu
204
+ By default, the cluster will not schedule pods in the master node. To enable master node scheduling:
205
+
206
+ ` ` ` bash
207
+ $ sudo -E kubectl taint nodes --all node-role.kubernetes.io/master-
207
208
` ` `
208
- ### Delete created pod
209
+
210
+ # # Create an unstrusted pod using Kata Containers
211
+
212
+ By default, all pods are created with the default runtime configured in CRI containerd plugin.
213
+
214
+ If a pod has the ` io.kubernetes.cri.untrusted-workload` annotation set to ` " true" ` , the CRI plugin runs the pod with the
215
+ [Kata Containers runtime](https://github.com/kata-containers/runtime/blob/master/README.md).
216
+
217
+ - Create an untrusted pod configuration
218
+
219
+ ` ` ` bash
220
+ $ cat << EOT | tee nginx-untrusted.yaml
221
+ apiVersion: v1
222
+ kind: Pod
223
+ metadata:
224
+ name: nginx-untrusted
225
+ annotations:
226
+ io.kubernetes.cri.untrusted-workload: "true"
227
+ spec:
228
+ containers:
229
+ - name: nginx
230
+ image: nginx
231
+
232
+ EOT
233
+ ` ` `
234
+
235
+ - Create an untrusted pod
236
+ ` ` ` bash
237
+ $ sudo -E kubectl apply -f nginx-untrusted.yaml
238
+ ` ` `
239
+
240
+ - Check pod is running
241
+
242
+ ` ` ` bash
243
+ $ sudo -E kubectl get pods
244
+ ` ` `
245
+
246
+ - Check hypervisor is running
247
+ ` ` ` bash
248
+ $ ps aux | grep qemu
249
+ ` ` `
250
+
251
+ # # Delete created pod
209
252
210
253
` ` ` bash
211
- # Delete pod
212
- $ sudo -E kubectl delete -f nginx-untrusted.yaml
254
+ $ sudo -E kubectl delete -f nginx-untrusted.yaml
213
255
` ` `
0 commit comments