Kubernetes for Developers

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

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.

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

  1. Title Page
  2. Copyright and Credits
    1. Kubernetes for Developers
    1. Why subscribe?
    2. PacktPub.com
    1. About the author
    2. About the reviewers
    3. Packt is searching for authors like you
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
      1. Download the example code files
      2. Conventions used
      1. Reviews
      1. What you need for development
        1. Optional tools
        1. Namespaces
        2. Writing your code for Pods and Containers
        1. Networks
        2. Controllers
        1. Representing Kubernetes resources
        1. Container images
          1. Container registries
          1. Dockerfile commands
          1. Building the container
          2. Running your container
            1. Pod name
            2. Port forwarding
            3. Proxy
            4. How did the proxy know to connect to port 5000 on the container?
            1. Building the container
            2. Running your container
              1. Port forwarding
              2. Proxy
              1. Practical notes for writing software to run in a container
                1. Getting options for your executable code
                2. Practical notes for building container images
                3. Sending output from your program
                1. Pods with more than one container
                2. Streaming the logs
                3. Previous logs
                4. Timestamps
                1. Interactive deployment of an image
                2. Attaching to a running Pod
                3. Running a second process in a container
                1. Organization of labels
                1. Viewing labels
                2. Listing resources with labels using kubectl
                3. Automatic labels and selectors
                1. Defining a service resource
                2. Endpoints
                3. Service type – ExternalName
                4. Headless service
                1. DNS for services
                1. Service type – LoadBalancer
                2. Service type – NodePort
                3. Minikube service
                1. Finding the Redis service
                2. Using Redis from Python
                3. Updating the Flask deployment
                1. Rollout history
                2. Rollout undo
                3. Updating with the kubectl set command
                1. Imperative versus declarative commands
                  1. A wall of YAML
                  2. Creating a simple deployment
                  1. ImagePullPolicy
                  2. Audit trail
                  1. Exposing labels and annotations in Pods
                  1. Creating a ConfigMap
                  2. Managing ConfigMaps
                  3. Exposing the configuration into your container images
                    1. Environment variables
                    2. Exposing ConfigMap as files inside the container
                    1. Exposing Secrets into a container
                    2. Secrets and security – how secret are the secrets?
                    1. SIDEBAR – JSONPATH
                    2. Using the ConfigMap within Python/Flask
                    1. Pod lifecycle
                      1. Container lifecycle
                      2. Deployments, ReplicaSets, and Pods
                      3. Getting a snapshot of the current state
                      1. Liveness probe
                      2. Readiness probe
                      3. Adding a probe to our Python example
                        1. Running the Python probes example
                        1. Quick interactive testing
                        1. SIGTERM in Python
                        2. SIGTERM in Node.js
                        1. Job
                        2. CronJob
                        3. A worker queue example with Python and Celery
                          1. Celery worker example
                            1. RabbitMQ and configuration
                            2. Celery worker
                            1. Volumes
                            2. PersistentVolume and PersistentVolumeClaim
                            1. A Node.js example using Stateful Set
                            1. Built-in metrics with Kubernetes
                            2. Kubernetes concept – Quality of Service
                              1. Choosing requests and limits for your containers
                              1. Installing Helm
                              2. Installing Prometheus using Helm
                              3. Viewing metrics with Prometheus 
                              1. Flask metrics with Prometheus
                              2. Node.js metrics with Prometheus
                              3. Service signals in Prometheus
                              1. A Kubernetes concept – DaemonSet
                              2. Installing and using Elasticsearch, Fluentd, and Kibana
                                1. Log aggregation with EFK
                                1. Filtering by app
                                2. Lucene query language
                                3. Running Kibana in production
                                1. Spans and traces
                                2. Architecture of Jaeger distributed tracing
                                3. Trying out Jaeger
                                1. Adding a tracing collector to your pod
                                2. Add the libraries and code to generate traces
                                3. Considerations for adding tracing
                                1. Testing strategies using Kubernetes
                                  1. Reviewing resources needed for testing
                                  2. Patterns of using Kubernetes with testing
                                    1. Tests local and system-under-test in Kubernetes
                                    2. Tests local and system-under-test in Kubernetes namespaces
                                    3. Tests in Kubernetes and system-under-test in Kubernetes namespaces
                                    1. PyTest and pytest-dependency
                                    2. PyTest fixtures and the python-kubernetes client
                                    3. Waiting for state changes
                                    4. Accessing the deployment
                                    1. Node.js tests and dependencies with mocha and chai
                                    2. Validating the cluster health
                                    3. Deploying with kubectl
                                    4. Waiting for the pods to become available
                                    5. Interacting with the deployment
                                    1. Example – using Minikube with Travis.CI
                                      1. Next steps
                                      1. Installing Jenkins using Helm
                                      2. Accessing Jenkins
                                      3. Updating Jenkins
                                      4. Example pipeline
                                      5. Next steps with pipelines
                                      1. Common errors and how to resolve them
                                        1. Error validating data
                                          1. Navigating the documentation
                                          1. Starting and inspecting the image
                                          2. Adding your own setup to the container 
                                          1. Missing resources
                                          1. Linters
                                          2. Helm
                                          3. ksonnet
                                          4. Brigade
                                          5. skaffold
                                          6. img
                                          7. Draft
                                          8. ksync
                                          9. Telepresence
                                          1. Slack
                                          2. YouTube
                                          3. Stack Overflow
                                          4. Mailing lists and forums
                                          1. 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