Skip to content

Latest commit

 

History

History
89 lines (59 loc) · 3.38 KB

K8s-Deployment.md

File metadata and controls

89 lines (59 loc) · 3.38 KB

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")

    image

  • Create Yaml file (deployment1.yaml) in your directory and copy the below definition into the file:

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:

image

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

image

  • Scale up to 5 replicas:

image

  • Scale down to 3 replicas:

image

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

image

  • Connect one of the pod with bash:

image

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

image

  • Ping other pods:

image

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

image

image

  • Delete deployment:

image