2017-08-29 00:19:25 +03:00
# Smoke Test
In this lab you will complete a series of tasks to ensure your Kubernetes cluster is functioning correctly.
## Data Encryption
In this section you will verify the ability to [encrypt secret data at rest ](https://kubernetes.io/docs/tasks/administer-cluster/encrypt-data/#verifying-that-data-is-encrypted ).
Create a generic secret:
```
kubectl create secret generic kubernetes-the-hard-way \
--from-literal="mykey=mydata"
```
Print a hexdump of the `kubernetes-the-hard-way` secret stored in etcd:
```
2019-03-20 07:34:49 +03:00
sudo ETCDCTL_API=3 etcdctl get \
2018-05-12 19:54:18 +03:00
--endpoints=https://127.0.0.1:2379 \
2019-03-20 07:34:49 +03:00
--cacert=/etc/etcd/ca.crt \
--cert=/etc/etcd/etcd-server.crt \
--key=/etc/etcd/etcd-server.key\
/registry/secrets/default/kubernetes-the-hard-way | hexdump -C
2017-08-29 00:19:25 +03:00
```
> output
```
00000000 2f 72 65 67 69 73 74 72 79 2f 73 65 63 72 65 74 |/registry/secret|
00000010 73 2f 64 65 66 61 75 6c 74 2f 6b 75 62 65 72 6e |s/default/kubern|
00000020 65 74 65 73 2d 74 68 65 2d 68 61 72 64 2d 77 61 |etes-the-hard-wa|
00000030 79 0a 6b 38 73 3a 65 6e 63 3a 61 65 73 63 62 63 |y.k8s:enc:aescbc|
2019-03-20 07:34:49 +03:00
00000040 3a 76 31 3a 6b 65 79 31 3a 78 cd 3c 33 3a 60 d7 |:v1:key1:x.< 3: ` . |
00000050 4c 1e 4c f1 97 ce 75 6f 3d a7 f1 4b 59 e8 f9 2a |L.L...uo=..KY..*|
00000060 17 77 20 14 ab 73 85 63 12 12 a4 8d 3c 6e 04 4c |.w ..s.c....< n.L |
00000070 e0 84 6f 10 7b 3a 13 10 d0 cd df 81 d0 08 be fa |..o.{:..........|
00000080 ea 74 ca 53 b3 b2 90 95 e1 ba bc 3f 88 76 db 8e |.t.S.......?.v..|
00000090 e1 1e 17 ea 0d b0 3b e3 e3 df eb 2e 57 76 1d d0 |......;.....Wv..|
000000a0 25 ca ee 5b f2 27 c7 f2 8e 58 93 e9 28 45 8f 3a |%..[.'...X..(E.:|
000000b0 e7 97 bf 74 86 72 fd e7 f1 bb fc f7 2d 10 4d c3 |...t.r......-.M.|
000000c0 70 1d 08 75 c3 7c 14 55 18 9d 68 73 ec e3 41 3a |p..u.|.U..hs..A:|
000000d0 dc 41 8a 4b 9e 33 d9 3d c0 04 60 10 cf ad a4 88 |.A.K.3.=..`.....|
000000e0 7b e7 93 3f 7a e8 1b 22 bf 0a |{..?z.."..|
2017-12-18 17:53:32 +03:00
000000ea
2017-08-29 00:19:25 +03:00
```
The etcd key should be prefixed with `k8s:enc:aescbc:v1:key1` , which indicates the `aescbc` provider was used to encrypt the data with the `key1` encryption key.
2019-03-20 07:34:49 +03:00
Cleanup:
`kubectl delete secret kubernetes-the-hard-way`
2017-08-29 00:19:25 +03:00
## Deployments
In this section you will verify the ability to create and manage [Deployments ](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/ ).
Create a deployment for the [nginx ](https://nginx.org/en/ ) web server:
```
2019-03-20 13:12:49 +03:00
kubectl create deployment nginx --image=nginx
2017-08-29 00:19:25 +03:00
```
List the pod created by the `nginx` deployment:
```
2019-03-20 13:12:49 +03:00
kubectl get pods -l app=nginx
2017-08-29 00:19:25 +03:00
```
> output
```
2018-09-30 22:35:05 +03:00
NAME READY STATUS RESTARTS AGE
nginx-dbddb74b8-6lxg2 1/1 Running 0 10s
2017-08-29 00:19:25 +03:00
```
2019-03-20 13:12:49 +03:00
### Services
2017-08-29 00:19:25 +03:00
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/ ).
2019-03-20 13:12:49 +03:00
Create a service to expose deployment nginx on node ports.
2017-08-29 00:19:25 +03:00
```
2019-03-20 13:12:49 +03:00
kubectl expose deploy nginx --type=NodePort --port 80
2017-08-29 00:19:25 +03:00
```
```
2019-03-20 13:12:49 +03:00
PORT_NUMBER=$(kubectl get svc -l app=nginx -o jsonpath="{.items[0].spec.ports[0].nodePort}")
2017-08-29 00:19:25 +03:00
```
2019-03-20 13:12:49 +03:00
Test to view NGINX page
2017-08-29 00:19:25 +03:00
```
2019-03-20 13:12:49 +03:00
curl http://worker-1:$PORT_NUMBER
curl http://worker-2:$PORT_NUMBER
2017-08-29 00:19:25 +03:00
```
2019-03-20 13:12:49 +03:00
> output
2017-08-29 00:19:25 +03:00
```
2019-03-20 13:12:49 +03:00
<!DOCTYPE html>
< html >
< head >
< title > Welcome to nginx!< / title >
# Output Truncated for brevity
< body >
2017-08-29 00:19:25 +03:00
```
2019-03-20 13:12:49 +03:00
### Logs
2017-08-29 00:19:25 +03:00
2019-03-20 13:12:49 +03:00
In this section you will verify the ability to [retrieve container logs ](https://kubernetes.io/docs/concepts/cluster-administration/logging/ ).
2017-08-29 00:19:25 +03:00
2019-03-20 13:12:49 +03:00
Retrieve the full name of the `nginx` pod:
2017-08-29 00:19:25 +03:00
```
2019-03-20 13:12:49 +03:00
POD_NAME=$(kubectl get pods -l app=nginx -o jsonpath="{.items[0].metadata.name}")
2017-08-29 00:19:25 +03:00
```
Print the `nginx` pod logs:
```
kubectl logs $POD_NAME
```
> output
```
2019-03-20 13:12:49 +03:00
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" "-"
2017-08-29 00:19:25 +03:00
```
### Exec
In this section you will verify the ability to [execute commands in a container ](https://kubernetes.io/docs/tasks/debug-application-cluster/get-shell-running-container/#running-individual-commands-in-a-container ).
Print the nginx version by executing the `nginx -v` command in the `nginx` container:
```
kubectl exec -ti $POD_NAME -- nginx -v
```
> output
```
2019-03-20 13:12:49 +03:00
nginx version: nginx/1.15.9
2018-05-12 19:54:18 +03:00
```
2019-03-20 13:12:49 +03:00
Next: [End to End Tests ](16-e2e-test.md )