In our last blog post on managing AWS Kubernetes from the command line, we taught you how to list the names of the available pods. You can find that post here.
Once you have the list of pods, you can then perform a number of operations from the command line directly against the pod using kubectl.
In certain situations, we will want to use the the labels from the yaml spec, to get details on the pod. To learn more about a specific pod, I’ll write a little script entitled describe_backend.sh, which will give me all of the details on a specific pod:
aws-okta exec allcode-devops -- kubectl describe deployment $1
The output results from the describe invocation will consist of a plethora of information including the label of the node, replicas, environment variables, etc.
./describe_backend.sh backend Name: backend Namespace: default CreationTimestamp: Thu, 30 May 2019 09:06:13 -0700 Labels: app=backend Annotations: deployment.kubernetes.io/revision: 9 Selector: app=backend Replicas: 1 desired | 1 updated | 1 total | 1 available | 0 unavailable StrategyType: RollingUpdate MinReadySeconds: 0 RollingUpdateStrategy: 25% max unavailable, 25% max surge Pod Template: Labels: app=backend Containers: backend: Image: 557625311111.dkr.ecr.us-west-2.amazonaws.com/backend:0.3.3 Port: 8080/TCP Host Port: 0/TCP Environment: MONGO_DB: AllCodeDatabase
Another one of our bash shell scripts will enable us to get a bash shell into the pod, so we can navigate to the logs or explore the health of the pod. The contents of my connect_bash.sh will look like the following where $1 will be the output from the “get pods” invocation
aws-okta exec allcode-devops -- kubectl exec -it $1 -- /bin/bash
The command line invocation will result in to a bash cli into the pod without going through the VPN! Helpful!
./connect_bash.sh backend-7d5f74d95f-vq111 root@backend-7d5f74d95f-vq111:/#