Kubernetes

Gets a list of all of the pods that are currently in the namespace.

kubectl get pods --all-namespaces

Getting access to the powershell environment from within the kubernetes cluster.

kubectl exec -it <podname> -- powershell

Gets all of the information about the status of the pod from within Kubernetes.

kubectl describe pod <podname>

Kubernetes Cheat Sheet

Set Kuberenetes Config:

export KUBECONFIG=<path_to_kubecfg>

Microk8s

Installing

brew install ubuntu/microk8s/microk8s
microk8s install
microk8s status --wait-ready
microk8s enable dashboard dns registry istio
microk8s kubectl get all --all-namespaces
microk8s dashboard-proxy

Starting Microk8s: microk8s start

Stopping Microk8s: microk8s stop

Helpful alias:

alias kubectl="microk8s kubectl"

Commands:

Gets a list of all of the nodes in the cluster

microk8s kubectl get nodes

Gets the nodes with the wide setting that includes internal and exteranl ip addresses:

microk8s kubectl get nodes -o wide

kubectl

Command for creating a manual deployment on a k8s cluster:

kubectl create deployment <deployment_name> --image=<docker_image>

Command for exposing a port on a deployment:

kubectl expose deployment <deployment_name> --type=NodePort --port=<port>

kubectl expose deployment <deployment_name> --type=NodePort --port=<port> --target-port=<internal_port_number>

Command for checking the status of a deployment including the port number:

kubectl get service <deployment_name>

Command for deleteing a deployment:

kubectl delete -n default deployment <deployment_name>

Command for deleteing a service:

kubectl delete -n default service <deployment_name>

Command for Getting the deployment

watch kubectl get deployment <deployment_name>

Command for getting status of the pod:

kubectl get pod -l app=<deployment_name>

Command for getting the description of an issue with a pod:

kubectl describe pod -l app=<deployment_name>

Connecting a repository instance to a k8s cluster

**Note: the password that is used here is not your password but a toekn that is created from dockerhub -> Security -> Access Tokens

For connecting to docker hub:

kubectl create secret docker-registry regcred --docker-username=<username> --docker-password=<password> --docker-email=<emailaddress>

When connecting to a server other than docker hub:

kubectl create secret docker-registry regcred --docker-username=<username> --docker-password=<password> --docker-email=<emailaddress> --server=<server>

List all of the secrets:

kubectl get secrets

Editing the Settings of a deployment

kubectl edit deployment <deployment_name>

You can get a yaml output via:

kubectl get service <deployment_name> -o yaml

Getting Log infromation about the status of a pod

This will get the logs of the process that is running and will follow the output of the process, -l will get everything associated with the label and –prefix=true will return the name of the pod as part of the output.

kubectl logs -f -l app=<deployment_name> --prefix=true

Upgrade the image of a container

The container image label can bee seen in the pod template under the containers:

kubectl set image deployment/<deployment_name> <kubernetes_container_label>=<repo/image:tag>

Get a history of all of the changes to a deployment:

kubectl rollout history deployment <deployment_name>

This command will rollback a deployment:

kubectl rollout undo deployment <deployment_name>

Namespaces

Create a namespace:œ

kubectl create namespace <namespace_name>

Delete a namespace and all items running under it:

kubectl delete namespace <namespace_name>

Apply a yaml file

kubectl appy -f <yaml_file>

Set context

kubectl config set-context --current --namespace=<namespace>