|
|
|
@ -57,13 +57,13 @@ In this section you will verify the ability to create and manage [Deployments](h
|
|
|
|
|
Create a deployment for the [nginx](https://nginx.org/en/) web server:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
kubectl run nginx --image=nginx
|
|
|
|
|
kubectl create deployment nginx --image=nginx
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
List the pod created by the `nginx` deployment:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
kubectl get pods -l run=nginx
|
|
|
|
|
kubectl get pods -l app=nginx
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
> output
|
|
|
|
@ -73,62 +73,49 @@ NAME READY STATUS RESTARTS AGE
|
|
|
|
|
nginx-dbddb74b8-6lxg2 1/1 Running 0 10s
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### Port Forwarding
|
|
|
|
|
### Services
|
|
|
|
|
|
|
|
|
|
In this section you will verify the ability to access applications remotely using [port forwarding](https://kubernetes.io/docs/tasks/access-application-cluster/port-forward-access-application-cluster/).
|
|
|
|
|
|
|
|
|
|
Retrieve the full name of the `nginx` pod:
|
|
|
|
|
Create a service to expose deployment nginx on node ports.
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
POD_NAME=$(kubectl get pods -l run=nginx -o jsonpath="{.items[0].metadata.name}")
|
|
|
|
|
kubectl expose deploy nginx --type=NodePort --port 80
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Forward port `8080` on your local machine to port `80` of the `nginx` pod:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
kubectl port-forward $POD_NAME 8080:80
|
|
|
|
|
PORT_NUMBER=$(kubectl get svc -l app=nginx -o jsonpath="{.items[0].spec.ports[0].nodePort}")
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Test to view NGINX page
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
curl http://worker-1:$PORT_NUMBER
|
|
|
|
|
curl http://worker-2:$PORT_NUMBER
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
> output
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
Forwarding from 127.0.0.1:8080 -> 80
|
|
|
|
|
Forwarding from [::1]:8080 -> 80
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
In a new terminal make an HTTP request using the forwarding address:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
curl --head http://127.0.0.1:8080
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
> output
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
HTTP/1.1 200 OK
|
|
|
|
|
Server: nginx/1.15.4
|
|
|
|
|
Date: Sun, 30 Sep 2018 19:23:10 GMT
|
|
|
|
|
Content-Type: text/html
|
|
|
|
|
Content-Length: 612
|
|
|
|
|
Last-Modified: Tue, 25 Sep 2018 15:04:03 GMT
|
|
|
|
|
Connection: keep-alive
|
|
|
|
|
ETag: "5baa4e63-264"
|
|
|
|
|
Accept-Ranges: bytes
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Switch back to the previous terminal and stop the port forwarding to the `nginx` pod:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
Forwarding from 127.0.0.1:8080 -> 80
|
|
|
|
|
Forwarding from [::1]:8080 -> 80
|
|
|
|
|
Handling connection for 8080
|
|
|
|
|
^C
|
|
|
|
|
<!DOCTYPE html>
|
|
|
|
|
<html>
|
|
|
|
|
<head>
|
|
|
|
|
<title>Welcome to nginx!</title>
|
|
|
|
|
# Output Truncated for brevity
|
|
|
|
|
<body>
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### Logs
|
|
|
|
|
|
|
|
|
|
In this section you will verify the ability to [retrieve container logs](https://kubernetes.io/docs/concepts/cluster-administration/logging/).
|
|
|
|
|
|
|
|
|
|
Retrieve the full name of the `nginx` pod:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
POD_NAME=$(kubectl get pods -l app=nginx -o jsonpath="{.items[0].metadata.name}")
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Print the `nginx` pod logs:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
@ -138,7 +125,8 @@ kubectl logs $POD_NAME
|
|
|
|
|
> output
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
127.0.0.1 - - [30/Sep/2018:19:23:10 +0000] "HEAD / HTTP/1.1" 200 0 "-" "curl/7.58.0" "-"
|
|
|
|
|
10.32.0.1 - - [20/Mar/2019:10:08:30 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.58.0" "-"
|
|
|
|
|
10.40.0.0 - - [20/Mar/2019:10:08:55 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.58.0" "-"
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### Exec
|
|
|
|
@ -154,175 +142,7 @@ kubectl exec -ti $POD_NAME -- nginx -v
|
|
|
|
|
> output
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
nginx version: nginx/1.15.4
|
|
|
|
|
nginx version: nginx/1.15.9
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Services
|
|
|
|
|
|
|
|
|
|
In this section you will verify the ability to expose applications using a [Service](https://kubernetes.io/docs/concepts/services-networking/service/).
|
|
|
|
|
|
|
|
|
|
Expose the `nginx` deployment using a [NodePort](https://kubernetes.io/docs/concepts/services-networking/service/#type-nodeport) service:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
kubectl expose deployment nginx --port 80 --type NodePort
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
> The LoadBalancer service type can not be used because your cluster is not configured with [cloud provider integration](https://kubernetes.io/docs/getting-started-guides/scratch/#cloud-provider). Setting up cloud provider integration is out of scope for this tutorial.
|
|
|
|
|
|
|
|
|
|
Retrieve the node port assigned to the `nginx` service:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
NODE_PORT=$(kubectl get svc nginx \
|
|
|
|
|
--output=jsonpath='{range .spec.ports[0]}{.nodePort}')
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Create a firewall rule that allows remote access to the `nginx` node port:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
gcloud compute firewall-rules create kubernetes-the-hard-way-allow-nginx-service \
|
|
|
|
|
--allow=tcp:${NODE_PORT} \
|
|
|
|
|
--network kubernetes-the-hard-way
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Retrieve the external IP address of a worker instance:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
EXTERNAL_IP=$(gcloud compute instances describe worker-0 \
|
|
|
|
|
--format 'value(networkInterfaces[0].accessConfigs[0].natIP)')
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Make an HTTP request using the external IP address and the `nginx` node port:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
curl -I http://${EXTERNAL_IP}:${NODE_PORT}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
> output
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
HTTP/1.1 200 OK
|
|
|
|
|
Server: nginx/1.15.4
|
|
|
|
|
Date: Sun, 30 Sep 2018 19:25:40 GMT
|
|
|
|
|
Content-Type: text/html
|
|
|
|
|
Content-Length: 612
|
|
|
|
|
Last-Modified: Tue, 25 Sep 2018 15:04:03 GMT
|
|
|
|
|
Connection: keep-alive
|
|
|
|
|
ETag: "5baa4e63-264"
|
|
|
|
|
Accept-Ranges: bytes
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Untrusted Workloads
|
|
|
|
|
|
|
|
|
|
This section will verify the ability to run untrusted workloads using [gVisor](https://github.com/google/gvisor).
|
|
|
|
|
|
|
|
|
|
Create the `untrusted` pod:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
cat <<EOF | kubectl apply -f -
|
|
|
|
|
apiVersion: v1
|
|
|
|
|
kind: Pod
|
|
|
|
|
metadata:
|
|
|
|
|
name: untrusted
|
|
|
|
|
annotations:
|
|
|
|
|
io.kubernetes.cri.untrusted-workload: "true"
|
|
|
|
|
spec:
|
|
|
|
|
containers:
|
|
|
|
|
- name: webserver
|
|
|
|
|
image: gcr.io/hightowerlabs/helloworld:2.0.0
|
|
|
|
|
EOF
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### Verification
|
|
|
|
|
|
|
|
|
|
In this section you will verify the `untrusted` pod is running under gVisor (runsc) by inspecting the assigned worker node.
|
|
|
|
|
|
|
|
|
|
Verify the `untrusted` pod is running:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
kubectl get pods -o wide
|
|
|
|
|
```
|
|
|
|
|
```
|
|
|
|
|
NAME READY STATUS RESTARTS AGE IP NODE
|
|
|
|
|
busybox-68654f944b-djjjb 1/1 Running 0 5m 10.200.0.2 worker-0
|
|
|
|
|
nginx-65899c769f-xkfcn 1/1 Running 0 4m 10.200.1.2 worker-1
|
|
|
|
|
untrusted 1/1 Running 0 10s 10.200.0.3 worker-0
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Get the node name where the `untrusted` pod is running:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
INSTANCE_NAME=$(kubectl get pod untrusted --output=jsonpath='{.spec.nodeName}')
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
SSH into the worker node:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
gcloud compute ssh ${INSTANCE_NAME}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
List the containers running under gVisor:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
sudo runsc --root /run/containerd/runsc/k8s.io list
|
|
|
|
|
```
|
|
|
|
|
```
|
|
|
|
|
I0930 19:27:13.255142 20832 x:0] ***************************
|
|
|
|
|
I0930 19:27:13.255326 20832 x:0] Args: [runsc --root /run/containerd/runsc/k8s.io list]
|
|
|
|
|
I0930 19:27:13.255386 20832 x:0] Git Revision: 50c283b9f56bb7200938d9e207355f05f79f0d17
|
|
|
|
|
I0930 19:27:13.255429 20832 x:0] PID: 20832
|
|
|
|
|
I0930 19:27:13.255472 20832 x:0] UID: 0, GID: 0
|
|
|
|
|
I0930 19:27:13.255591 20832 x:0] Configuration:
|
|
|
|
|
I0930 19:27:13.255654 20832 x:0] RootDir: /run/containerd/runsc/k8s.io
|
|
|
|
|
I0930 19:27:13.255781 20832 x:0] Platform: ptrace
|
|
|
|
|
I0930 19:27:13.255893 20832 x:0] FileAccess: exclusive, overlay: false
|
|
|
|
|
I0930 19:27:13.256004 20832 x:0] Network: sandbox, logging: false
|
|
|
|
|
I0930 19:27:13.256128 20832 x:0] Strace: false, max size: 1024, syscalls: []
|
|
|
|
|
I0930 19:27:13.256238 20832 x:0] ***************************
|
|
|
|
|
ID PID STATUS BUNDLE CREATED OWNER
|
|
|
|
|
79e74d0cec52a1ff4bc2c9b0bb9662f73ea918959c08bca5bcf07ddb6cb0e1fd 20449 running /run/containerd/io.containerd.runtime.v1.linux/k8s.io/79e74d0cec52a1ff4bc2c9b0bb9662f73ea918959c08bca5bcf07ddb6cb0e1fd 0001-01-01T00:00:00Z
|
|
|
|
|
af7470029008a4520b5db9fb5b358c65d64c9f748fae050afb6eaf014a59fea5 20510 running /run/containerd/io.containerd.runtime.v1.linux/k8s.io/af7470029008a4520b5db9fb5b358c65d64c9f748fae050afb6eaf014a59fea5 0001-01-01T00:00:00Z
|
|
|
|
|
I0930 19:27:13.259733 20832 x:0] Exiting with status: 0
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Get the ID of the `untrusted` pod:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
POD_ID=$(sudo crictl -r unix:///var/run/containerd/containerd.sock \
|
|
|
|
|
pods --name untrusted -q)
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Get the ID of the `webserver` container running in the `untrusted` pod:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
CONTAINER_ID=$(sudo crictl -r unix:///var/run/containerd/containerd.sock \
|
|
|
|
|
ps -p ${POD_ID} -q)
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Use the gVisor `runsc` command to display the processes running inside the `webserver` container:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
sudo runsc --root /run/containerd/runsc/k8s.io ps ${CONTAINER_ID}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
> output
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
I0930 19:31:31.419765 21217 x:0] ***************************
|
|
|
|
|
I0930 19:31:31.419907 21217 x:0] Args: [runsc --root /run/containerd/runsc/k8s.io ps af7470029008a4520b5db9fb5b358c65d64c9f748fae050afb6eaf014a59fea5]
|
|
|
|
|
I0930 19:31:31.419959 21217 x:0] Git Revision: 50c283b9f56bb7200938d9e207355f05f79f0d17
|
|
|
|
|
I0930 19:31:31.420000 21217 x:0] PID: 21217
|
|
|
|
|
I0930 19:31:31.420041 21217 x:0] UID: 0, GID: 0
|
|
|
|
|
I0930 19:31:31.420081 21217 x:0] Configuration:
|
|
|
|
|
I0930 19:31:31.420115 21217 x:0] RootDir: /run/containerd/runsc/k8s.io
|
|
|
|
|
I0930 19:31:31.420188 21217 x:0] Platform: ptrace
|
|
|
|
|
I0930 19:31:31.420266 21217 x:0] FileAccess: exclusive, overlay: false
|
|
|
|
|
I0930 19:31:31.420424 21217 x:0] Network: sandbox, logging: false
|
|
|
|
|
I0930 19:31:31.420515 21217 x:0] Strace: false, max size: 1024, syscalls: []
|
|
|
|
|
I0930 19:31:31.420676 21217 x:0] ***************************
|
|
|
|
|
UID PID PPID C STIME TIME CMD
|
|
|
|
|
0 1 0 0 19:26 10ms app
|
|
|
|
|
I0930 19:31:31.422022 21217 x:0] Exiting with status: 0
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Next: [Cleaning Up](14-cleanup.md)
|
|
|
|
|
Next: [End to End Tests](16-e2e-test.md)
|
|
|
|
|