K8s-Deployment.md
March 23, 2023 ยท View on GitHub
LAB: K8s Deployment - Scale Up/Down - Bash Connection - Port Forwarding
This scenario shows:
- how to create deployment,
- how to get detail information of deployment and pods,
- how to scale up and down of deployment,
- how to connect to the one of the pods with bash,
- how to show ethernet interfaces of the pod and ping other pods,
- how to forward ports to see nginx server page using browser.
Steps
-
Run minikube (in this scenario, K8s runs on WSL2- Ubuntu 20.04) ("minikube start")

-
Create Yaml file (deployment1.yaml) in your directory and copy the below definition into the file.
-
File: https://github.com/omerbsezer/Fast-Kubernetes/blob/main/labs/deployment/deployment1.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: firstdeployment
labels:
team: development
spec:
replicas: 3
selector: # deployment selector
matchLabels: # deployment selects "app:frontend" pods, monitors and traces these pods
app: frontend # if one of the pod is killed, K8s looks at the desire state (replica:3), it recreats another pods to protect number of replicas
template:
metadata:
labels: # pod labels, if the deployment selector is same with these labels, deployment follows pods that have these labels
app: frontend # key: value
spec:
containers:
- name: nginx
image: nginx:latest # image download from DockerHub
ports:
- containerPort: 80 # open following ports

- Create deployment and list the deployment's pods:

- Delete one of the pod, then K8s automatically creates new pod:

- Scale up to 5 replicas:

- Scale down to 3 replicas:

- Get more information about pods (ip, node):

- Connect one of the pod with bash:

- To install ifconfig, run: "apt update", "apt install net-tools"
- To install ping, run: "apt install iputils-ping"
- Show ethernet interfaces:

- Ping other pods:

- Port-forward from one of the pod to host (8085:80):

- On the browser, goto http://127.0.0.1:8085/

- Delete deployment:
