MY-k8s-Day1-Chapter-2 - (K8s Concept-Lab Guide-Partner)
MY-k8s-Day1-Chapter-2 - (K8s Concept-Lab Guide-Partner)
FUNDAMENTALS -
NETWORKING
February, 2023
CONTENTS
Kubernetes Basics............................................................................................ 5
Lab 1.1 – kubectl & kubeconfig .................................................................................................... 5
RESOURCES
HELPFUL TIPS
View next command Use Tab to view available commands after keyword
Pasting of commands in
web shell (chrome)
© F5, Inc. All rights reserved. F5, F5 Networks, and the F5 logo are trademarks of F5,
Inc. in the U.S. and in certain other countries. Other F5 trademarks are identified at
f5.com. Any other products, services, or company names referenced herein may be
trademarks of the respective owners with no endorsement or affiliation, expressed or
implied, claimed by F5. | February 2023
1
Dry Run --dry-run=client
Verify after execution get pods / XXXX and if error, describe XXXX
-o json
-o template
Navigating between cd .. or cd
directory
View directory ls
© F5, Inc. All rights reserved. F5, F5 Networks, and the F5 logo are trademarks of F5,
Inc. in the U.S. and in certain other countries. Other F5 trademarks are identified at
f5.com. Any other products, services, or company names referenced herein may be
trademarks of the respective owners with no endorsement or affiliation, expressed or
implied, claimed by F5. | February 2023
2
LAB INTRODUCTION
Starting the lab
Wait for the lab to spin up If color is yellow, wait. As the lab will differ in bootup time, Presenter will share the lab bootup time.
© F5, Inc. All rights reserved. F5, F5 Networks, and the F5 logo are trademarks of F5,
Inc. in the U.S. and in certain other countries. Other F5 trademarks are identified at
f5.com. Any other products, services, or company names referenced herein may be
trademarks of the respective owners with no endorsement or affiliation, expressed or
implied, claimed by F5. | February 2023
3
Accessing Web Shell Once all components are green, you may start the lab. To web shell into a K8s node, click the
access button and select web shell from the drop down
Access the master node of the K8s cluster through web shell, key in command below to switch user
to ubuntu
change the directory to home directory instead of root directory, issue command below
cd ~
You will find few yaml files listed in home directory, issue command below
ls
© F5, Inc. All rights reserved. F5, F5 Networks, and the F5 logo are trademarks of F5,
Inc. in the U.S. and in certain other countries. Other F5 trademarks are identified at
f5.com. Any other products, services, or company names referenced herein may be
trademarks of the respective owners with no endorsement or affiliation, expressed or
implied, claimed by F5. | February 2023
4
KUBERNETES BASICS
Pre-requisite -
Steps On the K8 Control Plane, execute the following commands. The following
commands are to retrieve the nodes and pods available within the cluster.
References
Estimated 5 mins
Completion
Time
Pre-
requisite
© F5, Inc. All rights reserved. F5, F5 Networks, and the F5 logo are trademarks of F5,
Inc. in the U.S. and in certain other countries. Other F5 trademarks are identified at
f5.com. Any other products, services, or company names referenced herein may be
trademarks of the respective owners with no endorsement or affiliation, expressed or
implied, claimed by F5. | February 2023
5
Steps Yaml files have been uploaded and change path to /home/ubuntu and you will find
yaml files as below.
Follow step 1 – 3 to define a yaml file and subsequently deploy it. Optionally, you may
skip the step 1 and 2 and proceed directly to step 3 you can choose to deploy using
the yaml file that has been uploaded on to /home/ubuntu directory.
Step 1: On the K8s Control Plane, execute the following command: [Note: do not use
the same name for the yaml file that has already been created]
vi pod2.yaml
Step 2: Copy and paste content below. We are specifying a pod YAML configuration
file with parameter of
1) image: nginx
2) name: nginx
for pod creation.
apiVersion: v1
kind: Pod
metadata:
name: nginx
labels:
name: nginx
spec:
containers:
- name: nginx
image: nginx
Step 3: Issue command below to verify pods created and then delete the pod.
cat pod.yaml
kubectl apply -f pod.yaml
kubectl get pods
kubectl get pods -o wide
kubectl delete pods nginx
© F5, Inc. All rights reserved. F5, F5 Networks, and the F5 logo are trademarks of F5,
Inc. in the U.S. and in certain other countries. Other F5 trademarks are identified at
f5.com. Any other products, services, or company names referenced herein may be
trademarks of the respective owners with no endorsement or affiliation, expressed or
implied, claimed by F5. | February 2023
6
References
Pre-requisite -
© F5, Inc. All rights reserved. F5, F5 Networks, and the F5 logo are trademarks of F5,
Inc. in the U.S. and in certain other countries. Other F5 trademarks are identified at
f5.com. Any other products, services, or company names referenced herein may be
trademarks of the respective owners with no endorsement or affiliation, expressed or
implied, claimed by F5. | February 2023
7
Steps Follow step 1 – 3 to define a yaml file and subsequently deploy it. Optionally, you
may skip the step 1 and 2 and proceed directly to step 3 you can choose to deploy
using the yaml file that has been uploaded on to /home/ubuntu directory.
Step 1: On the K8 Control Plane, execute the following commands. [Note: do not
use the same name for the yaml file that has already been created]
vi deployment2.yaml
Step 2: Copy and paste content below. We are specifying a deployment YAML
configuration file with parameter of:
1) Replica of 3
2) image: nginx:1.14.2
3) name: nginx
4) ports: 80
for pod creation.
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
Step 3: Issue command below to verify pods created and then delete the
deployment.
cat deployment.yaml
© F5, Inc. All rights reserved. F5, F5 Networks, and the F5 logo are trademarks of F5,
Inc. in the U.S. and in certain other countries. Other F5 trademarks are identified at
f5.com. Any other products, services, or company names referenced herein may be
trademarks of the respective owners with no endorsement or affiliation, expressed or
implied, claimed by F5. | February 2023
8
kubectl apply -f deployment.yaml
kubectl get deployment -o wide
kubectl describe deployment nginx-deployment
kubectl delete deployment nginx-deployment
References
© F5, Inc. All rights reserved. F5, F5 Networks, and the F5 logo are trademarks of F5,
Inc. in the U.S. and in certain other countries. Other F5 trademarks are identified at
f5.com. Any other products, services, or company names referenced herein may be
trademarks of the respective owners with no endorsement or affiliation, expressed or
implied, claimed by F5. | February 2023
9
LAB 1.4 – NAMESPACES
Pre- -
requisite
© F5, Inc. All rights reserved. F5, F5 Networks, and the F5 logo are trademarks of F5,
Inc. in the U.S. and in certain other countries. Other F5 trademarks are identified at
f5.com. Any other products, services, or company names referenced herein may be
trademarks of the respective owners with no endorsement or affiliation, expressed or
implied, claimed by F5. | February 2023
10
Steps Follow step 1 – 3 to define a yaml file and subsequently deploy it. Optionally,
you may skip the step 1 and 2 and proceed directly to step 3 you can choose
to deploy using the yaml file that has been uploaded on to /home/ubuntu
directory.
vi namespace2.yaml
apiVersion: v1
kind: Namespace
metadata:
name: production
labels:
name: production
---
apiVersion: v1
kind: Pod
metadata:
name: mypod
namespace: production
labels:
name: mypod
spec:
containers:
- name: mypod
image: nginx
© F5, Inc. All rights reserved. F5, F5 Networks, and the F5 logo are trademarks of F5,
Inc. in the U.S. and in certain other countries. Other F5 trademarks are identified at
f5.com. Any other products, services, or company names referenced herein may be
trademarks of the respective owners with no endorsement or affiliation, expressed or
implied, claimed by F5. | February 2023
11
kubectl get pods
kubectl get pods -n production
kubectl describe pods mypod -n production
kubectl delete pods mypod -n production
You may need to change from the uploaded yaml file name to the yaml file
name you have created if you have gone through Step 1 to 3 during pod
creation.
© F5, Inc. All rights reserved. F5, F5 Networks, and the F5 logo are trademarks of F5,
Inc. in the U.S. and in certain other countries. Other F5 trademarks are identified at
f5.com. Any other products, services, or company names referenced herein may be
trademarks of the respective owners with no endorsement or affiliation, expressed or
implied, claimed by F5. | February 2023
12
References
© F5, Inc. All rights reserved. F5, F5 Networks, and the F5 logo are trademarks of F5,
Inc. in the U.S. and in certain other countries. Other F5 trademarks are identified at
f5.com. Any other products, services, or company names referenced herein may be
trademarks of the respective owners with no endorsement or affiliation, expressed or
implied, claimed by F5. | February 2023
13
LAB 1.5 – SERVICES
Objective Creating service
Pre- -
requisite
© F5, Inc. All rights reserved. F5, F5 Networks, and the F5 logo are trademarks of F5,
Inc. in the U.S. and in certain other countries. Other F5 trademarks are identified at
f5.com. Any other products, services, or company names referenced herein may be
trademarks of the respective owners with no endorsement or affiliation, expressed or
implied, claimed by F5. | February 2023
14
Steps Follow step 1 – 3 to define a yaml file and subsequently deploy it. Optionally,
you may skip the step 1 and 2 and proceed directly to step 3 you can choose
to deploy using the yaml file that has been uploaded on to /home/ubuntu
directory.
vi service2.yaml
Step 2: Copy and paste content below. We are specifying a service and pod
YAML configuration file with parameter of:
1) image: nginx
2) name: nginx
3) service type: NodePort
4) nodePort: 30080
for pod creation.
apiVersion: v1
kind: Pod
metadata:
name: nginx
labels:
name: nginx
spec:
containers:
- name: nginx
image: nginx
---
apiVersion: v1
kind: Service
metadata:
name: nginx
labels:
name: nginx
spec:
type: NodePort
ports:
- port: 80
nodePort: 30080
name: http
- port: 443
nodePort: 30443
© F5, Inc. All rights reserved. F5, F5 Networks, and the F5 logo are trademarks of F5,
Inc. in the U.S. and in certain other countries. Other F5 trademarks are identified at
f5.com. Any other products, services, or company names referenced herein may be
trademarks of the respective owners with no endorsement or affiliation, expressed or
implied, claimed by F5. | February 2023
15
name: https
selector:
name: nginx
© F5, Inc. All rights reserved. F5, F5 Networks, and the F5 logo are trademarks of F5,
Inc. in the U.S. and in certain other countries. Other F5 trademarks are identified at
f5.com. Any other products, services, or company names referenced herein may be
trademarks of the respective owners with no endorsement or affiliation, expressed or
implied, claimed by F5. | February 2023
16
References
© F5, Inc. All rights reserved. F5, F5 Networks, and the F5 logo are trademarks of F5,
Inc. in the U.S. and in certain other countries. Other F5 trademarks are identified at
f5.com. Any other products, services, or company names referenced herein may be
trademarks of the respective owners with no endorsement or affiliation, expressed or
implied, claimed by F5. | February 2023
17
Kubernetes Bootcamp 2023
© F5, Inc. All rights reserved. F5, F5 Networks, and the F5 logo are trademarks of F5,
Inc. in the U.S. and in certain other countries. Other F5 trademarks are identified at
f5.com. Any other products, services, or company names referenced herein may be
trademarks of the respective owners with no endorsement or affiliation, expressed or
implied, claimed by F5. | February 2023
18
Kubernetes Bootcamp 2023
© F5, Inc. All rights reserved. F5, F5 Networks, and the F5 logo are trademarks of F5,
Inc. in the U.S. and in certain other countries. Other F5 trademarks are identified at
f5.com. Any other products, services, or company names referenced herein may be
trademarks of the respective owners with no endorsement or affiliation, expressed or
implied, claimed by F5. | February 2023
19
NETWORKING IN KUBERNETES
Objective Within a node, CNI will automatically provision IP Addresses for the Pods
Pre-requisite -
Create a pod. The control plane should create a pod on the available worker node.
Check if the pod is created successfully (Status: Running) and note the worker node as well as the
IP Address. The parameter -o wide reveals the extended details of the pods which includes the Pod
IP Address as well as Node
Web shell to the work node and do a ping on the alpine’s Pod IP Address.
The ping should succeed. You have successfully communicated with a pod with its auto assigned IP
Address.
Bonus: You can choose to simulate a production pod life cycle and delete the pods
And recreating them. You will find that IP Addresses changes each time. Therefore, there is a need
to have a service that acts as a proxy for these ephemeral pods.
© F5, Inc. All rights reserved. F5, F5 Networks, and the F5 logo are trademarks of F5,
Inc. in the U.S. and in certain other countries. Other F5 trademarks are identified at
f5.com. Any other products, services, or company names referenced herein may be
trademarks of the respective owners with no endorsement or affiliation, expressed or
implied, claimed by F5. | February 2023
20
References
© F5, Inc. All rights reserved. F5, F5 Networks, and the F5 logo are trademarks of F5,
Inc. in the U.S. and in certain other countries. Other F5 trademarks are identified at
f5.com. Any other products, services, or company names referenced herein may be
trademarks of the respective owners with no endorsement or affiliation, expressed or
implied, claimed by F5. | February 2023
21
Steps Retrieve pod details of nginx
Remember, a pod is like a mini–Virtual Machine. You can shell into the pod
The pod name is not the fully qualified name. We can identify the fully qualified name by locating
DNS resolution file
cat /etc/resolv.conf
Let’s test it out. Install and use nslookup on the fully qualified service namespace (service name +
namespace). Notice the name server is as declared in the DNS resolution file, take note of the
translated IP Address which we will verify against the service details later.
apt-get update
apt-get install busybox
busybox nslookup nginx.default.svc.cluster.local
Let us verify the results with the service details. Exit back to control plane and inspect the service.
You will notice that the Service details matches the results from the nslookup.
exit
kubectl describe svc nginx
Bonus: What about the name server, who is exposing the translating service? (Hint: it is an out of
the box service)
References
© F5, Inc. All rights reserved. F5, F5 Networks, and the F5 logo are trademarks of F5,
Inc. in the U.S. and in certain other countries. Other F5 trademarks are identified at
f5.com. Any other products, services, or company names referenced herein may be
trademarks of the respective owners with no endorsement or affiliation, expressed or
implied, claimed by F5. | February 2023
22
Kubernetes Bootcamp 2023
© F5, Inc. All rights reserved. F5, F5 Networks, and the F5 logo are trademarks of F5,
Inc. in the U.S. and in certain other countries. Other F5 trademarks are identified at
f5.com. Any other products, services, or company names referenced herein may be
trademarks of the respective owners with no endorsement or affiliation, expressed or
implied, claimed by F5. | February 2023
23
LAB 1.8 – CLUSTERIP
Objective K8 Networking. K8 supports ClusterIP which provides communication between pods within the same
cluster
Worker 1:
busybox42(a)
busybox42(b)
© F5, Inc. All rights reserved. F5, F5 Networks, and the F5 logo are trademarks of F5,
Inc. in the U.S. and in certain other countries. Other F5 trademarks are identified at
f5.com. Any other products, services, or company names referenced herein may be
trademarks of the respective owners with no endorsement or affiliation, expressed or
implied, claimed by F5. | February 2023
24
Steps On the K8 Control Plane, let us create a file
Let us create Pod and Service using the following yaml configuration
Notice that up to now, our files are not step by step instructions, we configure with the end state in
mind. That is because Kubernetes configurations are Declarative in nature. The usual practice is to
deploy via files as it is repeatable as well as we can version control. Also note that we can deploy
several K8s object in a single file (demarcated by the three dashes---)
Copy the details into the file and run the deployment file using the command
kind: Deployment
metadata:
apiVersion: apps/v1
kind: Deployment
metadata:
name: cluster-ip-deployment
labels:
app: cluster-ip-deployment
spec:
replicas: 2
selector:
matchLabels:
app: nginx-app
template:
metadata:
labels:
app: nginx-app
spec:
containers:
- name: nginx-hello
image: nginxdemos/hello:plain-text
ports:
- containerPort: 80
© F5, Inc. All rights reserved. F5, F5 Networks, and the F5 logo are trademarks of F5,
Inc. in the U.S. and in certain other countries. Other F5 trademarks are identified at
f5.com. Any other products, services, or company names referenced herein may be
trademarks of the respective owners with no endorsement or affiliation, expressed or
implied, claimed by F5. | February 2023
25
---
apiVersion: v1
kind: Service
metadata:
name: cluster-ip-service
spec:
type: ClusterIP
selector:
app: nginx-app
ports:
- name: http
port: 80 # ClusterIp Service Port
Let’s test the ClusterIP Service. We can consume the service with a curl command by doing the
following (1) Find a pod in the same node. [If there are no pods in the same node, feel free to create
more pods via commands, we have learnt this in Lab 1.6 step 1] (2) we will shell into the chosen pod
and do a curl.
Ping / curl the ClusterIP service to simulate internal cluster service consumption
curl cluster-ip-service
You can also curl the service’s IP address directly. Inspect the service and note the IP Address and
Port. Do note that the target port is used to select the containerPort of the Pod, which is declared in
the deployment
exit
kubectl describe service
kubectl exec -ti [YourPodName] -- /bin/bash
© F5, Inc. All rights reserved. F5, F5 Networks, and the F5 logo are trademarks of F5,
Inc. in the U.S. and in certain other countries. Other F5 trademarks are identified at
f5.com. Any other products, services, or company names referenced herein may be
trademarks of the respective owners with no endorsement or affiliation, expressed or
implied, claimed by F5. | February 2023
26
curl <Service IP Address:Port> (e.g. 10.244.126.28:80)
Tip: you can run the following command to reverse the yaml file execution. Don’t do it unless you
intend to reverse to troubleshoot failure, we still require ClusterIP Service to compare differences
with NodePort.
References
Objective K8 supports NodePort which provides communication between pods of different clusters
© F5, Inc. All rights reserved. F5, F5 Networks, and the F5 logo are trademarks of F5,
Inc. in the U.S. and in certain other countries. Other F5 trademarks are identified at
f5.com. Any other products, services, or company names referenced herein may be
trademarks of the respective owners with no endorsement or affiliation, expressed or
implied, claimed by F5. | February 2023
27
Steps Let’s attempt to access a service type ClusterIP as a consumer outside the cluster. We have a
virtual machine that is outside the cluster, let’s use that.
Previously in Lab 1.8, a service has already been created with ClusterIP. On the K8 controlplane,
execute the following commands to retrieve the IP Address and port number. Copy it
Open new tab and web shell into the lab’s Jumphost / Client, try consuming the service with that IP
Address and port number
you should expect to receive error: Failed to connect XXX. Connection timeout
Now, let’s attempt to access a service type NodePort as a consumer outside the cluster
Previously in Lab 1.5, a service has already been created with NodePort.
Back in the master node web shell, Inspect the service, retrieve the communication details for us to
consume.
Retrieve the port number from the NodePort from the service and IP Address from the nodes’s
internal ip address. The pod should be created in both worker nodes so either node will work fine.
if service is not created, please use the following command and inspect again
© F5, Inc. All rights reserved. F5, F5 Networks, and the F5 logo are trademarks of F5,
Inc. in the U.S. and in certain other countries. Other F5 trademarks are identified at
f5.com. Any other products, services, or company names referenced herein may be
trademarks of the respective owners with no endorsement or affiliation, expressed or
implied, claimed by F5. | February 2023
28
References
© F5, Inc. All rights reserved. F5, F5 Networks, and the F5 logo are trademarks of F5,
Inc. in the U.S. and in certain other countries. Other F5 trademarks are identified at
f5.com. Any other products, services, or company names referenced herein may be
trademarks of the respective owners with no endorsement or affiliation, expressed or
implied, claimed by F5. | February 2023
29