Kubernetes - Best practices


Prabhat Sharma


@hiprabhat
@prabhatsharma

Containers

  • Use small containers for production. Possibly alpine based that do not contain extra items.
  • Avoid building your containers based on distros like ubuntu
  • If possible, use multi-stage docker files.
  • Run a single process per container.
  • Optimize for docker build cache. Create images with common layers.
  • Be careful in using public images. Scan images for vulnerabilities using tools like Clair, Anchore, etc...

Kubernetes

  1. Do not create naked pods. Always use ReplicaSets or Deployments(or StatefulSets)
  2. Always specify resource limits for containers in pods.
  3. use namespaces to organize your applications.
  4. Store your YAML definition files in version control.
  5. Do not use latest tag in your deployment files.
  6. Follow 12 factor app principles.
  7. Sepcify non-root user for running containers in pods

Building APIs

  • Keep your base URL simple and intuitive
  • Nouns are good; verbs are bad. Keep verbs out of your base URLs
  • Version your APIs. https://api.site.com/v1/products
  • Use HTTP verbs to operate on the collections and elements (GET, POST, PUT, DELETE)
  • Error handling: Use HTTP status codes, provide easy to read messages.
References: Web API Design: Crafting Interfaces that Developers Love

HTTP status codes - Cheat sheet

1xx - Hold on
2xx - Here you go
3xx - Go away
4xx - You f****d up
5xx - I f****d up

Thank You

Questions?