Kubernetes for Developers
Read it now on the O’Reilly learning platform with a 10-day free trial.
O’Reilly members get unlimited access to books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.
Book description
A developer's field-guide to designing scalable services using Kubernetes
- Develop and run your software using containers within a Kubernetes environment
- Get hands-on experience of using Kubernetes with DevOps concepts such as continuous integration, benchmark testing, monitoring, and so on
- Pragmatic example-based approach showing how to use Kubernetes in the development process
If you are a full-stack or back-end software developers interested, curious, or being asked to test as well as run the code you're creating, you can leverage Kubernetes to make that process simpler and consistent regardless of where you deploy. If you're looking for developer focused examples in NodeJS and Python for how to build, test, deploy, and run your code with Kubernetes, this is perfect for you.
- Build your software into containers
- Deploy and debug software running in containers within Kubernetes
- Declare and add configuration through Kubernetes
- Define how your application fits together, using internal and external services
- Add feedback to your code to help Kubernetes manage your services
- Monitor and measure your services through integration testing and in production deployments
Kubernetes is documented and typically approached from the perspective of someone running software that has already been built. Kubernetes may also be used to enhance the development process, enabling more consistent testing and analysis of code to help developers verify not only its correctness, but also its efficiency. This book introduces key Kubernetes concepts, coupled with examples of how to deploy and use them with a bit of Node.js and Python example code, so that you can quickly replicate and use that knowledge.
You will begin by setting up Kubernetes to help you develop and package your code. We walk you through the setup and installation process before working with Kubernetes in the development environment. We then delve into concepts such as automating your build process, autonomic computing, debugging, and integration testing. This book covers all the concepts required for a developer to work with Kubernetes.
By the end of this book, you will be in a position to use Kubernetes in development ecosystems.
Style and approach
This book will cover examples using NodeJS and Python that walk you through building containers, defining your deployments, deploying, debugging, testing, and generally interacting with your code running on Kubernetes. The examples are focused on common development needs, and include pragmatic advice and the explanations behind that advice.
Show and hide more
Table of contents Product information
Table of contents
- Title Page
- Copyright and Credits
- Kubernetes for Developers
- Why subscribe?
- PacktPub.com
- About the author
- About the reviewers
- Packt is searching for authors like you
- Who this book is for
- What this book covers
- To get the most out of this book
- Download the example code files
- Conventions used
- Reviews
- What you need for development
- Optional tools
- Namespaces
- Writing your code for Pods and Containers
- Networks
- Controllers
- Representing Kubernetes resources
- Container images
- Container registries
- Dockerfile commands
- Building the container
- Running your container
- Pod name
- Port forwarding
- Proxy
- How did the proxy know to connect to port 5000 on the container?
- Building the container
- Running your container
- Port forwarding
- Proxy
- Practical notes for writing software to run in a container
- Getting options for your executable code
- Practical notes for building container images
- Sending output from your program
- Pods with more than one container
- Streaming the logs
- Previous logs
- Timestamps
- Interactive deployment of an image
- Attaching to a running Pod
- Running a second process in a container
- Organization of labels
- Viewing labels
- Listing resources with labels using kubectl
- Automatic labels and selectors
- Defining a service resource
- Endpoints
- Service type – ExternalName
- Headless service
- DNS for services
- Service type – LoadBalancer
- Service type – NodePort
- Minikube service
- Finding the Redis service
- Using Redis from Python
- Updating the Flask deployment
- Rollout history
- Rollout undo
- Updating with the kubectl set command
- Imperative versus declarative commands
- A wall of YAML
- Creating a simple deployment
- ImagePullPolicy
- Audit trail
- Exposing labels and annotations in Pods
- Creating a ConfigMap
- Managing ConfigMaps
- Exposing the configuration into your container images
- Environment variables
- Exposing ConfigMap as files inside the container
- Exposing Secrets into a container
- Secrets and security – how secret are the secrets?
- SIDEBAR – JSONPATH
- Using the ConfigMap within Python/Flask
- Pod lifecycle
- Container lifecycle
- Deployments, ReplicaSets, and Pods
- Getting a snapshot of the current state
- Liveness probe
- Readiness probe
- Adding a probe to our Python example
- Running the Python probes example
- Quick interactive testing
- SIGTERM in Python
- SIGTERM in Node.js
- Job
- CronJob
- A worker queue example with Python and Celery
- Celery worker example
- RabbitMQ and configuration
- Celery worker
- Volumes
- PersistentVolume and PersistentVolumeClaim
- A Node.js example using Stateful Set
- Built-in metrics with Kubernetes
- Kubernetes concept – Quality of Service
- Choosing requests and limits for your containers
- Installing Helm
- Installing Prometheus using Helm
- Viewing metrics with Prometheus
- Flask metrics with Prometheus
- Node.js metrics with Prometheus
- Service signals in Prometheus
- A Kubernetes concept – DaemonSet
- Installing and using Elasticsearch, Fluentd, and Kibana
- Log aggregation with EFK
- Filtering by app
- Lucene query language
- Running Kibana in production
- Spans and traces
- Architecture of Jaeger distributed tracing
- Trying out Jaeger
- Adding a tracing collector to your pod
- Add the libraries and code to generate traces
- Considerations for adding tracing
- Testing strategies using Kubernetes
- Reviewing resources needed for testing
- Patterns of using Kubernetes with testing
- Tests local and system-under-test in Kubernetes
- Tests local and system-under-test in Kubernetes namespaces
- Tests in Kubernetes and system-under-test in Kubernetes namespaces
- PyTest and pytest-dependency
- PyTest fixtures and the python-kubernetes client
- Waiting for state changes
- Accessing the deployment
- Node.js tests and dependencies with mocha and chai
- Validating the cluster health
- Deploying with kubectl
- Waiting for the pods to become available
- Interacting with the deployment
- Example – using Minikube with Travis.CI
- Next steps
- Installing Jenkins using Helm
- Accessing Jenkins
- Updating Jenkins
- Example pipeline
- Next steps with pipelines
- Common errors and how to resolve them
- Error validating data
- Navigating the documentation
- Starting and inspecting the image
- Adding your own setup to the container
- Missing resources
- Linters
- Helm
- ksonnet
- Brigade
- skaffold
- img
- Draft
- ksync
- Telepresence
- Slack
- YouTube
- Stack Overflow
- Mailing lists and forums
- Leave a review - let other readers know what you think
Show and hide more
Product information
- Title: Kubernetes for Developers
- Author(s): Joseph Heck
- Release date: April 2018
- Publisher(s): Packt Publishing
- ISBN: 9781788834759