- Install minikube
./install-minukube.sh
- Start minikube (enable v1alpha1)
minikube start --nodes=2 \
--memory='4000mb' \
--cpus=4 \
--disk-size=10g \
--driver=kvm2 \
--extra-config=apiserver.runtime-config=settings.k8s.io/v1alpha1=true
- Configure
kubectl config use-context minikube
Delete
minikube delete --all=true --purge=true
- See what changes would be made, returns nonzero returncode if different
kubectl get configmap kube-proxy -n kube-system -o yaml | \
sed -e "s/strictARP: false/strictARP: true/" | \
kubectl diff -f - -n kube-system
kubectl get configmap kube-proxy -n kube-system -o yaml | \
sed -e "s/mode: \"\"/mode: \"ipvs\"/" | \
kubectl diff -f - -n kube-system
- Actually apply the changes, returns nonzero returncode on errors only
kubectl get configmap kube-proxy -n kube-system -o yaml | \
sed -e "s/strictARP: false/strictARP: true/" | \
kubectl apply -f - -n kube-system
kubectl get configmap kube-proxy -n kube-system -o yaml | \
sed -e "s/mode: \"\"/mode: \"ipvs\"/" | \
kubectl apply -f - -n kube-system
- Install metallb
kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.9.3/manifests/namespace.yaml
kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.9.3/manifests/metallb.yaml
# On first install only
kubectl create secret generic -n metallb-system memberlist --from-literal=secretkey="$(openssl rand -base64 128)"
- Configmap
MINIKUBE_IP=$(minikube ip)
export MINIKUBE_BASE_IP=${MINIKUBE_IP%.*}
cat <<EOF | kubectl create -f -
apiVersion: v1
kind: ConfigMap
metadata:
namespace: metallb-system
name: config
data:
config: |
address-pools:
- name: default
protocol: layer2
addresses:
- ${MINIKUBE_BASE_IP}.95-${MINIKUBE_BASE_IP}.105
EOF
-
Get cm:
kubectl -n metallb-system get cm config
-
reference: https://metallb.universe.tf/installation
kubectl get pod
- get information about all runnning podskubectl describe pod <pod>
- describe one podkubectl expose pod <pod> --port=444 --name=frontend
- expose the port of a pod (creates a new service)kubectl port-forward <pod> 8080
- port forward the exposed pod port to your local machinekubectl attach <pod> -i
- attach to the podkubectl exec <pod> -- command
- Execute a command on the podkubectl label pods <pod> my label=awesome
- Add a new label to a podkubectl run -i --tty busybox --image=busybox --restart=Never -- sh
- Run a shell in a pod - very useful for debuggingkubectl get deployments
- get information on current deploymentskubectl get rs
- get information about replica setskubectl get pods --show-labels
- get pods, and also show labels attached to those podskubectl set image deployment/helloworld-deployment k8s-demo=k8s-demo:2
- run k8s-demo with the image label version 2kubectl edit deployment/helloworld-deployment
- edit the deployment objectkubectl rollout status deployment/helloworld-deployment
- get the status of the rolloutkubectl rollout history deployment/helloworld-deployment
- get the history of the rolloutkubectl rollout undo deployment/helloworld-deployment
- rollback to previous versionkubectl rollout undo deployment/helloworld-deployment --to-revision=n
- rollback to any versionkubectl explain pods
orkubectl explain pod.spec
documentationwatch -n1 "kubectl get all -o wide --show-labels"
kubectl logs pod my-name --previous
to show previous restarted podkubectl api-resources
show all resourceskubectl drain <node name>
andkubectl uncordon <node name>
safely drain nodekubectl create -f kubia-deployment-v1.yaml --record
,kubectl set image deployment kubia nodejs=luksa/kubia:v2
,kubectl rollout undo deployment kubia
andkubectl rollout history deployment kubia
- properties:
revisionHistoryLimit
andminReadySeconds
kubectl rollout pause deployment kubia
andkubectl rollout resume deployment kubia
kubectl get pods --all-namespaces -o wide --field-selector spec.nodeName=<node-name>
NOTE Although most objects' names must conform to the naming conventions specified in RFC 1035 (Domain names), which means they may contain only letters, digits, dashes, and dots, namespaces (and a few others) aren't allowed to contain dots.