Use the local version of Kubernetes that comes with Docker desktop. See the link for installation instructions. It can be quite resource heavy so you should disable it once you're done.
There are other options like kind, minikube, k3s if you prefer.
Make sure you have kubectl
installed. It should be installed as part of Docker under C:\Program Files\Docker\Docker\resources\bin\kubectl.exe
. If you can't type kubectl
in a terminal window, then you need to add that path to the system environment variable called PATH
.
kubectl config get-contexts
should list all the "contexts" (the clusters) you have access to. Thedocker-desktop
cluster should be therekubectl config use-context docker-desktop
should connect you to the local cluster- Make sure you can access it by running
kubectl get pods -A
(list all pods in all namespaces)
You might also want to connect to the cluster using Lens, so that you get a better overview of what's going on. The cluster should be listed in Lens and you should be able to connect to it.
- In order to run Flux locally, you need to create a personal access token in GitHub: https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token.
$env:GITHUB_TOKEN='<your token>'
$env:GITHUB_USER='<your username>'
You're going to need the Flux CLI, install it from here: https://fluxcd.io/flux/installation/#install-the-flux-cli (again, Chocolatey is an easy way for Windows).
kubectl get namespaces
will list the existing namespacescd manifests
kubectl apply -f namespace.yaml
will tell kubernetes to create the namespace defined in the file.kubectl get namespaces
will list the new namespace
We actually create a Deployment
, which is responsible of keeping one or more replicas of a pod alive.
kubectl apply -f deployment.yaml
kubectl get pods -n whoami
list the pods in thewhoami
namespace- If you delete a pod, the deployment will make sure a new replica is created.
kubectl delete pod -n whoami <name_of_pod>
Create a Service
which we can use to access the pods in a load balanced way.
kubectl apply -f service.yaml
kubectl get services -n whoami
to make sure the service is created. You can see that it has aClusterIP
but noExternalIP
. This means that you cannot access this service from outside the cluster.- A way of accessing the service is to do a port-forward. That will map a port on your local computer, to a port on the service. This isn't something you do other than in debugging purposes.
kubectl port-forward -n whoami svc/whoami 8080:80
will let you access the service fromhttp://localhost:8080/
on your local computer. - Press
ctrl+c
to abort port forwarding
In order to access a service (and indirectly a pod) from outside the cluster, we need an Ingress Controller. The one we use is Traefik.
cd traefik
kubectl apply -f 00-role.yaml -f 00-account.yaml -f 01-role-binding.yaml -f 02-traefik.yaml -f 02-traefik-services.yaml
- http://localhost:8080/dashboard/#/ should show you the Traefik dashboard
- http://localhost:80 will give you a 404 (from Traefik)
kubectl apply -f 03-whoami.yaml -f 03-whoami-services.yaml -f 04-whoami-ingress.yaml
- http://localhost:80
- Start by deleting the previous stuff
kubectl delete -f 00-role.yaml -f 00-account.yaml -f 01-role-binding.yaml -f 02-traefik.yaml -f 02-traefik-services.yaml -f 03-whoami.yaml -f 03-whoami-services.yaml -f 04-whoami-ingress.yaml
kubectl kustomize
will use kustomize to merge the files into one.kubectl apply -k ./
Flux is a tool that helps us do "GitOps". That means that we can have a desired state in git, and it will be Flux's job to make sure that state is reconciled in the cluster.
Flux is running as a pod in the cluster, listening for changes in the git repository while also making sure the cluster matches what's in git.
- Make sure you're good to go:
flux check --pre
- Install Flux in the cluster, and create a new personal reposoty flux will sync against
flux bootstrap github --owner=$env:GITHUB_USER --repository=flux-demo --branch=main --path=./clusters/my-cluster --personal
- Check Flux installation
kubectl get pods -n flux-system
- Clone your new repo:
git clone https://github.com/$env:GITHUB_USER/fleet-infra
and open it in an editor