# Pod

## PODS

* is an abstraction of a server
  * can run multiple container within single namespace, exposed by single IP
* only started through Deployment

**Init** container is an additional container in POD that completes a task before the regular container is started.

```java
only if (init_container.started()) {
    regular_contaner.start();
}
```

### Jobs

kubectl create cronjob sleep-job --image=busybox --schedule"\*/2 \* \* \* \*" --dry-run -o yaml > job.yaml

### Namespace

Namespace implements kernel level resource isolation.\
Kubernetes supports multiple virtual clusters backed by the same physical cluster. These virtual clusters are called namespaces. Read more about namespaces at [Kubernetes reference](https://kubernetes.io/docs/user-guide/namespaces)

## Deployment

* replicas - how many copies
* strategy - how Pods should be updated
  * recreate - all pods killed and new created => temporary unavailability
  * :thumbsup: rollingUpdate
* selector - how labels are matched agains the Pod
* template - Pod specification to create it

```
kubectl run httpd-run --image=httpd --replicas
kubectl get deployments.apps [name]
kubectl get rs
kubectl scale deployments/[DEPLOYMENT_NAME] --replicas=4
```

### labels / selectors / annotations

* label -> key/value pair to identify K8s resource
* annotation is used to provide additional metadata in object (licenses, maintainer...)

:information\_source: :thumbsdown: kubectl label deployment \[name] \[key]=\[value]\
:information\_source: kubectl get deployments.apps --show-labels\
:information\_source: kubectl get deployments.apps --selector \[key]=\[value]

### History

kubectl rollout history deployment \[name]\
kubectl rollout undo deployment \[name] --to-revision=1

## Patterns

* Ambassador
* Adapter

![](https://415484505-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LxtoAXZwwOc4XGto8vb%2Fuploads%2FWorMZl8Uyf83DpXnChUk%2Fimage.png?alt=media\&token=357572c6-ccc8-4996-82a9-d1245c409e7b)

* Sidecar container
  * [Injecting secrets.](https://www.vaultproject.io/docs/platform/k8s/injector)
  * [Reloading ConfigMaps](https://github.com/jimmidyson/configmap-reload) when there's a change.
  * [Caching.](https://thenewstack.io/tutorial-apply-the-sidecar-pattern-to-deploy-redis-in-kubernetes/)
* Init container
