3  Usage

3.1 Dependencies

You will need to install the following dependencies:

brew install awscli kubectl helm

3.2 Authentication

Ensure you have access to EKS which is done by adding your IAM to the EKS in the terraform configuration.

KUBECONFIG=./kubeconfig aws --profile=account eks update-kubeconfig --cluster cluster-name

There can be multiple clusters so pick the correct cluster. Ensure that you set export KUBECONFIG=./kubeconfig to get the correct KUBECONFIG file. This can be added into you .bashrc or .zshrc

3.3 Ingress

The ingress is in its simplest form a Kubernetes LoadBalancer. Instead of what would traditionally be this:

DNS (i.e app.example.com) -> Kubernetes Service -> Kubernetes Pods

It is the following:

DNS (i.e app.example.com) -> Ingress (Public IP Address/CNAME) -> Kubernetes Service -> Kubernetes Pods

To break down the Ingress request cycle even further it is the following:

DNS (i.e app.example.com) -> Ingress [Kubernetes Service -> Kubernetes Pods (Nginx) -> Kubernetes Service -> Kubernetes Pods]

The Ingress is just another pod such as Nginx that relays the traffic and as such is just another pod in the system. The ingress is a helm chart and is installed manually with the following script.

The ingress works at the DNS layer so it needs to be passed a Host to work:

curl -k -H "Host: app.example.com" <https://a54313f35cb5b11e98bb60231b063008-2077563408.us-west-2.elb.amazonaws.com>

3.4 Deployments

3.4.1 Scale Down / Up

This has to be done through the deployment in the helm chart. Another way to do it is to scale down

num=0

kubectl scale --replicas=${num} -n <namespace> deployment/<deploymentname>

3.5 Pods

3.5.1 List Running Pods

kubectl get pods -A

Kubernetes lets you divide your cluster into namespaces. Each namespace can have its own set of resources. The above command lists all running pods on every cluster. Pods in the kube-system namespace belong to Kubernetes and helps it function.

3.5.2 Describe Pods

kubectl describe pods <podname>

3.5.3 “SSH”

To connect to the application look at the namespaces:

kubectl get pods -A
kubectl exec -it -n <namespace> <pod> -c <container> -- bash

3.5.4 Logs

kubectl get pods -A
kubectl logs -f -n <namespace> <pod> -c <container>

This lets you view the logs of the running pod. The container running on the pod should be configured to output logs to STDOUT/STDERR.

3.5.5 Restart a Pod

If you pod is not responding or needs a restart the way to do it is to use the following command. This will delete the pod and replace it with a new pod if it is a part of a deployment.

kubectl delete pod <pod-name>

3.5.6 Pod Issues

A pod can have various different errors. The common ones are:

  • OOMError: The pod or underlying node ran out of memory and killed the pod.
  • CrashLoopBackup: The application itself has an issue, use kubectl logs -f <pod> to find out why
  • ImageNotFound: The docker image for the pod can’t be found.

Cluster Info and Management: 1. Cluster Information: • kubectl cluster-info : Retrieves cluster details like Kubernetes master and services. • kubectl config view : Displays the kubeconfig configuration file. • kubectl version : Shows Kubernetes client and server version info. 2. Nodes and Cluster Operations: • kubectl get nodes : Lists all the nodes in the cluster. • kubectl describe node ip-10-3-141-99.eu-west-1.compute.internal : Provides detailed information about a specific node. • kubectl get pods –all-namespaces : Lists all pods across all namespaces. • kubectl get services –all-namespaces : Lists all services across all namespaces. Workload Management: 1. Pods: • kubectl get pods : Lists all pods in the current namespace. • kubectl describe pod axiom-web-945f96ffb-6svcn : Describes details of a specific pod. • kubectl logs axiom-web-945f96ffb-6svcn : Displays logs from a specific pod. 2. Deployments: • kubectl get deployments : Lists all deployments in the current namespace. • kubectl describe deployment axiom-web : Describes details of a specific deployment. • kubectl rollout status deployment/axiom-web : Checks the status of a deployment rollout. • kubectl rollout history deployment/axiom-web : Displays rollout history of a deployment. 3. Services: • kubectl get services : Lists all services in the current namespace. • kubectl describe service axiom-web : Describes details of a specific service. Scaling: • kubectl scale deployment/ –replicas=2 : Scales a deployment to the desired number of replicas. • kubectl autoscale deployment/ –min= –max= –cpu-percent= : Sets up autoscaling based on CPU usage. Debugging and Troubleshooting: 1. Troubleshooting: • kubectl describe : Describes details of a specific resource (pod, service, etc.). • kubectl exec -it – /bin/bash : Opens a shell inside a running container. 2. Health Checks and Status: • kubectl get events : Shows cluster events. • kubectl top nodes : Displays resource usage for nodes. • kubectl top pods : Displays resource usage for pods.