Containerization
Containers are made using the Docker library. The creation, destruction, and modification of containers can be automated and orchestrated using Python. It provides a way to programmatically maintain and modify container states. Some applications include the following:
- Interaction with Docker API for commands, such as getting a list of Docker containers or images present in the OS
- Automatically generating Docker Compose files from a list of Docker images
- Building Docker images
- Orchestrating containers using the Kubernetes library
- Testing and verifying Docker images
You may be wondering what the point of containers is, and that may be because you’ve never gotten tired of the constant online discourse over OSs and frameworks and which ones are superior (in fact, you may have even encouraged such malarkey). But, containers exist for those who tire of such debate and instead want isolated environments for all their specific operating needs. So they made one with containers, and someone had the bright idea to call them microservices.
Microservices
Sometimes, containers and microservices are used interchangeably, but in modern DevOps that is not necessarily the case. Yes, it is containers that make microservices possible, but t the overall writing of microservices on top of those containers is efficient code that has the most bang for its buck. Some reasons for Python use in microservices are as follows:
- Strong native library support inside of a Python container – libraries such as json, asyncio, and subprocess
- Excellent native code modules that simplify certain iterative and manipulative operations on data such as the collection module
- Ability to properly natively handle semi-structured and varied JSON data that is usually used in microservices
To have these microservices interact with each other effectively and consistently, we need some repetition, some consistent repetition. What’s the word I’m looking for … automaton … no, that’s a robot … autograph … no, that’ll be what I do once this book becomes a bestseller … automation, yes, that’s the word. Automation.
Automation is probably the primary selling point for DevOps engineers when it comes to Python because of its incredible automation library and support features. Most systems guys who transition to DevOps prefer their precious Bash scripting, and that does have a place in environments such as these, but Python is more powerful and more flexible, and it is better supported by the community and the companies in the industry overall. Some applications of Python for automation in this case would be the following:
- Various Software Development Kits (SDKs) for cloud-based deployments in AWS, Azure, Google Cloud, and other providers
- Support for automated building and testing of applications
- Support for monitoring applications and sending notifications
- Support for parsing and scraping necessary data from web pages, databases, and various other sources of data
Now that we have talked the talk, let’s walk a little. A light jog to combine Python and DevOps.