Friday, April 29, 2022

Kubernetes daily use commands

 Here is a quick view on k8 commands which are ideally useful for daily interaction work

  • kubectl config get-contexts
    • display list of contexts
  • kubectx <env-name>
    • to switch the env
  • kubectl get nodes
    • Get all nodes
  • kubectl get namespaces
    • Get all namespaces for a environment
  • kubectl -n services get pod <pod-name>
    • Get specific pod details
  • kubectl -n services get pods
    • Get all pods
  • kubectl -n services delete pod <pod-name>
    • Delete specific pod name
  • -o wide
    • To get data in more details like which node etc
  • -o yaml
    • To open specific file to see the details
  • kubectl -n services describe pod <pod-name>
    • To see description of the pod
  • kubectl -n services exec -it  <pod-name> /bin/bash
    • Logging into the pod to see details at code level
  • kubectl -n services get hpa <hpd-pod-name>
    • To check hpa details if hpa enabled
  • kubectl -n services scale deploy <pod-name> --replicas=3
    • To manual scale
  • kubectl -n services get pods -o wide | grep ½
    • Get all pods which are in unhealthy state
  • kubectl -n services get deployment <pod-name> -o yaml
    • To check min/max replicas or any other data point w.r.t deployment
  • kubectl -n services get deployment <pod-name> -o yaml
    • To edit min/max replicas or any resources
  • kubectl -n services rollout restart deployment <po-name>
    • To restart a service
  • kubectl -n services logs <pod-name> -c install -f
    • This could be used if our pod is in Init stage. Gives us the keys that are missing from config(Search for nil after running this command)
  • kubectl -n configuration get pods
    • Consul and Vault status
  • stern -n configuration <name>
    • Check logs of vault
  • stern -n services <pod-name> -c <app-name> -t --since 1m
    • Prints logs of all the pods of last 1 min
  • stern -n services geolayers-api-primary -c geolayers-api -t --since 1m | grep '<text>' 
    • Prints log only for the text that is in grep
  • kubectl describe canary <pod-name> -n services
    • To check canary deployment of specific pod
  • kubectl get canary -n services
    • To check all pods for which canary enabled

Kubectl commands complete cheatsheet : https://kubernetes.io/docs/reference/kubectl/cheatsheet/

Happy Learning !! :)

Design Parking Garage

 Let's discuss designing parking garage as a problem statement.

At high level what all we need to consider and think about while designing a parking garage.

Product Requirements:

  • Need to be able to reserve a parking spot and receive some kind of ticket or receipt.
  • Need to be able to pay for a parking spot.
  • System needs to have a high consistency (no two people should be able to reseve the same spot at the same time).
  • 3 types of vehicles (compact, regular and large).
  • flat rate, but different rates depending of the type of parking.

APIs:
  • Public Endpoints
    • /reserve
      • Params : garage_id, start_time, end_time
      • Returns : (spot_id, reservation_id)
    • /payment
      • Params : reservation_id
      • Note : Likely using an existing API to handle (Stripe, Square etc...)
    • /cancel
      • Params : reservation_id
  • Internal Endpoints
    • /calculate_payment
      • Params : reservation_id
    • /freespots
      • Params : garage_id, vehicle_type, time
      • Note : Smaller vehicles can fit into larger spots if necessary and therefore should be included in the overall number of spots
    • /allocate_spot
      • Params : garage_id, vehicle_type, time
    • /create_account
      • Params ; email, password, first_name, last_name
    • /login
      • Params : email, password

Data Schema:
  • Reservations
    • id : primary key
    • garage_id : foreign key
    • spot_id : foreign key
    • start: timestamp
    • end : timestamp
    • paid : boolean
  • Garage
    • id : primary key
    • zipcode : varchar
    • rate_compact : decimal
    • rate_regular : decimal
    • rate_large : decimal
  • Spots
    • id : primary key
    • garage_id : foreign key
    • vehicle_type : enum
    • status : enum
  • Users
    • id : primary key
    • email : varchar
    • password : varchar (note that this probably SHA-256 hash)
    • first_name : varchar
    • last_name : varchar
  • Vehicles
    • id : primary key
    • user_id : foreign key
    • licence : varchar



My Profile

My photo
can be reached at 09916017317