Part 1 Flashcards
Question 1: Creating Single Container Pods Create a pod with the name of kplabs-nginx. The pod should be launched from an image of mykplabs/kubernetes:nginx . The name of the container should be mycontainer
apiVersion: v1
kind: Pod
metadata:
name: kplabs-nginx
namespace: default
labels:
env: test
spec:
containers:
- name: mycontainer
image: mykplabs/kubernetes:nginx
Create a Multi-Container POD with the name of kplabs-multi-container
There should be 3 containers as part of the pod. Name the first container as first-container
, 2nd container as second-container
and 3rd container as third-container
1st container should be launched from nginx
image, second container should be launched from mykplabs/kubernetes:nginx
image and third container from busybox
image.
Connect to the first-container and run the following command: apt-get update && apt-get install net-tools
Connect to the third-container and identify the ports in which processes are listening. Perform wget
command on those ports and check if you can download the HTML page.
apiVersion: v1
kind: Pod
metadata:
name: kplabs-multi-container
namespace: default
labels:
env: test
spec:
containers:
- name: first-container
image: nginx - name: second-container
image: mykplabs/kubernetes:nginx - name: third-container
image: busybox
command:
- sleep
- “3600”
kubectl exec -it kplabs-multi-container bash
netstat -ntlp kubectl exec -it kplabs-multi-container -c third-container sh
wget http://localhost:80
Create a pod with the name of kplabs-cmdargs
. The pod should be launched from an image of busybox
. The name of the container should be cmdcontainer
. Both the container image’s CMD and ENTRYPOINT instruction should be overridden.
The container should start with sleep
command and argument of 3600
apiVersion: v1
kind: Pod
metadata:
name: kplabs-cmdargs
namespace: default
labels:
env: test
spec:
containers:
- name: cmdcontainer
image: busybox
command: [“sleep”]
args: [“3600”]
Create a pod with the name of kplabs-ports
. The pod should be launched from an image of nginx
. The name of the container should be nginx
. Expose Port 80
for the POD.
apiVersion: v1
kind: Pod
metadata:
name: kplabs-ports
namespace: default
labels:
env: test
spec:
containers:
- name: nginx
image: nginx
apiVersion: v1
kind: Service
metadata:
name: nginx
labels:
run: nginx
spec:
ports:
- port: 80
protocol: TCP
selector:
run: nginx
kubectl exec -it kplabs-ports -c nginx sh
apt-get update && apt-get install net-tools
kubectl port-forward pods/kplabs-ports 8888:80
CLI Documentation
- List down all the available fields and it’s associated description that we can include in a POD Manifest. Store data to
pod.txt
- List down all the fields & it’s description that we can add under the metadata section under POD manifest. Store data to
pod-manifest.txt
- Matthew has realized that there is an option for
tolerationSeconds
under POD -> Spec -> Tolerations. Store the associated documentation for tolerationSeconds and store it under a file named tolerationSeconds.txt
kubectl explain pod >pod.txt
kubectl explain pod.spec > pod-manifest.txt
kubectl explain pod.spec.tolerations > tolerationSeconds.txt
Arguments
Create a pod named kplabs-logging
The Pod should have a container running from the nginx
image with the following arguments:
- /bin/sh
- -c
- >
- i=0;
- while true;
- do
- echo “$i: $(date)” >> /var/log/1.log;
- echo “$(date) INFO $i” >> /var/log/2.log;
- i=$((i+1));
- sleep 1;
- done
Once POD is created, connect to the POD and verify the contents of /var/log/1.log
and /var/log/2.log
apiVersion: v1
kind: Pod
metadata:
name: kplabs-logging
namespace: default
labels:
env: test
spec:
containers:
- name: nginx
image: nginx
args :
- /bin/sh
- -c
- >
i=0;
while true;
do
echo “$i: $(date)” >> /var/log/1.log;
echo “$(date) INFO $i” >> /var/log/2.log;
i=$((i+1));
sleep 1;
done
kubectl exec -it kplabs-logging -c nginx sh
cat /var/log/1.log
kubectl delete pod kplabs-logging
POD Troubleshooting
- Create a POD with the name
kplabs-troubleshoot
. Launch it frombusybox
image. - Once launch, verify if you can see pod in “Ready” state.
- If it’s not in ready state, find out what can be the reason.
- Edit the POD manifest to make sure busybox pod is available for at-least next 10 minutes.
apiVersion: v1
kind: Pod
metadata:
name: kplabs-cmdargs
namespace: default
labels:
env: test
spec:
containers:
- name: cmdcontainer
image: busybox
command: [“sleep”]
args: [“3600”]
API Primitives
- Create a proxy connection via
kubectl proxy --port 8080
- Verify from browser if you are able to see the list all the Kubernetes API’s.
- Find the list of resources under the
/api/v1
- Find the list of all the PODS running within your Kubernetes environment,
kubectl proxy –port 8080
kubectrl describe
kubectrl describe pods
kubectrl explain
kubectrl explain pod
kubectl run –help
kubectl run –help ( scroll up to see examples)