Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Infrastructure as Code for Beginners

You're reading from   Infrastructure as Code for Beginners Deploy and manage your cloud-based services with Terraform and Ansible

Arrow left icon
Product type Paperback
Published in May 2023
Publisher Packt
ISBN-13 9781837631636
Length 222 pages
Edition 1st Edition
Tools
Arrow right icon
Author (1):
Arrow left icon
Russ McKendrick Russ McKendrick
Author Profile Icon Russ McKendrick
Russ McKendrick
Arrow right icon
View More author details
Toc

Table of Contents (15) Chapters Close

Preface 1. Part 1: The Foundations – An Introduction to Infrastructure as Code
2. Chapter 1: Choosing the Right Approach – Declarative or Imperative FREE CHAPTER 3. Chapter 2: Ansible and Terraform beyond the Documentation 4. Chapter 3: Planning the Deployment 5. Part 2: Getting Hands-On with the Deployment
6. Chapter 4: Deploying to Microsoft Azure 7. Chapter 5: Deploying to Amazon Web Services 8. Chapter 6: Building upon the Foundations 9. Part 3: CI/CD and Best Practices
10. Chapter 7: Leveraging CI/CD in the Cloud 11. Chapter 8: Common Troubleshooting Tips and Best Practices 12. Chapter 9: Exploring Alternative Infrastructure-as-Code Tools 13. Index 14. Other Books You May Enjoy

Pets versus cattle

Traditionally, pets or cattle has been a way of defining your data center resources. It’s an analogy that describes a collection of hardware or virtualized resources as either pets or cattle.

Pets

Pets are resources that are owned by individual users/teams or managed on an individual basis.

Normally, they are seen as important fixed points within any application architecture and, like with a pet, you do the following:

  • You give them names: For example, your server may have a hostname that looks something like backendapplication.server.domain.com, so it is easily identifiable.
  • You feed and water them: For example, you take and keep backups that you review regularly. You keep a close eye on resource utilization and add more RAM and drive space as required.
  • If they get ill, you care for them: They have monitoring agents installed, meaning you are alerted if there is a problem – sometimes 24/7 – and if there is an issue, you do everything you can to restore service by having troubleshooting procedures in place.
  • You expect them to live for a long time: Given their importance within your application architecture and that you are caring for them, you expect them to be around for quite a while.

Resources that are now considered pets have typically been around for some time, and their configuration has organically evolved over that time based on their utilization, making them each a unique deployment, which is why you care for them, just like having a real pet – a good example of this is a long-running server.

Cattle

With resources that have been deployed to be treated as cattle, you only care about the health of the herd and not an individual resource:

  • There are too many of them to give names: For example, your servers may have a hostname that looks something like beapp001.server.domain.com to beapp015.server.domain.com; you just keep incrementing the number rather than assigning a unique name that makes them easily identifiable.
  • You watch them from afar: Given the number of resources, you only really care about the availability of the herd, meaning you probably only just ship performance stats and logs from the resources, and you do not need to back them up as it would be quick to replace them.
  • If they get ill, you replace them: As already mentioned, if there is an issue with a resource, rather than troubleshoot the problem, you terminate it and replace it with another resource ASAP. Typically, this process is automated so that a resource is quickly taken out of service and another one put in place.
  • You don’t expect them to live for a long time: Given their numbers, they can be quite short-lived – in some cases, resources may only exist for a short amount of time to handle an increase in the workload. Once the demand for additional resources has ceased, some of the resources are terminated.

Conclusion

Pets versus cattle mainly applies to application deployment strategies rather than purely just the underlying infrastructure. After all, let’s say your application, for whatever reason, needs to run as a single fixed point – for example, your application does the following:

  • Writes essential files to the local disc, which can’t be lost if an instance is terminated
  • Has manual steps for bringing an application instance online after it has been deployed
  • Is licensed to a MAC address or CPU ID of a host

In this case, you may not be able to treat your deployments as cattle, but you can write your Infrastructure as Code so that the bulk of your deployment is as automated as possible.

These are technical reasons, but there are some considerations from a business point of view as well.

The one that will get most businesses’ attention is cost efficiency. Your choice of either a pets or cattle approach could have a significant impact on your hosting costs.

The cattle approach, which treats servers as ephemeral resources, allows for better resource utilization and automated scaling, potentially reducing costs. On the other hand, deploying pets, which emphasizes individual server care, may result in higher maintenance and management costs but could be justified for mission-critical applications that demand special attention.

Taking a cattle approach enables faster deployment and scaling of your workloads; this allows businesses to respond more quickly to market changes and customer needs. Deploying pets might lead to longer deployment times, potentially impacting a company’s competitiveness.

Regulatory and security requirements could also influence the choice between pet and cattle deployments. The pets approach, focusing on managing individual resources, may be more appropriate for businesses with strict regulatory or security requirements, as it allows for more fine-grained control and auditing of server configurations. However, the cattle approach, emphasizing automation and rapid scaling, might not provide the same level of control and may require additional efforts to ensure compliance and security.

Now that we have a good idea of the type of deployments you could be dealing with, let’s now talk about what this means for an Infrastructure-as-Code deployment.

You have been reading a chapter from
Infrastructure as Code for Beginners
Published in: May 2023
Publisher: Packt
ISBN-13: 9781837631636
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image