Sources for a practice lecture about containers used in NSWI026 MFF UK and SEPA4M33SEP, FEL CVUT. This should be a simple introduction for k8s, it's not recommended for a production usage.
- Install minikube
- Observe cluster
- Try k8s dashboard
- (Optional) Try k9s
- Deploy resource using kubectl
- Deploy resource using helm
- Try GitOps and ArgoCD
We will use Minikube.
# Install minikube
curl -LO https://github.com/kubernetes/minikube/releases/latest/download/minikube-linux-amd64
sudo install minikube-linux-amd64 /usr/local/bin/minikube && rm minikube-linux-amd64
# Start minikube
minikube start
# Optional steps
minikube config set rootless true
minikube delete
minikube startYou will need to have kubectl, I successfully installed it using Brew.
# Install kubectl using brew
brew install kubectl
# Test if it works fine
kubectl get po -A
# Optional, try k9s
brew install k9sLet's see what minikube is simulating for us:
Let's check a first deployment, we can try it using Kubernetes Dashboard
minikube addons enable metrics-server
minikube dashboardCheck the cluster using dashboard in browser, eg. http://127.0.0.1:37737/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/.
Observe existing resoruces in cluster
- See Service -> Pod -> Container
- Check namespaces
Let's try first deployment of an Nginx container,
kubectl apply -f 01-deployment.yamlYou can validate results in dashboard or using k9s.
-
Pod
- This is mostly for debug purposes
- Pod name change with each restart
export POD_NAME=$(kubectl get pods -o go-template --template '{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}') echo Name of the Pod: $POD_NAME
- Let's try
kubectl proxy(port-forward would work as well)kubectl proxy curl http://localhost:8001/api/v1/namespaces/default/pods/$POD_NAME:80/proxy/
-
Service
- Service will be stable, even if pod is recreated
- Let's try
kubectl port-forward(proxy would work as well)kubectl port-forward svc/nginx 9090:80 curl http://localhost:9090
-
Ingress
- We would normally have an ingress that will be pointing to a service.
We use deployment for nginx. Deployment is stateless (name and IP could change), data are stored in ephemeral storage (eg. /tmp folder) or shares a single PersistentVolumeClaim (PVC) across all pods. StatefulSet is statuful (name and IP is stable), data are stored in volumeClaimTemplates to create a unique, persistent PVC for each pod (e.g., data-db-0, data-db-1).
We need to install helm, I was successfull using brew. See full docs on https://helm.sh/docs/topics/charts/.
# Install dependencies
brew install helm
# Test the template
helm template hello-helm --values hello-helm/values.yamlLet's deploy with helm
# Remove old changes
kubectl delete -f 01-deployment.yaml
# Let's use helm install
helm install helm-release hello-helm --values hello-helm/values.yaml
helm listLet's try to automate deployment using GitOps principles.
We can deploy ArgoCD to our cluster.
# Remove previous deployment
helm uninstall helm-release
# Create a new namespace
kubectl create ns argocd
# Deploy a new resources
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/v2.5.8/manifests/install.yaml
# Forward port to localhost
kubectl port-forward svc/argocd-server -n argocd 9090:443Let's check ArgoCD web GUI at https://localhost:9090, default username is admin, password we get using
kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d; echoAdd new project in ArgoCD using following config:
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: example
spec:
project: default
source:
repoURL: 'https://github.com/maresmar/k8s-course.git' # Or better replace with your repository
path: 02-helm/hello-helm
targetRevision: HEAD
destination:
server: 'https://kubernetes.default.svc'
namespace: argocd
syncPolicy: {}Use GUI to "SYNC" changes, and observe results.
You could also commit a new message in cm.yaml and try to "REFRESH" (changes from GitHub) and "SYNC" them to cluster.
- https://minikube.sigs.k8s.io/docs/handbook/controls/
- https://minikube.sigs.k8s.io/docs/handbook/accessing/
- https://k9scli.io/
- https://kubernetes.io/docs/tutorials/kubernetes-basics/expose/expose-intro/
- https://argo-cd.readthedocs.io/en/stable/
- https://medium.com/@mehmetodabashi/installing-argocd-on-minikube-and-deploying-a-test-application-caa68ec55fbf