Dit deel is nog niet vertaald. Je ziet de Engelse tekst.
Doel
Ship one small release from a Git commit to a running service, and use each of the 10 tools for the job it is best at. Every task should take one or two commands. Do the drill once slowly, then again with a timer: the goal is under 25 minutes, without looking at the solution.
Voordat je begint
- Install the tools (all are free). Make a local cluster:
kind create cluster --name drill. - Make the folder
~/drillwith anindex.htmlthat saysversion 1and a 2-lineDockerfile(FROM nginx:1.27-alpine,COPY index.html /usr/share/nginx/html/).
Taken
Vink een taak aan als hij klaar is. Alleen je browser onthoudt dit.
- git — make a repository, commit both files, tag the commit
v1.0.0(annotated), and show the last commit in one line. - docker — build the image
drill-web:1.0.0, run it on port 8081, and stop it again after the test. - curl — check the container: only the HTTP status code, then the response headers, with a 3-second timeout.
- kind / kubectl — load the image into the kind cluster (no registry), create a namespace
drill, a deployment with 2 replicas, and a Service. - kubectl — wait for the rollout, then reach the app with
port-forwardandcurl. Show the pods with their node and IP. - helm — install the chart
bitnami/redis(or any small chart) indrillwith one value changed from the command line; list releases; uninstall. - kubectl — change
index.htmltoversion 2, build1.0.1, load it, update the image of the deployment, watch the rollout, then roll back. - terraform — with the
localprovider, write a filerelease.txtthat contains the deployed version from a variable;applywith-var. - ansible — run an ad-hoc command against
localhostthat shows the free disk space, and one that makes sure the folder/tmp/drillexists. - ssh — run one remote command on a server (or
localhostwith your key) that prints the hostname and uptime, using a host entry from~/.ssh/config.
Controleer je werk
git describe --tags
kubectl -n drill rollout history deploy/web
kubectl -n drill get deploy web -o jsonpath='{.spec.template.spec.containers[0].image}{"\n"}'
cat release.txt
ls -d /tmp/drillgit describeprintsv1.0.0.- The rollout history has at least 3 revisions (create, update, rollback).
- After the rollback the image is
drill-web:1.0.0andcurlshowsversion 1. release.txthas the version you gave with-var.
Hints
Toon de hints
git log -1 --oneline;git tag -a v1.0.0 -m "first release".curl -s -o /dev/null -w "%{http_code}\n" -m 3 URLandcurl -sI URL.kind load docker-image drill-web:1.0.0 --name drill; in the deployment setimagePullPolicy: IfNotPresent(the default for a tag that is notlatest).kubectl rollout status,kubectl rollout undo,kubectl get pods -o wide.helm install NAME CHART --set key=value -n NS;helm list -n NS.ansible localhost -m command -a "df -h /";ansible localhost -m file -a "path=/tmp/drill state=directory".
Oplossing
Toon de oplossing
- git.
- docker + 3. curl.
- and 5. kind + kubectl.
kind load docker-image drill-web:1.0.0 --name drill kubectl create ns drill kubectl -n drill create deploy web --image=drill-web:1.0.0 --replicas=2 --port=80 kubectl -n drill expose deploy web --port 80 kubectl -n drill rollout status deploy/web kubectl -n drill get pods -o wide kubectl -n drill port-forward svc/web 8082:80 & curl -s localhost:8082 version 1 - helm.
- Update and roll back.
echo "version 2" > index.html && docker build -t drill-web:1.0.1 . && kind load docker-image drill-web:1.0.1 --name drill kubectl -n drill set image deploy/web drill-web=drill-web:1.0.1 kubectl -n drill rollout status deploy/web kubectl -n drill rollout undo deploy/web kubectl -n drill rollout history deploy/webkubectl create deploynames the container after the image (drill-web); check it withkubectl -n drill get deploy web -o yaml | grep -A2 containersifset imagesays the container is not found. - terraform.main.tf
variable "version_deployed" { type = string } resource "local_file" "release" { filename = "${path.module}/release.txt" content = "web ${var.version_deployed}\n" } - ansible.
- ssh.~/.ssh/config
Host lab HostName 127.0.0.1 User youruser IdentityFile ~/.ssh/id_ed25519
Mijn notities
Nog geen notities.
Lessen voor dit lab
- 13.2git — elke wijziging in één geschiedenis
- 13.3docker — containers bouwen en draaien
- 13.4kubectl — praten met Kubernetes
- 13.5helm — pakketten voor Kubernetes
- 13.6terraform — infrastructure as code
- 13.7ansible — veel servers configureren
- 13.10ssh — veilige toegang tot servers
- 13.11curl — websites en API's testen
- 13.12Volg één wijziging door alle 10 tools
- 13.13Test jezelf