Build and push a Docker image to the registry

docker build -t <proj name> <directory> 
#add -q for less clutter on the screen
docker run -d -p <port>:<port on localhost> <name>
docker tag <name> <user/name:v>
docker push <user/name:v>

Set up a Kubernetes cluster inside Virtualbox (using Vagrant)

vagrant up
vagrant ssh
sudo su
curl -sfL <https://get.k3s.io> | sh -
k3s kubectl get node
cd /etc/rancher/k3s
vi k3s.yaml
kubectl get no -o wide

Create deployment

kubectl create deploy go-helloworld --image=nandiniproothi/go-helloworld:v1.0.0

If your pod gets an CreateContainerError, try running this command: zypper install -t pattern apparmor this uses SUSE's CLI zypper which can install, update, remove, and manage repositories apparmor_parser loads apparmor (a linux security module) profiles into the linux kernel

To check if the application is running in the container, we can forward the port

kubectl port-forward deployment/go-helloworld 6111:6111 --address 0.0.0.0

Now, check http://192.168.50.4:6111/ (check your Vagrantfile for the IP)

Edit the deployment's yaml file, change the version, pull that image from docker hub and run it on a different port. The RS is created on its own.

kubectl edit deploy go-helloworld -o yaml
/image
a
<change v1.0.0 to v2.0.0>
esc
:wq
kubectl get rs
kubectl get po

To expose the deployment to a service

kubectl expose deploy go-helloworld --port=6112 --target-port=6112
kubectl get svc

Note: ClusterIP is the default service type and TCP is the default network protocol for a service

To check if the service is accessible

kubectl run test-$RANDOM --namespace=default --rm -it --image=alpine -- sh
#creates a test pod and opens the command prompt. terminates the pod once the shell is closed
wget -qO- 10.43.200.247:6112

To create a configmap, secret, and namespace