Hands-On Kubernetes on Windows

Book description

Build and deploy scalable cloud applications using Windows containers and Kubernetes

Key Features

  • Run, deploy, and orchestrate containers on the Windows platform with this Kubernetes book
  • Use Microsoft SQL Server 2019 as a data store to deploy Kubernetes applications written in .NET Framework
  • Set up a Kubernetes development environment and deploy clusters with Windows Server 2019 nodes

Book Description

With the adoption of Windows containers in Kubernetes, you can now fully leverage the flexibility and robustness of the Kubernetes container orchestration system in the Windows ecosystem. This support will enable you to create new Windows applications and migrate existing ones to the cloud-native stack with the same ease as for Linux-oriented cloud applications.

This practical guide takes you through the key concepts involved in packaging Windows-distributed applications into containers and orchestrating these using Kubernetes. You'll also understand the current limitations of Windows support in Kubernetes. As you advance, you'll gain hands-on experience deploying a fully functional hybrid Linux/Windows Kubernetes cluster for development, and explore production scenarios in on-premises and cloud environments, such as Microsoft Azure Kubernetes Service.

By the end of this book, you'll be well-versed with containerization, microservices architecture, and the critical considerations for running Kubernetes in production environments successfully.

What you will learn

  • Understand containerization as a packaging format for applications
  • Create a development environment for Kubernetes on Windows
  • Grasp the key architectural concepts in Kubernetes
  • Discover the current limitations of Kubernetes on the Windows platform
  • Provision and interact with a Kubernetes cluster from a Windows machine
  • Create hybrid Windows Kubernetes clusters in on-premises and cloud environments

Who this book is for

This book is for software developers, system administrators, DevOps engineers, and architects working with Kubernetes on Windows, Windows Server 2019, and Windows containers. Knowledge of Kubernetes as well as the Linux environment will help you get the most out of this book.

