Kubernetes (k8s) for developers

Create oci images/containers

Use podman or docker.

examplescript.sh

#!/bin/bash
while true
do
	echo "Press [CTRL+C] to stop.."
	sleep 1
done

Make the script executable.

chmod +x ./examplescript.sh

Dockerfile. The filename must be “Dockerfile” or when calling docker build -f must be used to pass in the filename.

FROM ubuntu:22.04
ADD examplescript.sh /
RUN apt update && apt install bash -y
CMD [ "./examplescript.sh" ]

build the image

sudo docker build -t exampleapp .

Verify the image was built.

sudo docker build -t exampleapp .
sudo docker images
sudo docker run localhost/exampleapp

create pods and deployments

create a pod yaml

Create the yaml for a pod running a nginx container.

kubectl run nginx --image=nginx --dry-run=client -o yaml > example-pod.yaml

create a deployment yaml

Create the yaml for a deployment with a pod running an nginx container.

kubectl create deployment --image=nginx nginx --dry-run=client -o yaml > example-deployment.yaml

create a nodeport service yaml

Use a nodeport service to expose an applications via port. Note: –tcp=:

kubectl create service nodeport ns-service --tcp=80:80 --dry-run=client -o yaml > example-nodeport-service.yaml