You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
1.6 KiB
Markdown

# Kubernetes up and Running
## Setting your kubeconfig
To make it easier on you copy your kube config file to the root of this project and name it kubeconfig.conf. Then just remember to run source `scripts/profile` to start using the kubectl command. I am just setting the KUBECONFIG envar to the kubeconfig.conf file for the bash session.
## Accessing a pod from your laptop
Portforwarding
```
kubectl port-forward <pod name> <port>:<pod_port>
```
## Basic logging
```
kubectl logs <pod name>
```
Stream logs with `-f`
```
kubectl logs -f <pod name>
```
To view logs from the previous pod. Useful if the pod instances keep restarting.
```
kubectl logs --previous <pod_name>
```
## Running commands in your container with exec
One off commands
```
kubectl exec <pod name> <cmd>
kubectl exec kuard date
```
Interactive sessions
```
kubectl exec -it <pod name> <cmd>
```
## Copying files to and from a running container
```
kubectl cp <pod name>:<path> <host path>
```
```
kubectl cp <host path> <pod name>:<path>
```
## Demo app
https://github.com/kubernetes-up-and-running/kuard
Here is an example of using the cgroups access to limit container resources to 200mb of ram and 1G of swap. If these resources are exceed, which you can test with the kuard application, the container will be terminated.
```
docker run -d --name kuard -p 8080:8080 --memory 200m --memory-swap 1G docker1.runcible.io:5151/kuard:latest
```
If we wanted to limit cpu you could use
```
docker run -d --name kuard -p 8080:8080 --memory 200m --memory-swap 1G --cpu-shares 1024 docker1.runcible.io:5151/kuard:latest
```