Table of contents

  1. Title Page
  2. Copyright and Credits
    1. Hands-On Kubernetes on Windows
  3. About Packt
    1. Why subscribe?
  4. Contributors
    1. About the author
    2. About the reviewer
    3. Packt is searching for authors like you
  5. 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. Conventions used
    4. Get in touch
      1. Reviews
  6. Section 1: Creating and Working with Containers
  7. Creating Containers
    1. Technical requirements
    2. Linux versus Windows containers
      1. Docker containerization on Linux
      2. Docker containerization on Windows
      3. Key differences between containers on Linux and Windows
    3. Understanding Windows container variants
      1. Process isolation
      2. Hyper-V isolation
      3. Linux containers on Windows
        1. LinuxKit and MobyLinuxVM
        2. LinuxKit LCOW and Hyper-V isolation
    4. Installing Docker Desktop for Windows tooling
      1. Stable and Edge channels
      2. Installation
      3. Verifying the installation
      4. Running process-isolated containers
      5. Running LCOW containers
    5. Building your first container
      1. Preparing a Visual Studio Code workspace
      2. Creating a sample HTML web page
      3. Creating a Dockerfile
      4. Building a Docker image
      5. Running Windows containers
      6. Inspecting container logs
      7. Exec into a running container
    6. Summary
    7. Questions
    8. Further reading
  8. Managing State in Containers
    1.  Technical requirements
    2. Mounting local volumes for stateful applications
      1. Volumes and bind mount
      2. Creating and mounting volumes
      3. Removing volumes
      4. Mounting a local container host directory using bind mounts
    3. Using remote/cloud storage for container storage
      1. Installing the Azure CLI and Azure PowerShell module
      2. Creating Azure Files SMB share
      3. Mounting Azure Files SMB share in a container
    4. Running clustered solutions inside containers
      1. Creating a MongoDB ReplicaSet
      2. Writing and reading test data
    5. Summary
    6. Questions
    7. Further reading
  9. Working with Container Images
    1. Technical requirements
    2. Storing and sharing container images
      1. Pushing an image to the Docker registry
      2. Using a custom local registry
    3. Using cloud container builders
      1. Creating a GitHub repository
      2. Creating a Docker Hub repository with autobuild
      3. Triggering the Docker Hub autobuild
      4. Creating Azure Container Registry
      5. Building a Docker image using Azure Container Registry
      6. Automatic builds for Azure Container Registry
    4. Image tagging and versioning
      1. Using the latest tag
      2. Semantic versioning 
    5. Ensuring the integrity of the image supply chain
      1. Signing an image
      2. Enabling DCT for the client
    6. Summary
    7. Questions
    8. Further reading
  10. Section 2: Understanding Kubernetes Fundamentals
  11. Kubernetes Concepts and Windows Support
    1. Technical requirements
    2. Kubernetes high-level architecture
      1. What is Kubernetes?
      2. Kubernetes master – control plane
        1. kube-apiserver
        2. etcd cluster
        3. kube-scheduler
        4. kube-controller-manager
        5. cloud-controller-manager
      3. Kubernetes nodes – data plane
        1. kubelet
        2. Container runtime
        3. kube-proxy
      4. DNS
    3. Kubernetes objects
      1. Pods
      2. ReplicaSets
      3. Deployments
      4. StatefulSets
      5. DaemonSets
      6. Services
      7. Storage-related objects
    4. The Windows and Kubernetes ecosystem
    5. Kubernetes limitations on Windows
    6. Creating your own development cluster from scratch
      1. minikube
      2. Docker Desktop for Windows
    7. Production cluster deployment strategies
      1. kubeadm
      2. kops
      3. kubespray
      4. AKS Engine
    8. Managed Kubernetes providers
      1. Creating AKS cluster with Windows nodes
    9. Summary
    10. Questions
    11. Further reading
  12. Kubernetes Networking
    1. Technical requirements
    2. Kubernetes networking principles
      1. L2 network
      2. Overlay network
      3. Other solutions
      4. Services
        1. ClusterIP
        2. NodePort
        3. LoadBalancer
        4. ExternalName
      5. Ingress
    3. Kubernetes CNI network plugins
      1. Understanding the CNI project
      2. CoreOS Flannel
    4. Windows Server networking in Kubernetes
      1. Limitations
    5. Choosing Kubernetes network modes
      1. L2Bridge
      2. L2Tunnel
      3. Overlay
      4. Transparent
    6. Summary
    7. Questions
    8. Further reading
  13. Interacting with Kubernetes Clusters
    1. Technical requirements
    2. Installing Kubernetes command-line tooling
    3. Accessing Kubernetes clusters
    4. Working with development clusters
    5. Looking at common kubectl commands
      1. Creating resources
      2. Deleting resources
      3. Describing and listing resources
      4. Editing resources
      5. Running an ad hoc Pod
      6. Accessing Pod container logs
      7. Execcing into a Pod container
      8. Copying Pod container files
      9. Port forwarding and proxying traffic
    6. Summary
    7. Questions
    8. Further reading
  14. Section 3: Creating Windows Kubernetes Clusters
  15. Deploying a Hybrid On-Premises Kubernetes Cluster
    1. Technical requirements
    2. Preparing the Hyper-V environment
      1. Enabling Hyper-V
      2. Creating an internal NAT Hyper-V vSwitch
      3. Creating an external Hyper-V vSwitch
    3. Creating a Kubernetes master node using kubeadm
      1. Creating a VM and installing Ubuntu Server
        1. Creating the VM
        2. Installing Ubuntu Server
        3. Configuring the network
        4. Installing additional packages for integration with Hyper-V
        5. Setting up a passwordless SSH login
      2. Installing and configuring Kubernetes prerequisites
      3. Planning the cluster
      4. Initializing the cluster
    4. Installing the Kubernetes network
    5. Preparing VMs for Windows nodes
      1. Creating the VM
      2. Installing Windows Server 2019
      3. Configuring the network
      4. Installing the SSH server
      5. Installing and configuring Kubernetes prerequisites
    6. Joining Windows nodes using kubeadm
    7. Deploying and inspecting your first application
    8. Summary
    9. Questions
    10. Further reading
  16. Deploying a Hybrid Azure Kubernetes Service Engine Cluster
    1. Technical requirements
    2. Installing AKS Engine
    3. Creating an Azure resource group and a service principal
    4. Using apimodel and generating an Azure resource manager template
    5. Deploying the cluster
    6. Deploying and inspecting your first application
      1. Basic operations
      2. Connecting to virtual machines
      3. Enabling Azure Log Analytics and Azure Monitor for containers
    7. Summary
    8. Questions
    9. Further reading
  17. Section 4: Orchestrating Windows Containers Using Kubernetes
  18. Deploying Your First Application
    1. Technical requirements
    2. Imperatively deploying an application
    3. Using Kubernetes manifest files
    4. Scheduling Pods on Windows nodes
    5. Accessing your application
    6. Scaling the application
    7. Summary
    8. Questions
    9. Further reading
  19. Deploying Microsoft SQL Server 2019 and a ASP.NET MVC Application
    1. Technical requirements
    2. Creating and publishing an ASP.NET MVC application to Docker Hub
      1. Injecting the configuration using environment variables
      2. Configuring logging for Windows containers log monitor
      3. Creating a Dockerfile
      4. Building and pushing the Docker image
    3. Preparing the AKS Engine
    4. Deploying a failover Microsoft SQL Server 2019
    5. Deploying the ASP.NET MVC application
    6. Accessing the application
    7. Scaling the application
    8. Debugging the application
      1. Creating a debug Dockerfile and publishing a debug image
      2. Updating the Kubernetes Deployment
      3. Attaching the Visual Studio remote debugger
    9. Summary
    10. Questions
    11. Further reading
  20. Configuring Applications to Use Kubernetes Features
    1. Technical requirements
    2. Using namespaces to isolate applications
      1. Creating namespaces
      2. kubectl commands and namespaces
      3. Deleting namespaces
    3. Health monitoring using liveness and readiness probes
      1. Readiness probes
      2. Liveness probes
      3. Startup probes
    4. Specifying resource limits and configuring autoscaling
      1. Resource requests and limits
      2. HPA
    5. Managing application configuration using ConfigMaps and Secrets
    6. Managing persistent data storage on Windows nodes
    7. Configuring rolling updates for Deployments
    8. Role-Based Access Control
    9. Summary
    10. Questions
    11. Further reading
  21. Development Workflow with Kubernetes
    1. Technical requirements
    2. Using developer tooling with Kubernetes
      1. Visual Studio 2019
      2. Visual Studio Code
    3. Packaging applications using Helm
      1. Installing Helm
      2. Deploying Microsoft SQL Server using Helm
      3. Creating a Helm chart for our Voting application
    4. Debugging a containerized application using Azure Application Insights
      1. Enabling Azure Application Insights
      2. Snapshot debugger
    5. Using Kubernetes Dashboard
      1. Deploying Kubernetes Dashboard
      2. Accessing pod container logs
      3. Executing commands in a pod container
    6. Working on microservices in a team using Azure Dev Spaces
    7. Summary
    8. Questions
    9. Further reading
  22. Securing Kubernetes Clusters and Applications
    1. Technical requirements
    2. Securing Kubernetes clusters
      1. Using built-in RBAC for authorization 
      2. Using an external authentication provider
      3. Bootstrapping the cluster using kubeadm
      4. Disabling public API access
      5. Disabling the public Dashboard
      6. Running containers in nonprivileged mode
      7. Encrypting data at rest
      8. Using network policies
      9. Securing the image supply chain and scan images
      10. Rotating infrastructure credentials and certificates
      11. Enabling audit logging
      12. Integrating AAD with AKS Engine
    3. Securing container runtime in Windows
    4. Deploying secure applications using network policies
      1. Network policy support
      2. Configuring network policy
    5. Kubernetes secrets on Windows machines
    6. Summary
    7. Questions
    8. Further reading
  23. Monitoring Kubernetes Applications Using Prometheus
    1. Technical requirements
    2. Available monitoring solutions
      1. Prometheus and monitoring Windows nodes
    3. Provisioning observable Windows nodes
      1. Installing WMI Exporter and enabling Metrics Server in Docker
      2. Using extensions for AKS Engine
    4. Deploying Prometheus using a Helm chart
      1. Installing Helm charts
      2. Verifying the Deployment
    5. Windows Performance Counters
      1. Extending a Docker image with the Telegraf service
      2. Deploying an observable version of the voting application
    6. Monitoring .NET applications using prometheus-net
      1. Installing the NuGet package and adding metrics
      2. Deploying the new version of the voting application
    7. Configuring dashboards and alerts in Grafana
      1. Adding visualizations
      2. Configuring alerting
    8. Summary
    9. Questions
    10. Further reading
  24. Disaster Recovery
    1. Technical requirements
    2. Kubernetes cluster backup strategy
    3. Backing up an etcd cluster
    4. Restoring the etcd cluster backup
    5. Automating backup
    6. Replacing a failed etcd cluster member
    7. Summary
    8. Questions
    9. Further reading
  25. Production Considerations for Running Kubernetes
    1. Technical requirements
    2. Provisioning clusters reproducibly
      1. Infrastructure as code for clusters
      2. GitOps for application workloads
    3. Kubeadm limitations
    4. Upgrading clusters
    5. OS patching
    6. Configuring a network proxy for the Docker daemon and Kubernetes
    7. Summary
    8. Questions
    9. Further reading
  26. Assessments
    1. Chapter 1: Creating Containers
    2. Chapter 2: Managing State in Containers
    3. Chapter 3: Working with Container Images
    4. Chapter 4: Kubernetes Concepts and Windows Support
    5. Chapter 5: Kubernetes Networking
    6. Chapter 6: Interacting with Kubernetes Clusters
    7. Chapter 7: Deploying a Hybrid On-Premises Kubernetes Cluster
    8. Chapter 8: Deploying a Hybrid Azure Kubernetes Service Engine Cluster
    9. Chapter 9: Deploying Your First Application
    10. Chapter 10: Deploying Microsoft SQL Server 2019 and ASP.NET MVC Applications
    11. Chapter 11: Configuring Applications to Use Kubernetes Features
    12. Chapter 12: Development Workflow with Kubernetes
    13. Chapter 13: Securing Kubernetes Clusters and Applications
    14. Chapter 14: Monitoring Kubernetes Applications Using Prometheus
    15. Chapter 15: Disaster Recovery
    16. Chapter 16: Production Considerations for Running Kubernetes
  27. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think

Product information

  • Title: Hands-On Kubernetes on Windows
  • Author(s): Piotr Tylenda
  • Release date: March 2020
  • Publisher(s): Packt Publishing
  • ISBN: 9781838821562