Skip to content

Commit

Permalink
Add cronjobs and YAML catch up instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
jpetazzo committed Nov 2, 2019
1 parent c9bc417 commit 7444f8d
Show file tree
Hide file tree
Showing 6 changed files with 337 additions and 15 deletions.
160 changes: 160 additions & 0 deletions k8s/dockercoins.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: hasher
name: hasher
spec:
replicas: 1
selector:
matchLabels:
app: hasher
template:
metadata:
labels:
app: hasher
spec:
containers:
- image: dockercoins/hasher:v0.1
name: hasher
---
apiVersion: v1
kind: Service
metadata:
labels:
app: hasher
name: hasher
spec:
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
app: hasher
type: ClusterIP
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: redis
name: redis
spec:
replicas: 1
selector:
matchLabels:
app: redis
template:
metadata:
labels:
app: redis
spec:
containers:
- image: redis
name: redis
---
apiVersion: v1
kind: Service
metadata:
labels:
app: redis
name: redis
spec:
ports:
- port: 6379
protocol: TCP
targetPort: 6379
selector:
app: redis
type: ClusterIP
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: rng
name: rng
spec:
replicas: 1
selector:
matchLabels:
app: rng
template:
metadata:
labels:
app: rng
spec:
containers:
- image: dockercoins/rng:v0.1
name: rng
---
apiVersion: v1
kind: Service
metadata:
labels:
app: rng
name: rng
spec:
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
app: rng
type: ClusterIP
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: webui
name: webui
spec:
replicas: 1
selector:
matchLabels:
app: webui
template:
metadata:
labels:
app: webui
spec:
containers:
- image: dockercoins/webui:v0.1
name: webui
---
apiVersion: v1
kind: Service
metadata:
labels:
app: webui
name: webui
spec:
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
app: webui
type: NodePort
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: worker
name: worker
spec:
replicas: 1
selector:
matchLabels:
app: worker
template:
metadata:
labels:
app: worker
spec:
containers:
- image: dockercoins/worker:v0.1
name: worker
66 changes: 66 additions & 0 deletions slides/k8s/kubectlrun.md
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,72 @@ Let's leave `kubectl logs` running while we keep exploring.

---

## Scheduling periodic background work

- A Cron Job is a job that will be executed at specific intervals

(the name comes from the traditional cronjobs executed by the UNIX crond)

- It requires a *schedule*, represented as five space-separated fields:

- minute [0,59]
- hour [0,23]
- day of the month [1,31]
- month of the year [1,12]
- day of the week ([0,6] with 0=Sunday)

- `*` means "all valid values"; `/N` means "every N"

- Example: `*/3 * * * *` means "every three minutes"

---

## Creating a Cron Job

- Let's create a simple job to be executed every three minutes

- Cron Jobs need to terminate, otherwise they'd run forever

.exercise[

- Create the Cron Job:
```bash
kubectl run --schedule="*/3 * * * *" --restart=OnFailure --image=alpine sleep 10
```

- Check the resource that was created:
```bash
kubectl get cronjobs
```

]

---

## Cron Jobs in action

- At the specified schedule, the Cron Job will create a Job

- The Job will create a Pod

- The Job will make sure that the Pod completes

(re-creating another one if it fails, for instance if its node fails)

.exercise[

- Check the Jobs that are created:
```bash
kubectl get jobs
```

]

(It will take a few minutes before the first job is scheduled.)

---


## What about that deprecation warning?

- As we can see from the previous slide, `kubectl run` can do many things
Expand Down
93 changes: 93 additions & 0 deletions slides/k8s/yamldeploy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# Deploying with YAML

- So far, we created resources with the following commands:

- `kubectl run`

- `kubectl create deployment`

- `kubectl expose`

- We can also create resources directly with YAML manifests

---

## `kubectl apply` vs `create`

- `kubectl create -f whatever.yaml`

- creates resources if they don't exist

- if resources already exist, don't alter them
<br/>(and display error message)

- `kubectl apply -f whatever.yaml`

- creates resources if they don't exist

- if resources already exist, update them
<br/>(to match the definition provided by the YAML file)

- stores the manifest as an *annotation* in the resource

---

## Creating multiple resources

- The manifest can contain multiple resources separated by `---`

```yaml
kind: ...
apiVersion: ...
metadata: ...
name: ...
...
---
kind: ...
apiVersion: ...
metadata: ...
name: ...
...
```

---

## Creating multiple resources

- The manifest can also contain a list of resources

```yaml
apiVersion: v1
kind: List
items:
- kind: ...
apiVersion: ...
...
- kind: ...
apiVersion: ...
...
```

---

## Deploying dockercoins with YAML

- We provide a YAML manifest with all the resources for Dockercoins

(Deployments and Services)

- We can use it if we need to deploy or redeploy Dockercoins

.exercise[

- Deploy or redeploy Dockercoins:
```bash
kubectl apply -f ~/container.training/k8s/dockercoins.yaml
```

]

(If we deployed Dockercoins earlier, we will see warning messages,
because the resources that we created lack the necessary annotation.
We can safely ignore them.)

11 changes: 6 additions & 5 deletions slides/kube-fullday.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ chapters:
- shared/prereqs.md
#- shared/webssh.md
- shared/connecting.md
- k8s/versions-k8s.md
#- k8s/versions-k8s.md
- shared/sampleapp.md
#- shared/composescale.md
#- shared/hastyconclusions.md
Expand All @@ -42,17 +42,18 @@ chapters:
#- k8s/buildshiprun-selfhosted.md
- k8s/buildshiprun-dockerhub.md
- k8s/ourapponkube.md
#- k8s/kubectlproxy.md
#- k8s/localkubeconfig.md
#- k8s/accessinternal.md
-
- k8s/setup-k8s.md
- k8s/yamldeploy.md
#- k8s/setup-k8s.md
- k8s/dashboard.md
#- k8s/kubectlscale.md
- k8s/scalingdockercoins.md
- shared/hastyconclusions.md
- k8s/daemonset.md
#- k8s/dryrun.md
#- k8s/kubectlproxy.md
#- k8s/localkubeconfig.md
#- k8s/accessinternal.md
- k8s/rollout.md
#- k8s/healthchecks.md
#- k8s/healthchecks-more.md
Expand Down
7 changes: 4 additions & 3 deletions slides/kube-selfpaced.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,17 @@ chapters:
- k8s/buildshiprun-dockerhub.md
- k8s/ourapponkube.md
-
- k8s/kubectlproxy.md
- k8s/localkubeconfig.md
- k8s/accessinternal.md
- k8s/yamldeploy.md
- k8s/setup-k8s.md
- k8s/dashboard.md
#- k8s/kubectlscale.md
- k8s/scalingdockercoins.md
- shared/hastyconclusions.md
- k8s/daemonset.md
- k8s/dryrun.md
- k8s/kubectlproxy.md
- k8s/localkubeconfig.md
- k8s/accessinternal.md
-
- k8s/rollout.md
- k8s/healthchecks.md
Expand Down
Loading

0 comments on commit 7444f8d

Please sign in to comment.