Tutorials
Short, reproducible procedures: build an image, write a pipeline, run your first Terraform cycle, diagnose a crashing pod, get comfortable with Git and GitLab, and get around VS Code.
Step-by-step procedures
Each tutorial can be completed on a laptop. Commands are copyable. They follow the official tool documentation: check the docs for your version.
Build a small multi-stage Docker image
Docker
Compile a tiny Go web server in one stage and ship only the binary in a minimal, non-root runtime image.
Prerequisites
- Docker installed and running
- No Go installation needed: the build happens in the container
Steps
1. Create the application.
module hello
go 1.22package main
import (
"fmt"
"log"
"net/http"
)
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "hello from a multi-stage image")
})
log.Fatal(http.ListenAndServe(":8080", nil))
}2. Write the Dockerfile. The first stage has the compiler. The second stage contains only the binary.
FROM golang:1.22 AS build
WORKDIR /src
COPY go.mod main.go ./
RUN CGO_ENABLED=0 go build -o /out/app .
FROM gcr.io/distroless/static-debian12:nonroot
COPY --from=build /out/app /app
USER nonroot
EXPOSE 8080
ENTRYPOINT ["/app"]3. Build and run.
docker build -t hello:1 .
docker run --rm -p 8080:8080 hello:1Verify
In a second terminal:
curl http://localhost:8080/
docker images hello:1Common pitfalls
- The final image has no shell, so
docker exec ... shwill fail. That is expected. Use an image with a shell temporarily if you need to debug. CGO_ENABLED=0is needed so the binary is statically linked and runs on the static base image.- Pin image versions in real projects and review base image updates deliberately.
Write a first GitLab CI pipeline with artifacts
GitLab CI
Create two stages, pass a file from the first job to the second, and see the pipeline fail when a check fails.
Prerequisites
- A GitLab project with shared or project runners enabled
Steps
1. Add this file at the root of the repository.
stages:
- build
- test
build-job:
stage: build
image: alpine:3.20
script:
- mkdir -p dist
- echo "artifact" > dist/app.txt
artifacts:
paths:
- dist/
test-job:
stage: test
image: alpine:3.20
script:
- test -f dist/app.txt2. Commit and push. Open the project’s CI/CD, then Pipelines, page to watch it run.
3. Break it on purpose. Change the test to test -f dist/missing.txt, push, and observe the failed job and its log.
Verify
The first run should show both jobs green. After the change, test-job fails and, if merge requests require a passing pipeline, the merge is blocked.
Common pitfalls
- Jobs in later stages receive artifacts from earlier stages by default. Use
dependenciesorneedsto control this. - Artifacts are for passing outputs between jobs. Use
cachefor dependency downloads.
Your first Terraform workflow without any cloud account
Terraform
Learn init, plan, apply and destroy using the local provider, so nothing is billed.
Prerequisites
- Terraform CLI installed
Steps
1. Create the configuration.
terraform {
required_providers {
local = {
source = "hashicorp/local"
}
}
}
variable "greeting" {
type = string
default = "Hello from Terraform"
}
resource "local_file" "hello" {
filename = "${path.module}/hello.txt"
content = "${var.greeting}n"
}
output "file_path" {
value = local_file.hello.filename
}2. Run the cycle.
terraform init
terraform fmt
terraform validate
terraform plan
terraform apply3. Change the variable and read the plan.
terraform plan -var="greeting=Hello again"4. Clean up.
terraform destroyVerify
After apply, cat hello.txt shows the greeting. The second plan shows the file content changing, and destroy removes the file.
Common pitfalls
- Always read the plan. Look for lines marked as replaced or destroyed, not just added or changed.
- The state file (
terraform.tfstate) can contain sensitive values. Do not commit it. Use a remote backend for shared work.
Diagnose a Kubernetes pod in CrashLoopBackOff
Kubernetes
A repeatable order of checks that keeps you from guessing. Read-only commands first, then act.
Prerequisites
- kubectl configured for the target cluster and namespace
- Permission to read pods, events and logs
Steps
1. Find the failing pod.
kubectl get pods -n <namespace>2. Read the pod description. Look at State, Last State, Reason, Exit Code, the container’s restart count and the Events at the bottom.
kubectl describe pod <pod> -n <namespace>3. Read the logs of the previous, crashed container.
kubectl logs <pod> -n <namespace> --previous4. Check recent events in the namespace.
kubectl get events -n <namespace> --sort-by=.lastTimestamp5. Interpret what you see.
OOMKilledas the last reason: the container exceeded its memory limit. Compare usage with the limit before raising it.- A non-zero exit code with an application stack trace in the logs: it is an application or configuration error, not a Kubernetes one.
- Failed liveness probe events: the probe may be too strict or start too early. Review
initialDelaySecondsor use a startup probe. - Error pulling image events would show
ImagePullBackOffinstead, which is a different problem (registry, credentials or tag).
6. If the cause is a bad release, roll back.
kubectl rollout undo deployment/<name> -n <namespace>
kubectl rollout status deployment/<name> -n <namespace>Verify
The pod should reach Running and stay ready. Watch it with kubectl get pods -w for a few minutes, not seconds, because the back-off delay grows between restarts.
Common pitfalls
- Do not delete pods repeatedly hoping it fixes itself. Restarts hide the evidence.
- Raising limits without measuring can move the problem to other workloads on the node.
- Restart-happy behaviour can cascade to dependent services. Change one thing at a time and record it.
Git commands with examples, then browse and use a GitLab project
GitGitLab
The core Git commands with worked examples, then the same repository browsed and used through GitLab: the file tree, branches, commits, and opening a merge request.
Prerequisites
- Git installed (
git --version) - A GitLab account (gitlab.com or a self-managed instance) with at least read access to one project; write access for the push and merge request steps
Steps
1. Configure Git once per machine.
$ git config --global user.name "Your Name"
$ git config --global user.email "you@example.com"
$ git config --global init.defaultBranch main2. Track a small project locally. A plain local repository first, no GitLab involved yet, so the core commands are clear before a remote enters the picture.
$ mkdir hello-git && cd hello-git
$ git init
$ echo "# Hello Git" > README.md
$ git status
$ git add README.md
$ git commit -m "docs: add README"
$ git log --oneline3. Branch, inspect and undo. git status and git diff before every commit is the habit that avoids most mistakes; git restore and git reset --soft are how to walk something back without losing work.
$ git switch -c feature/readme-update
$ echo "A short note about this project." >> README.md
$ git status
$ git diff
$ git add README.md
$ git commit -m "docs: expand README"
# Undo an unstaged edit, safely
$ echo "oops" >> README.md
$ git restore README.md
# Undo the last commit but keep the change staged
$ git reset --soft HEAD~1
# List and switch branches
$ git branch
$ git switch main4. Browse the project in GitLab, before cloning anything. Open the project in a browser and look at:
- The file tree on the project’s overview page, and the branch selector above it
- Repository > Commits for the commit history, and Repository > Branches for every branch and who last pushed to it
- A file’s Blame view, to see which commit last changed each line
- Merge requests and Issues in the left sidebar, for what is currently in progress
5. Clone the project and connect your local Git to it.
$ git clone https://gitlab.com/your-group/your-project.git
$ cd your-project
$ git remote -v
$ git branch -a6. Make a change, push a branch, and open a merge request. Push first:
$ git switch -c fix/typo-in-readme
# edit a file, then:
$ git add -A
$ git commit -m "fix(docs): correct typo"
$ git push -u origin fix/typo-in-readmeGitLab prints a direct link to create the merge request right after the push; otherwise open the project, go to Merge requests, and click New merge request, choosing the branch just pushed as the source.
7. Keep your branch up to date.
$ git fetch origin
$ git status
$ git pull
# Rebase your branch on the latest main instead of merging, if your team prefers a linear history
$ git switch fix/typo-in-readme
$ git rebase mainVerify
git log --oneline shows the commits from step 2 and 3 in order. After step 6, the new merge request appears under the project’s Merge requests tab, targeting the branch chosen there (usually main). git branch -vv shows the local branch tracking its GitLab counterpart.
Common pitfalls
git reset --harddiscards uncommitted changes permanently.git reset --soft(used above) keeps them staged; when in doubt, use--softorgit restoreinstead.git resetrewrites history and should stay local, before anything is pushed. Once a commit is on a shared branch, undo it withgit revertinstead, which adds a new commit rather than erasing the old one.- Force-pushing (
git push --force) to a shared branch can overwrite a teammate’s work.git push --force-with-leaseat least refuses if the remote has commits your local copy has not seen. - Rebasing (step 7) rewrites the branch’s commits. Safe on a branch only you use; avoid rebasing a branch other people have already pulled.
Get around VS Code: files, editing, the terminal and your first extension
VS Code
The core interface and habits, before the SRE-specific setup: opening a project the right way, moving around and editing with confidence, and running something without leaving the editor. Default macOS shortcuts are used throughout; check yours in Preferences: Open Keyboard Shortcuts if they differ.
Prerequisites
- VS Code installed. See the VS Code for SRE and DevOps guide’s install step if it is not yet on your Mac, including how to put the
codecommand in your PATH.
Steps
1. Open a folder, not a file. VS Code’s project features (search across files, Source Control, the Explorer tree) need a folder open, not a single file.
$ code ~/projects/your-project
# From inside VS Code's own terminal, to open a different folder
$ code .2. Learn the four places you will spend the most time.
- Explorer (Cmd + Shift + E): the file tree for the open folder
- Editor tabs: each open file, with a dot on tabs that have unsaved changes
- Command Palette (Cmd + Shift + P): every command VS Code exposes, searchable by name, including ones with no keyboard shortcut or menu entry
- Integrated terminal (Ctrl + `, the backtick key): a real shell, opened in the project folder
3. Edit faster than one line at a time.
- Cmd + P: jump straight to a file by typing part of its name (different from Cmd + Shift + P, the Command Palette)
- Cmd + D: select the next occurrence of the current selection, to rename several matches by typing once
- Option + Click: add another cursor, to edit several lines at the same position at once
- Cmd + F / Cmd + Shift + F: find in the current file, or across every file in the folder
4. Install one extension and set it as the default formatter. Prettier is used here as a concrete example; substitute whichever formatter matches your language.
$ code --install-extension esbenp.prettier-vscode
$ code --list-extensionsThen, in Preferences: Open User Settings (JSON), set it for the relevant language, for example:
{
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
}5. Run something and jump straight to an error. Run a script in the integrated terminal. A file path and line number in the output is clickable and opens that exact location in the editor.
$ python3 broken.py
File "broken.py", line 7
prin("hello")
NameError: name 'prin' is not definedVerify
Cmd + P then a partial filename opens the right file from anywhere in the project. The Extensions view (Cmd + Shift + X) lists the extension installed in step 4 as installed and enabled. Clicking a file:line reference in the terminal’s output opens that file at that line.
Common pitfalls
- Opening a single file (File > Open File) instead of the folder loses project-wide search, Source Control, and most extension features. Use File > Open Folder.
- Cmd + P (quick open a file) and Cmd + Shift + P (the Command Palette, for commands) are easy to mix up; the Palette always starts with
>in the input box. - Hand-editing
settings.jsonwith a stray comma or missing brace can silently stop later keys in the same file from applying. VS Code underlines the syntax error; fix it before assuming a setting “does not work”. - An extension only becomes the active formatter once it is set under the language-specific key shown in step 4; installing it alone is not enough.
benmabrouk.fr: free DevOps and SRE learning resources, written from real-world experience.