Achieve reliable release automation and get zero troublesome notifications on your release day Key Features Develop the skills to build command-line tools to control thousands of nodes Use Go to create Terraform providers and GitHub actions and extend Kubernetes Gain the knowledge to build Dev
Go for DevOps: Learn how to use the Go language to automate servers, the cloud, Kubernetes, GitHub, Packer, and Terraform
โ Scribed by John Doak; David Justice
- Publisher
- Packt Publishing
- Year
- 2022
- Tongue
- English
- Leaves
- 634
- Category
- Library
No coin nor oath required. For personal study only.
โฆ Synopsis
Achieve reliable release automation and get zero troublesome notifications on your release day.
Purchase of the print or Kindle book includes a free eBook in the PDF format.
Key Features
Develop the skills to build command-line tools to control thousands of nodes
Use Go to create Terraform providers and GitHub actions and extend Kubernetes
Gain the knowledge to build DevOps workflows that are understandable, scalable, and safe
Book Description
Go is the go-to language for DevOps libraries and services, and without it, achieving fast and safe automation is a challenge. With the help of Go for DevOps, you'll learn how to deliver services with ease and safety, becoming a better DevOps engineer in the process.
Some of the key things this book will teach you are how to write Go software to automate configuration management, update remote machines, author custom automation in GitHub Actions, and interact with Kubernetes. As you advance through the chapters, you'll explore how to automate the cloud using software development kits (SDKs), extend HashiCorp's Terraform and Packer using Go, develop your own DevOps services with gRPC and REST, design system agents, and build robust workflow systems.
By the end of this Go for DevOps book, you'll understand how to apply development principles to automate operations and provide operational insights using Go, which will allow you to react quickly to resolve system failures before your customers realize something has gone wrong.
What you will learn
Understand the basic structure of the Go language to begin your DevOps journey
Interact with filesystems to read or stream data
Communicate with remote services via REST and gRPC
Explore writing tools that can be used in the DevOps environment
Develop command-line operational software in Go
Work with popular frameworks to deploy production software
Create GitHub actions that streamline your CI/CD process
Write a ChatOps application with Slack to simplify production visibility
Who this book is for
This book is for Ops and DevOps engineers who would like to use Go to develop their own DevOps tooling or integrate custom features with DevOps tools such as Kubernetes, GitHub Actions, HashiCorp Packer, and Terraform. Experience with some type of programming language, but not necessarily Go, is necessary to get started with this book.
โฆ Table of Contents
Cover
Title Page
Copyright
Dedication
Contributors
Table of Contents
Preface
Section 1: Getting Up and Running with Go
Chapter 1: Go Language Basics
_Technical requirements
_Using the Go Playground
_Utilizing Go packages
_Declaring a package
__Importing a package
__Using a package
__Package name conflicts
__Packages must be used
__A Go Hello World
__Using Go's variable types
__Go's types
__Declaring variables
__Variable scopes and shadowing
__Function/statement variable must be used
_Looping in Go
_C style
__Removing the init statement
__Remove the post statement too and you have a while loop
__Creating an infinite loop
__Using conditionals
__if statements
__else
_Learning about functions
_Returning multiple values and named results
__Variadic arguments
__Anonymous functions
__Defining public and private
_Using arrays and slices
_Arrays
__Slices
__Extracting all values
__Understanding maps
__Declaring a map
__Accessing values
__Adding new values
__Extracting all values
__Understanding Go pointers
__Memory addresses
__Function arguments are copies
__Pointers to the rescue
_Getting to know about structs
_Declaring a struct
__Declaring a custom type
__Custom struct types
__Adding methods to a type
__Changing a field's value
__Changing a field's value in a method
__Constructors
__Comprehending Go interfaces
__Defining an interface type
__Important things about interfaces
__The blank interface โ Go's universal value
__Type assertion
____Summary
Chapter 2: Go Language Essentials
_Handling errors in Go
_Creating an error
__Using an error
__Creating named errors
__Custom errors
__Wrapping errors
__Utilizing Go constants
__Declaring a constant
__Enumeration via constants
__Printing enumerators
_Using defer, panic, and recover
_defer
__panic
__recover
__Utilizing goroutines for concurrency
__Starting a goroutine
__Synchronization
__WaitGroups
__Channels
__Sending/receiving
__select statements
__Channels as an event signal
__Mutexes
__RWMutex
_Understanding Go's Context type
_Using a Context to signal a timeout
__Honoring a context when receiving
__Context in the standard library
__Context to pass values
__Best practices
__Utilizing Go's testing framework
__Creating a basic test file
__Creating a simple test
__Table Driven Tests (TDT)
__Creating fakes with interfaces
__Third-party testing packages
_Generics โ the new kid on the block
_Type parameters
__Using type constraints
__We could do better with constraints
__Current built-in constraints
__Type constraints with methods
__Adding type parameters to struct types
__Specifying the type when calling a generic function
__Gotchas to watch for
__When to use generics
__Summary
Chapter 3: Setting Up Your Environment
_Technical requirements
_Installing Go on your machine
__macOS installation using the package installer
__macOS installation via Homebrew
__Windows installation using MSI
__Linux
__Other platforms
__A note on Go compiler version compatibility
_Building code locally
_Creating a module directory and go.mod file
__Updating a module when adding dependencies
__Adding a hello world
__Running our first program
__Summary
Chapter 4: Filesystem Interactions
_All I/O in Go are files
_I/O interfaces
__Reading and writing to files
__Reading local files
__Writing local files
__Reading remote files
_Streaming file content
_Stdin/Stdout/Stderr are just files
__Reading data out of a stream
__Writing data into a stream
__OS-agnostic pathing
__What OS/platform am I running?
__Using filepath
__Relative and absolute pathing
_OS-agnostic filesystems
_io.fs filesystems
__embed
__Walking our filesystem
__The io/fs future
__Summary
Chapter 5: Using Common Data Formats
_Technical requirements
_CSV files
__Basic value separation using the strings package
__Using the encoding/csv package
__Using excelize when dealing with Excel
_Popular encoding formats
_The Go field tags
__JSON
__YAML encoding
__Summary
Chapter 6: Interacting with Remote Data Sources
_Technical requirements
_Accessing SQL databases
__Connecting to a Postgres database
__Querying a Postgres database
__Null values
__Writing data to Postgres
__Transactions
__Postgres-specific types
__Other options
__Storage abstractions
__Case study โ data migration of an orchestration system โ Google
_Developing REST services and clients
_REST for RPCs
__Developing gRPC services and clients
__Protocol buffers
__Stating the prerequisites
__Generating your packages
__Writing a gRPC client
__Writing a gRPC server
__Creating a server binary
__Creating a client binary
__Company-standard RPC clients and servers
____Summary
Chapter 7: Writing Command-Line Tooling
_Technical requirements
_Implementing application I/O
__The flag package
__Custom flags
__Basic flag error handling
__Shorthand flags
__Accessing non-flag arguments
__Retrieving input from STDIN
_Using Cobra for advanced CLI applications
_Code organization
__The optional Cobra generator
__The command package
__Handling OS signals
__Capturing an OS signal
__Using Context to cancel
____Summary
Chapter 8: Automating Command-Line Tasks
_Technical requirements
_Using os/exec to automate local changes
__Determining the availability of essential tools
_Using SSH in Go to automate remote changes
_Connecting to another system
__Designing safe, concurrent change automations
__Components of a change
__Writing a concurrent job
__Case study โ Network rollouts
_Writing a system agent
_Designing a system agent
__Implementing Install
__Implementing SystemPerf
__Summary
Section 2: Instrumenting, Observing, and Responding
Chapter 9: Observability with OpenTelemetry
_Technical requirements
_An introduction to OpenTelemetry
__Reference architecture for OpenTelemetry
__OpenTelemetry components
_Logging with context
_Our first log statement
__Structured and leveled logs with Zap
__Ingesting, transforming, and exporting logs using OpenTelemetry
__Instrumenting for distributed tracing
__The life cycle of a distributed trace
__Correlating traces and logs
__Adding log entries to spans
_Instrumenting for metrics
_The life cycle of a metric
__Client/server metrics with OpenTelemetry
__Alerting on metrics abnormalities
__Adding and configuring Alertmanager
____Summary
Chapter 10: Automating Workflows with GitHub Actions
_Technical requirements
_Understanding the basics of GitHub Actions
__Exploring the components of a GitHub Action
__How to build and trigger your first GitHub Action
_Building a continuous integration workflow
_Introducing the tweeter command-line tool
__Goals of the tweeter continuous integration workflow
__Continuous integration workflow for tweeter
__Building a release workflow
__GitHub releases
__Release automation for tweeter
_Creating a custom GitHub Action using Go
_Basics of custom actions
__Goals for the tweeter custom GitHub Action
__Creating the tweeter action
__Publishing a custom Go GitHub Action
__The basics of publishing actions
__Goals for publishing the tweeter custom action
__Managing action semantic versioning
__Publishing the tweeter action to the GitHub Marketplace
____Summary
Chapter 11: Using ChatOps to Increase Efficiency
_Technical requirements
_Environment architecture
_Using an Ops service
_Building a basic chatbot
_Creating event handlers
_Case Study โ Regexes versus Lexer and Parser
__Creating our Slack application
__Running the applications
____Summary
Section 3: Cloud ready Go
Chapter 12: Creating Immutable Infrastructure Using Packer
_Technical requirements
_Building an Amazon Machine Image
__Setting up an AWS source
__Defining a build block and adding some provisioners
__Executing a Packer build
_Validating images with Goss
_Creating a spec file
__Adding a Packer provisioner
__Customizing Packer with plugins
__Writing your own plugin
__Releasing a plugin
__Using our plugin in a build
__Debugging a Packer plugin
____Summary
Chapter 13: Infrastructure as Code with Terraform
_Technical requirements
_An introduction to IaC
_Understanding the basics of Terraform
_Initializing and applying infrastructure specs using Terraform
__Understanding the basics of Terraform providers
__Defining and provisioning cloud resources
_Building a pet store Terraform provider
_Resources for building custom providers
__The pet store provider
__Publishing custom providers
__Summary
Chapter 14: Deploying and Building Applications in Kubernetes
_Technical requirements
_Interacting with the Kubernetes API
__Creating a KinD cluster
__Using kubectl to interact with the API
_Deploying a load-balanced HTTP application using Go
_It all starts with main
__Creating a ClientSet
__Creating a namespace
__Deploying the application into the namespace
__Creating the NGINX deployment
__Waiting for ready replicas to match desired replicas
__Creating a Service to load-balance
__Creating an ingress to expose our application on a local host port
__Streaming pod logs for the NGINX application
__Extending Kubernetes with custom resources and operators
__Custom Resource Definitions
__Controllers
__Standing on the shoulders of giants
_Building a pet store operator
_Initializing the new operator
__Summary
Chapter 15: Programming the Cloud
_Technical requirements
_What is the cloud?
_Learning the basics of the Azure APIs
_A background on cloud APIs and SDKs
__Microsoft Azure identity, RBAC, and resource hierarchy
__Creating an Azure account and accessing the API
__Building infrastructure using Azure Resource Manager
__Azure SDK for Go
__Setting up your local environment
__Building an Azure virtual machine
_Using provisioned Azure infrastructure
_Building an Azure Storage account
__Summary
Chapter 16: Designing for Chaos
_Technical requirements
_Using overload prevention mechanisms
__Case study โ AWS client requests overwhelm the network
__Using circuit breakers
__Using backoff implementations
__Combining circuit breakers with backoff
_Using rate limiters to prevent runaway workflows
_Case study โ Google satellite disk erase
__Channel-based rate limiter
__Token-bucket rate limiter
__Building workflows that are repeatable and never lost
__Building idempotent workflows
__Using three-way handshakes to prevent workflow loss
_Using policies to restrict tools
_Defining a gRPC workflow service
__Creating a policy engine
__Writing a policy
__Cautions on policy engines
__Building systems with an emergency stop
__Understanding emergency stops
__Building an emergency-stop package
__Using the emergency-stop package
__Case study โ Google's network backbone emergency stop
____Summary
Index
About Packt
Other Books You May Enjoy
โฆ Subjects
DevOps;Golang;Programming;Go;Cloud;Kubernetes;GitHub;Packer;Terraform;
๐ SIMILAR VOLUMES
Achieve reliable release automation and get zero troublesome notifications on your release day Key Features Develop the skills to build command-line tools to control thousands of nodes Use Go to create Terraform providers and GitHub actions and extend Kubernetes Gain the knowledge to build Dev
<p><span>Understand the world of modern network automation with Go and deepen your knowledge with insights from 10+ experts who have real-world hands-on experience with network automation and/or are using Go for network-related tasks</span></p><h4><span>Key Features</span></h4><ul><li><span><span>A
<p><span>Understand the world of modern network automation with Go and deepen your knowledge with insights from 10+ experts who have real-world hands-on experience with network automation and/or are using Go for network-related tasks</span></p><h4><span>Key Features</span></h4><ul><li><span><span>A
Simplify your DevOps roles with DevOps tools and techniques Key Features โข Learn to utilize business resources effectively to increase productivity and collaboration โข Leverage the ultimate open source DevOps tools to achieve continuous integration and continuous delivery (CI/CD) โข Ensure fast