0%

Book Description

Leverage Kubernetes and container architecture to successfully run production-ready workloads

Key Features

  • Implement Kubernetes to orchestrate and scale applications proficiently
  • Leverage the latest features of Kubernetes to resolve common as well as complex problems in a cloud-native environment
  • Gain hands-on experience in securing, monitoring, and troubleshooting your application

Book Description

Kubernetes is a popular open source orchestration platform for managing containers in a cluster environment. With this Kubernetes cookbook, you'll learn how to implement Kubernetes using a recipe-based approach. The book will prepare you to create highly available Kubernetes clusters on multiple clouds such as Amazon Web Services (AWS), Google Cloud Platform (GCP), Azure, Alibaba, and on-premises data centers.

Starting with recipes for installing and configuring Kubernetes instances, you'll discover how to work with Kubernetes clients, services, and key metadata. You'll then learn how to build continuous integration/continuous delivery (CI/CD) pipelines for your applications, and understand various methods to manage containers. As you advance, you'll delve into Kubernetes' integration with Docker and Jenkins, and even perform a batch process and configure data volumes. You'll get to grips with methods for scaling, security, monitoring, logging, and troubleshooting. Additionally, this book will take you through the latest updates in Kubernetes, including volume snapshots, creating high availability clusters with kops, running workload operators, new inclusions around kubectl and more.

By the end of this book, you'll have developed the skills required to implement Kubernetes in production and manage containers proficiently.

What you will learn

  • Deploy cloud-native applications on Kubernetes
  • Automate testing in the DevOps workflow
  • Discover and troubleshoot common storage issues
  • Dynamically scale containerized services to manage fluctuating traffic needs
  • Understand how to monitor your containerized DevOps environment
  • Build DevSecOps into CI/CD pipelines

Who this book is for

This Kubernetes book is for developers, IT professionals, and DevOps engineers and teams who want to use Kubernetes to manage, scale, and orchestrate applications in their organization. Basic understanding of Kubernetes and containerization is necessary.

