Skip to content

Latest commit

 

History

History
93 lines (61 loc) · 3.58 KB

K8s-Deployment.md

File metadata and controls

93 lines (61 loc) · 3.58 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

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

image

  • 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