Table of Contents

  1. Title Page
  2. Copyright and Credits
    1. Kubernetes A Complete DevOps Cookbook
  3. Dedication
  4. About Packt
    1. Why subscribe?
  5. Contributors
    1. About the author
    2. About the reviewer
    3. Packt is searching for authors like you
  6. Preface
    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. Download the color images
      3. Code in Action
      4. Conventions used
    4. Sections
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
      5. See also
    5. Get in touch
      1. Reviews
  7. Building Production-Ready Kubernetes Clusters
    1. Technical requirements
    2. Configuring a Kubernetes cluster on Amazon Web Services 
      1. Getting ready
      2. How to do it…
        1. Installing the command-line tools to configure AWS services
        2. Installing kops to provision a Kubernetes cluster
        3. Provisioning a Kubernetes cluster on Amazon EC2
        4. Provisioning a managed Kubernetes cluster on Amazon EKS
      3. How it works...
      4. There's more…
        1. Using the AWS Shell
        2. Using a gossip-based cluster
        3. Using different regions for an S3 bucket
        4. Editing the cluster configuration
        5. Deleting your cluster
        6. Provisioning an EKS cluster using the Amazon EKS Management Console
        7. Deploying Kubernetes Dashboard
      5. See also
    3. Configuring a Kubernetes cluster on Google Cloud Platform
      1. Getting ready
      2. How to do it…
        1. Installing the command-line tools to configure GCP services
        2. Provisioning a managed Kubernetes cluster on GKE
        3. Connecting to Google Kubernetes Engine (GKE) clusters
      3. How it works…
      4. There's more…
        1. Using Google Cloud Shell
        2. Deploying with a custom network configuration
        3. Deleting your cluster
        4. Viewing the Workloads dashboard
      5. See also
    4. Configuring a Kubernetes cluster on Microsoft Azure
      1. Getting ready
      2. How to do it…
        1. Installing the command-line tools to configure Azure services
        2. Provisioning a managed Kubernetes cluster on AKS
        3. Connecting to AKS clusters
      3. How it works…
      4. There's more…
        1. Deleting your cluster
        2. Viewing Kubernetes Dashboard
      5. See also
    5. Configuring a Kubernetes cluster on Alibaba Cloud
      1. Getting ready
      2. How to do it…
        1. Installing the command-line tools to configure Alibaba Cloud services
        2. Provisioning a highly available Kubernetes cluster on Alibaba Cloud
        3. Connecting to Alibaba Container Service clusters
      3. How it works…
      4. There's more…
    6. Configuring and managing Kubernetes clusters with Rancher
      1. Getting ready
      2. How to do it…
        1. Installing Rancher Server
        2. Deploying a Kubernetes cluster
        3. Importing an existing cluster
        4. Enabling cluster and node providers
      3. How it works…
      4. There's more…
        1. Bind mounting a host volume to keep data
        2. Keeping user volumes persistent
        3. Running Rancher on the same Kubernetes nodes
      5. See also
    7. Configuring Red Hat OpenShift 
      1. Getting ready
      2. How to do it…
        1. Downloading OpenShift binaries
        2. Provisioning an OpenShift cluster
        3. Connecting to OpenShift clusters
      3. How it works…
      4. There's more…
        1. Deleting your cluster
      5. See also
    8. Configuring a Kubernetes cluster using Ansible
      1. Getting ready
      2. How to do it…
        1. Installing Ansible
        2. Provisioning a Kubernetes cluster using an Ansible playbook
        3. Connecting to the Kubernetes cluster
      3. See also
    9. Troubleshooting installation issues
      1. How to do it…
      2. How it works…
      3. There's more…
        1. Setting log levels
      4. See also
  8. Operating Applications on Kubernetes
    1. Technical requirements
    2. Deploying workloads using YAML files
      1. Getting ready
      2. How to do it…
        1. Creating a Deployment
        2. Verifying a Deployment
        3. Editing a Deployment
        4. Rolling back a deployment
        5. Deleting a Deployment
      3. How it works...
      4. See also
    3. Deploying workloads using Kustomize
      1. Getting ready
      2. How to do it…
        1. Validating the Kubernetes cluster version
        2. Generating Kubernetes resources from files
        3. Creating a base for a development and production Deployment
      3. How it works...
      4. See also
    4. Deploying workloads using Helm charts
      1. Getting ready
      2. How to do it…
        1. Installing Helm 2.x
        2. Installing an application using Helm charts
        3. Searching for an application in Helm repositories
        4. Upgrading an application using Helm
        5. Rolling back an application using Helm
        6. Deleting an application using Helm
        7. Adding new Helm repositories
        8. Building a Helm chart
      3. How it works...
      4. See also
    5. Deploying and operating applications using Kubernetes operators
      1. Getting ready
      2. How to do it…
        1. Installing KUDO and the KUDO kubectl plugin
        2. Installing the Apache Kafka Operator using KUDO
        3. Installing Operator Lifecycle Manager
        4. Installing the Zalando PostgreSQL Operator
      3. See also
    6. Deploying and managing the life cycle of Jenkins X
      1. Getting ready
      2. How to do it...
        1. Installing the Jenkins X CLI
        2. Creating a Jenkins X Kubernetes cluster
        3. Verifying Jenkins X components
        4. Switching Kubernetes clusters
        5. Validating cluster conformance
      3. How it works...
      4. There's more…
        1. Importing an application
        2. Upgrading a Jenkins X application
        3. Deleting a Jenkins X Kubernetes cluster
      5. See also
    7. Deploying and managing the life cycle of GitLab
      1. Getting ready
      2. How to do it...
        1. Installing GitLab using Helm
        2. Connecting to the GitLab dashboard
        3. Creating the first GitLab user
        4. Upgrading GitLab
      3. How it works...
      4. There's more…
        1. Using your own wildcard certificate
        2. Using autogenerated self-signed certificates
        3. Enabling the GitLab Operator
        4. Deleting GitLab
      5. See also
  9. Building CI/CD Pipelines
    1. Technical requirements
    2. Creating a CI/CD pipeline in Jenkins X
      1. Getting ready
      2. How to do it…
        1. Connecting to Jenkins Pipeline Console
        2. Importing an application as a pipeline
        3. Checking application status
        4. Promoting an application to production
        5. Creating a pipeline using a QuickStart application
      3. How it works...
    3. Creating a CI/CD pipeline in GitLab
      1. Getting ready
      2. How to do it…
        1. Creating a project using templates
        2. Importing an existing project from GitHub
        3. Enabling Auto DevOps
        4. Enabling Kubernetes cluster integration
        5. Creating a pipeline using Auto DevOps
        6. Incrementally rolling out applications to production
      3. How it works...
      4. There's more...
        1. GitLab Web IDE
        2. Monitoring environments
      5. See also
    4. Creating a CI/CD pipeline in CircleCI
      1. Getting ready
      2. How to do it...
        1. Getting started with CircleCI
        2. Deploying changes to a Kubernetes cluster on EKS
      3. How it works...
      4. See also
    5. Setting up a CI/CD pipeline using GitHub Actions
      1. Getting ready
      2. How to do it...
        1. Creating a workflow file
        2. Creating a basic Docker build workflow
        3. Building and publishing images to Docker Registry
        4. Adding a workflow status badge
      3. See also
    6. Setting up a CI/CD pipeline on Amazon Web Services
      1. Getting ready
      2. How to do it...
        1. Creating an AWS CodeCommit code repository
        2. Building projects with AWS CodeBuild
        3. Creating an AWS CodeDeploy deployment
        4. Building a pipeline with AWS CodePipeline
      3. How it works...
      4. See also
    7. Setting up a CI/CD pipeline with Spinnaker on Google Cloud Build
      1. Getting ready
      2. How to do it...
        1. Installing and configuring the Spin CLI
        2. Configuring a service account for the CI/CD
        3. Configuring events to trigger a pipeline
        4. Deploying Spinnaker using Helm
        5. Creating a Google Cloud Source code repository
        6. Building projects with Google Cloud Build
        7. Configuring a Spinnaker pipeline
        8. Rolling out an application to production
      3. See also
    8. Setting up a CI/CD pipeline on Azure DevOps
      1. Getting ready
      2. How to do it...
        1. Getting started with Azure DevOps
        2. Configuring Azure Pipelines
        3. Deploying changes to an AKS cluster
      3. How it works...
      4. See also
  10. Automating Tests in DevOps
    1. Technical requirements
    2. Building event-driven automation with StackStorm
      1. Getting ready
      2. How to do it…
        1. Installing StackStorm
        2. Accessing the StackStorm UI
        3. Using the st2 CLI
        4. Defining a rule
        5. Deploying a rule
      3. See also
    3. Automating tests with the Litmus framework
      1. Getting ready
      2. How to do it…
        1. Installing the Litmus Operator
        2. Using Chaos Charts for Kubernetes
        3. Creating a pod deletion chaos experiment
        4. Reviewing chaos experiment results
        5. Viewing chaos experiment logs
      3. How it works...
      4. See also
    4. Automating Chaos Engineering with Gremlin
      1. Getting ready
      2. How to do it…
        1. Setting up Gremlin credentials
        2. Installing Gremlin on Kubernetes
        3. Creating a CPU attack against a Kubernetes worker
        4. Creating a node shutdown attack against a Kubernetes worker
        5. Running predefined scenario-based attacks
        6. Deleting Gremlin from your cluster
      3. How it works...
      4. See also
    5. Automating your code review with Codacy
      1. Getting ready
      2. How to do it…
        1. Accessing the Project Dashboard
        2. Reviewing commits and PRs
        3. Viewing issues by category
        4. Adding a Codacy badge to your repository
      3. See also
    6. Detecting bugs and anti-patterns with SonarQube
      1. Getting ready
      2. How to do it…
        1. Installing SonarQube using Helm
        2. Accessing the SonarQube Dashboard
        3. Creating a new user and tokens
        4. Enabling quality profiles
        5. Adding a project
        6. Reviewing a project's quality
        7. Adding marketplace plugins
        8. Deleting SonarQube from your cluster
      3. How it works...
      4. See also
    7. Detecting license compliance issues with FOSSA
      1. Getting ready
      2. How to do it…
        1. Adding projects to FOSSA
        2. Triaging licensing issues
        3. Adding a FOSSA badge to your project
  11. Preparing for Stateful Workloads
    1. Technical requirements
    2. Managing Amazon EBS volumes in Kubernetes
      1. Getting ready
      2. How to do it…
        1. Creating an EBS storage class
        2. Changing the default storage class
        3. Using EBS volumes for persistent storage
        4. Using EBS storage classes to dynamically create persistent volumes
        5. Deleting EBS persistent volumes
        6. Installing the EBS CSI driver to manage EBS volumes
      3. See also
    3. Managing GCE PD volumes in Kubernetes
      1. Getting ready
      2. How to do it…
        1. Creating a GCE persistent disk storage class
        2. Changing the default storage class
        3. Using GCE PD volumes for persistent storage
        4. Using GCE PD storage classes to create dynamic persistent volumes
        5. Deleting GCE PD persistent volumes
        6. Installing the GCP Compute PD CSI driver to manage PD volumes
      3. How it works...
      4. See also
    4. Managing Azure Disk volumes in Kubernetes
      1. Getting ready
      2. How to do it…
        1. Creating an Azure Disk storage class
        2. Changing the default storage class to ZRS
        3. Using Azure Disk storage classes to create dynamic PVs
        4. Deleting Azure Disk persistent volumes
        5. Installing the Azure Disk CSI driver
      3. See also
    5. Configuring and managing persistent storage using Rook
      1. Getting ready
      2. How to do it…
        1. Installing a Ceph provider using Rook
        2. Creating a Ceph cluster
        3. Verifying a Ceph cluster's health
        4. Create a Ceph block storage class
        5. Using a Ceph block storage class to create dynamic PVs
      3. See also
    6. Configuring and managing persistent storage using OpenEBS
      1. Getting ready
      2. How to do it…
        1. Installing iSCSI client prerequisites
        2. Installing OpenEBS
        3. Using ephemeral storage to create persistent volumes
        4. Creating storage pools
        5. Creating OpenEBS storage classes
        6. Using an OpenEBS storage class to create dynamic PVs
      3. How it works...
      4. See also
    7. Setting up NFS for shared storage on Kubernetes
      1. Getting ready
      2. How to do it…
        1. Installing NFS prerequisites
        2. Installing an NFS provider using a Rook NFS operator
        3. Using a Rook NFS operator storage class to create dynamic NFS PVs
        4. Installing an NFS provisioner using OpenEBS
        5. Using the OpenEBS NFS provisioner storage class to create dynamic NFS PVs
      3. See also
    8. Troubleshooting storage issues
      1. Getting ready
      2. How to do it…
        1. Persistent volumes in the pending state
        2. A PV is stuck once a PVC has been deleted
  12. Disaster Recovery and Backup
    1. Technical requirements
    2. Configuring and managing S3 object storage using MinIO
      1. Getting ready
      2. How to do it…
        1. Creating a deployment YAML manifest
        2. Creating a MinIO S3 service
        3. Accessing the MinIO web user interface
      3. How it works...
      4. See also
    3. Managing Kubernetes Volume Snapshots and restore
      1. Getting ready
      2. How to do it…
        1. Enabling feature gates
        2. Creating a volume snapshot via CSI
        3. Restoring a volume from a snapshot via CSI
        4. Cloning a volume via CSI
      3. How it works...
      4. See also
    4. Application backup and recovery using Velero
      1. Getting ready
      2. How to do it…
        1. Installing Velero
        2. Backing up an application
        3. Restoring an application
        4. Creating a scheduled backup
        5. Taking a backup of an entire namespace
        6. Viewing backups with MinIO
        7. Deleting backups and schedules
      3. How it works...
      4. See also
    5. Application backup and recovery using Kasten
      1. Getting ready
      2. How to do it…
        1. Installing Kasten
        2. Accessing the Kasten Dashboard
        3. Backing up an application
        4. Restoring an application
      3. How it works...
      4. See also
    6. Cross-cloud application migration
      1. Getting ready
      2. How to do it…
        1. Creating an export profile in Kasten
        2. Exporting a restore point in Kasten
        3. Creating an import profile in Kasten
        4. Migrating an application in Kasten
        5. Importing clusters into OpenEBS Director
        6. Migrating an application in OpenEBS Director
      3. See also
  13. Scaling and Upgrading Applications
    1. Technical requirements
    2. Scaling applications on Kubernetes
      1. Getting ready
      2. How to do it…
        1. Validating the installation of Metrics Server
        2. Manually scaling an application
        3. Autoscaling applications using a Horizontal Pod Autoscaler
      3. How it works...
      4. See also
    3. Assigning applications to nodes
      1. Getting ready
      2. How to do it…
        1. Labeling nodes
        2. Assigning pods to nodes using nodeSelector
        3. Assigning pods to nodes using node and inter-pod Affinity
      3. How it works...
      4. See also
    4. Creating an external load balancer
      1. Getting ready
      2. How to do it…
        1. Creating an external cloud load balancer
        2. Finding the external address of the service
      3. How it works...
      4. See also
    5. Creating an ingress service and service mesh using Istio
      1. Getting ready
      2. How to do it…
        1. Installing Istio using Helm
        2. Verifying the installation
        3. Creating an ingress gateway
      3. How it works...
      4. There's more…
        1. Deleting Istio
      5. See also
    6. Creating an ingress service and service mesh using Linkerd
      1. Getting ready
      2. How to do it…
        1. Installing the Linkerd CLI
        2. Installing Linkerd
        3. Verifying a Linkerd deployment
        4. Adding Linkerd to a service
      3. There's more…
        1. Accessing the dashboard
        2. Deleting Linkerd
      4. See also
    7. Auto-healing pods in Kubernetes
      1. Getting ready
      2. How to do it…
        1. Testing self-healing pods
        2. Adding liveness probes to pods
      3. How it works...
      4. See also
    8. Managing upgrades through blue/green deployments
      1. Getting ready
      2. How to do it…
        1. Creating the blue deployment
        2. Creating the green deployment
        3. Switching traffic from blue to green
      3. See also
  14. Observability and Monitoring on Kubernetes
    1. Technical requirements
    2. Monitoring in Kubernetes
      1. Getting ready
      2. How to do it…
        1. Adding metrics using Kubernetes Metrics Server
        2. Monitoring metrics using the CLI
        3. Monitoring metrics using Kubernetes Dashboard
        4. Monitoring node health
      3. See also
    3. Inspecting containers
      1. Getting ready
      2. How to do it…
        1. Inspecting pods in Pending status
        2. Inspecting pods in ImagePullBackOff status
        3. Inspecting pods in CrashLoopBackOff status
      3. See also
    4. Monitoring using Amazon CloudWatch
      1. Getting ready
      2. How to do it…
        1. Enabling Webhook authorization mode
        2. Installing Container Insights Agents for Amazon EKS
        3. Viewing Container Insights metrics
      3. See also
    5. Monitoring using Google Stackdriver
      1. Getting ready
      2. How to do it…
        1. Installing Stackdriver Kubernetes Engine Monitoring support for GKE
        2. Configuring a workspace on Stackdriver
        3. Monitoring GKE metrics using Stackdriver
      3. See also
    6. Monitoring using Azure Monitor
      1. Getting ready
      2. How to do it…
        1. Enabling Azure Monitor support for AKS using the CLI
        2. Monitoring AKS performance metrics using Azure Monitor
        3. Viewing live logs using Azure Monitor
      3. See also
    7. Monitoring Kubernetes using Prometheus and Grafana
      1. Getting ready
      2. How to do it…
        1. Deploying Prometheus using Helm charts
        2. Monitoring metrics using Grafana dashboards
        3. Adding a Grafana dashboard to monitor applications
      3. See also
    8. Monitoring and performance analysis using Sysdig
      1. Getting ready
      2. How to do it…
        1. Installing the Sysdig agent
        2. Analyzing application performance
      3. See also
    9. Managing the cost of resources using Kubecost
      1. Getting ready
      2. How to do it…
        1. Installing Kubecost
        2. Accessing the Kubecost dashboard
        3. Monitoring Kubernetes resource cost allocation
      3. See also
  15. Securing Applications and Clusters
    1. Technical requirements
    2. Using RBAC to harden cluster security
      1. Getting ready
      2. How to do it…
        1. Viewing the default Roles
        2. Creating user accounts
        3. Creating Roles and RoleBindings
        4. Testing the RBAC rules
      3. How it works...
      4. See also
    3. Configuring Pod Security Policies
      1. Getting ready
      2. How to do it…
        1. Enabling PSPs on EKS
        2. Enabling PSPs on GKE
        3. Enabling PodSecurityPolicy on AKS
        4. Creating a restricted PSPs
      3. There's more…
        1. Restricting pods to access certain volume types
        2. Using Kubernetes PodSecurityPolicy advisor
      4. See also
    4. Using Kubernetes CIS Benchmark for security auditing
      1. Getting ready
      2. How to do it…
        1. Running kube-bench on Kubernetes
        2. Running kube-bench on managed Kubernetes services
        3. Running kube-bench on OpenShift
      3. How it works...
      4. See also
    5. Building DevSecOps into the pipeline using Aqua Security
      1. Getting ready
      2. How to do it…
        1. Scanning images using Trivy
        2. Building vulnerability scanning into GitLab
        3. Building vulnerability scanning into CircleCI
      3. See also
    6. Monitoring suspicious application activities using Falco
      1. Getting ready
      2. How to do it…
        1. Installing Falco on Kubernetes
        2. Detecting anomalies using Falco
        3. Defining custom rules
      3. How it works...
      4. See also
    7. Securing credentials using HashiCorp Vault
      1. Getting ready
      2. How to do it…
        1. Installing Vault on Kubernetes
        2. Accessing the Vault UI
        3. Storing credentials on Vault
      3. See also
  16. Logging with Kubernetes
    1. Technical requirements
    2. Accessing Kubernetes logs locally
      1. Getting ready
      2. How to do it…
        1. Accessing logs through Kubernetes
        2. Debugging services locally using Telepresence
      3. How it works...
      4. See also
    3. Accessing application-specific logs
      1. Getting ready
      2. How to do it…
        1. Getting shell access in a container
        2. Accessing PostgreSQL logs inside a container
    4. Building centralized logging in Kubernetes using the EFK stack
      1. Getting ready
      2. How to do it…
        1. Deploying Elasticsearch Operator
        2. Requesting the Elasticsearch endpoint
        3. Deploying Kibana
        4. Aggregating logs with Fluent Bit
        5. Accessing Kubernetes logs on Kibana
      3. See also
    5. Logging Kubernetes using Google Stackdriver
      1. Getting ready
      2. How to do it…
        1. Installing Stackdriver Kubernetes Engine Monitoring support for GKE
        2. Viewing GKE logs using Stackdriver
      3. See also
    6. Using a managed Kubernetes logging service
      1. Getting ready
      2. How to do it…
        1. Connecting clusters to Director Online
        2. Accessing logs using Director Online
    7. Logging for your Jenkins CI/CD environment
      1. Getting ready
      2. How to do it…
        1. Installing the Fluentd plugin
        2. Streaming Jenkins logs to Elasticsearch using Fluentd
      3. There's more…
        1. Installing the Logstash plugin
        2. Streaming Jenkins logs to Elasticsearch using Logstash
      4. See also
  17. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think
18.188.131.255