One place for hosting & domains

      Advantages

      Understanding MongoDB: Advantages of a Document-Oriented NoSQL Database


      Introduction

      Data has become a driving force of technology in recent years, as modern applications and websites need to manage an ever-increasing amount of data. Traditionally, database management systems organize data based on the relational model. As organizations’ data needs have changed, however, a number of new types of databases have been developed.

      These new types of databases often don’t rely on the traditional table structure provided by relational databases, and can thus allow for far more flexibility than the rigid structure imposed by relational databases. Additionally, they typically don’t use Structured Query Language (SQL), which is employed by most relational database systems to allow users to define and interact with data. This has led to many of these new non-relational databases to be referred to generally as NoSQL databases.

      First released in 2009, MongoDB — also known as Mongo — is a document-oriented NoSQL database used in many modern web applications. This conceptual article provides a high-level overview of the features that set MongoDB apart from other database management systems and make it a valuable tool across many different use cases.

      A Brief Overview of MongoDB

      As mentioned in the introduction, MongoDB is considered to be a NoSQL database since it doesn’t depend on the relational model. Every database management system is designed around a certain type of data model that defines how the data within the database will be organized. The relational model involves storing data in tables — more formally known as relations — made up of rows and columns.

      MongoDB, on the other hand, stores its data records in structures known as documents. Mongo allows you to group multiple documents into a structure known as a collection, which can be further grouped into separate databases.

      A document is written in BSON, a binary representation of JSON. Like objects in JSON, MongoDB documents begin and end with curly brackets ({ and }), and contain a number of field-and-value pairs which typically take the form of field: value. A field’s value can be any one of the data types used in BSON, or even other structures like documents and arrays.

      Security

      MongoDB comes installed with a number of features that can help to prevent data loss as well as access by unauthorized users. Some of these features can be found on other database management systems. For instance, Mongo, like many modern DBMSs, allows you to encrypt data as it traverses a network — sometimes called data in transit. It does this by requiring that connections to the database be made with Transport Layer Security (TLS), a cryptographic protocol that serves as a successor to Secure Sockets Layer (SSL).

      Also like other DBMSs, Mongo manages authorization — the practice of setting rules for a given user or group of users to define what actions they can perform and what resources they can access — through a computer security concept known as role-based access control, or RBAC. Whenever you create a MongoDB user, you have the option to provide them with one or more roles.

      A role defines what privileges a user has, including what actions they can perform on a given database, collection, set of collections, or cluster. For example, you can assign a user the readWrite role on any database, meaning that you can read and modify the data held in any database on your system as long as you’ve granted a user the readWrite role over it. Something that distinguishes MongoDB’s RBAC from that of other databases is that, in addition to its built-in roles, Mongo also allows you to define custom roles, giving you even more control over what resources users can access on your system.

      Since the release of version 4.2, MongoDB supports client-side field level encryption. This involves encrypting certain fields within a document before the data gets written to the database. Any client or application that tries to read it later on must first present the correct encryption keys to be able to decrypt the data in these fields.

      To illustrate, say your database holds a document with the following fields and values:

      {
        "name" : "Sammy",
        "phone" : "555-555-1234",
        "creditcard" : "1234567890123456"
      }
      

      It could be dangerous to store sensitive information like this — namely, a person’s phone and credit card numbers — in a real-world application. Even if you’ve put limits on who can access the database, anyone who has privileges to access the database could see and take advantage of your users’ sensitive information. When properly configured, though, these fields would look something like if they were written with client side field level encryption:

      {
        "name" : "Sammy",
        "phone" : BinData6,"quas+eG4chuolau6ahq=i8ahqui0otaek7phe+Miexoo"),
        "creditcard" : BinData6,"rau0Teez=iju4As9Eeyiu+h4coht=ukae8ahFah4aRo="),
      }
      

      For a more thorough overview of MongoDB’s security features, along with some general strategies for keeping a Mongo database secure, we encourage you to check out our series on MongoDB Security: Best Practices to Keep Your Data Safe.

      Flexibility

      Another characteristic of MongoDB that has helped drive its adoption is the flexibility it provides when compared with more traditional database management systems. This flexibility is rooted in MongoDB’s document-based design, since collections in Mongo do not enforce a specific structure that every document within them must follow. This contrasts with the rigid structure imposed by tables in a relational database.

      Whenever you create a table in a relational database, you must explicitly define the set of columns the table will hold along with their data types. Following that, every row of data you add must conform to that specific structure. On the other hand, MongoDB documents in the same collection can have different fields, and even if they share a given field it can hold different data types in different documents.

      This rigidity imposed by the relational model isn’t necessarily a bad thing. In fact, it makes relational databases quite useful for storing data that neatly conforms to a predefined structure. But it can become limiting in cases where you need to store unstructured data — data that doesn’t easily fit into predefined data models or isn’t easily searchable by conventional tools.

      Examples of unstructured data include media content, like videos or photos, communications data, or text files. Sometimes, unstructured data is generalized as qualitative data. In other words, data that may be human readable but is difficult for computers to adequately parse. MongoDB’s versatile document-oriented design, however, makes it a great choice for storing and analyzing unstructured data as well as structured and semi-structured data.

      Another example of Mongo’s flexibility is how it offers multiple avenues for interacting with one’s data. For example, you can run the mongo shell, a JavaScript-based interface that comes installed with the MongoDB server, which allows you to interact with your data from the command line.

      Mongo also supports a number of official drivers that can help you connect a database to your application. Mongo provides these libraries for a variety of popular programming languages, including PHP, Java, JavaScript, and Python. These drivers also provide support for the data types found in their respective host languages, expanding on the BSON data types available by default.

      High Availability

      Any computer-based database system depends on its underlying hardware to function and serve the needs of an application or client. If the machine on which it’s running fails for any reason, the data held within the database won’t be accessible until the machine is back up and running. If a database management system is able to remain in operation for a higher than normal period of time, it’s said to be highly available.

      One way many databases remain highly available is through a practice known as replication. Replication involves synchronizing data across multiple different databases running on separate machines. This results in multiple copies of the same data and provides redundancy in case one of the database servers fails. This ensures that the synchronized data always remains available to the applications or clients that depend on it.

      In MongoDB, a group of servers that maintain the same data set through replication are referred to as a replica set. Each running instance of MongoDB that’s part of a given replica set is referred to as one of its members. Every replica set must have one primary member and at least one secondary member.

      One advantage that MongoDB’s replica sets have over other replication implementations in other database systems is Mongo’s automatic failover mechanism. In the event that the primary member becomes unavailable, an automated election process happens among the secondary nodes to choose a new primary.

      Scalability

      As a core component of modern applications, it’s important for a database to be able to respond to changes in the amount of work it must perform. After all, an application can see sudden surges in its number of users, or perhaps experience periods of particularly heavy workloads.

      Scalability refers to a computer system’s ability to handle an ever-growing amount of work, and the practice of increasing this capacity is called scaling. There are two ways one can scale a computer system:

      • Vertical scaling — also called scaling up — involves adding more computing resources to a given system, typically by increasing its storage capacity or memory
      • Horizontal scaling — also called, scaling out — involves splitting the workload across multiple computing nodes which, all together, make up a single logical system

      To vertically scale a MongoDB database, one could back up its data and migrate it to another machine with more computing resources. This is generally the same procedure for vertically scaling any database management system, including relational databases. However, scaling up like this can have drawbacks. The cost of using larger and larger machines over time can become prohibitively expensive and, no matter how great it is, there is always an upper limit to how much data a single machine can store.

      Sharding is a strategy some administrators employ for scaling out a database. If you’d like a thorough explanation of sharding, we encourage you to read our conceptual article on Understanding Database Sharding. For the purposes of this article, though, understand that sharding is the process of breaking up a data set based on a given set of rules, and distributing the resulting pieces of data across multiple separate database nodes. A single node that holds part of a sharded cluster’s data set is known as a shard.

      Database management systems don’t always include sharding capabilities as a built-in feature, so oftentimes sharding is implemented at the application level. MongoDB, however, does include a built-in sharding feature which allows you to shard data at the collection level. As of version 3.6, every MongoDB shard must be deployed as a replica set to ensure that the shard’s data remains highly available.

      To shard data in Mongo, you must select one or more fields in a given collection’s documents to function as the shard key. MongoDB then takes the range of shard key values and divides them into non-overlapping ranges, known as chunks, and each chunk is assigned to a given shard.

      Following that, Mongo reads each document’s shard key value, determines what chunk the document belongs to, and then distributes the document to the appropriate shard. MongoDB actively monitors the number of chunks in each shard, and will attempt to migrate chunks from one shard to another to ensure that each has an equal amount.

      The main drawback of sharding is that it adds a degree of operational complexity to a database system. However, once you have a working MongoDB shard cluster, the process of adding more shards to scale the system horizontally is fairly straightforward, and a properly configured replica set can be added as a shard with a single command. This makes MongoDB an appealing choice for applications that need to scale out quickly.

      Is MongoDB Right for my Application?

      Relational database management systems still see wider use than databases that employ a NoSQL model. With that said, though, MongoDB continues to gain ground thanks to the features described throughout this guide. In particular, it’s become a common choice of database for a number of use cases.

      For example, its scaling capabilities and high availability make it a popular database for e-commerce and gaming applications where the number of users being served can increase quickly and dramatically. Likewise, its flexible schema and ability to handle large amounts of unstructured data make it a great choice for content management applications which need to manage an ever-evolving catalog of assets, ranging from text, to video, images, and audio files. It has also seen strong adoption among mobile application developers, thanks again to its powerful scaling as well as its data analysis capabilities.

      When deciding whether you should use MongoDB in your next application, you should first ask yourself what the application’s specific data needs are. If your application will store data that rigidly adheres to a predefined structure, you may not get much additional value from Mongo’s schemaless design and you might be better off using a relational database.

      Then, weigh how much data you expect your application will need to store and use. MongoDB’s document-oriented design makes it a great choice for applications that need to store large amounts of unstructured data. Similarly, MongoDB’s scalability and high availability make it a perfect fit for applications that serve a large and ever-growing number of clients. However, these features could be excessive in cases that aren’t as data intensive.

      Conclusion

      By reading this article, you’ll have gained a better understanding of the features that set MongoDB apart from other database management systems. Although MongoDB is a powerful, flexible, and secure database management system that can be the right choice of database in certain use cases, it may not always be the best choice. While its document-based and schemaless design may not supplant the relational database model any time soon, Mongo’s rapid growth highlights its value as a tool worth understanding.

      For more information about MongoDB, we encourage you to check out DigitalOcean’s entire library of MongoDB content. Additionally, the official MongoDB documentation serves as a valuable resource of information on working with Mongo.



      Source link

      Advantages of Using Kubernetes


      Updated by Linode Contributed by Linode

      What is Kubernetes

      Kubernetes is a container orchestration system that was initially designed by Google to help scale containerized applications in the cloud. Kubernetes can manage the lifecycle of containers, creating and destroying them depending on the needs of the application, as well as providing a host of other features. In the past few years Kubernetes has become one of the most discussed concepts in cloud based application development, and the rise of Kubernetes signals a shift in the way that applications are developed and deployed.

      In general, Kubernetes is formed by a cluster of servers, called Nodes, each running Kubernetes agent processes and communicating with one another. The Master Node is made up of a collection of processes called the control plane that help enact and maintain the desired state of the Kubernetes cluster, while Worker Nodes are responsible for running the containers that form your applications and services.

      For a more in-depth explanation of Kubernetes concepts, see our five-part Beginner’s Guide to Kubernetes.

      What is Managed Kubernetes

      Managed Kubernetes solutions are concerned with the management of one or more parts of a Kubernetes cluster. Because a cluster is formed from a number of different components, there are many different kinds of managed Kubernetes products, and each will solve a different set of problems.

      Why use a managed Kubernetes solution?

      Kubernetes can make managing containers and microservices easier, but Kubernetes itself also requires some administrative overhead. This includes:

      • Performing updates to the Kubernetes control plane and agent software,
      • Monitoring the health of those components, and
      • Monitoring the health of the underlying hardware systems.

      Managed Kubernetes solutions will help offload some or all of this work.

      Here’s a few common categories:

      • Hosted, Managed Kubernetes

        Several cloud computing companies offer products which provision clusters on their platform. The control plane and Master Nodes for these clusters are entirely managed by the platform, which means that all maintenance and updates for the control plane software are carried out by the platform, and the platform monitors the health of the Master Nodes and performs repairs as needed.

        The platform will provide interfaces for the customer to provision cloud instances that serve as Worker Nodes. These instances are pre-configured with Kubernetes’ agent software and are automatically joined to your cluster.

        The customer generally assumes responsibility for deploying and maintaining their applications on the cluster. The Master Nodes are often provided at no cost, and the customer only pays for the Worker Nodes they provision.

        Note

        The upcoming Linode Kubernetes Engine (LKE) is an example of this category.

      • Software-as-a-Service Kubernetes

        Other companies offer Kubernetes-as-a-Service (KaaS) products. These are cloud-based applications which assist in the provisioning and ongoing software maintenance of clusters. However, they do not necessarily provide the server instances which will act as your cluster’s nodes. A frequent use-case for these products is using Kubernetes with on-premise servers:

        • The customer will create or build servers in their on-premise facility. The customer will usually need to complete some prerequisite instructions to prepare their servers for use with the KaaS application.

        • The KaaS application will connect to the customer’s servers and form a cluster from them, where some servers are designated as Master Nodes and others as Worker Nodes. The KaaS product will install the appropriate Kubernetes control plane and agent software.

        • The KaaS application will continue to monitor the on-premise cluster and will perform software maintenance on them over time. The customer will need to perform repairs for any hardware issues on the cluster nodes.

        In this arrangement, the customer is responsible for the cost of the cluster nodes, but much of the administration complexity for Kubernetes is offloaded to the KaaS application.

        It’s also possible to use some KaaS applications with other cloud infrastructure platforms. The KaaS application will provision a cluster that’s formed from cloud instances on the platform, and the customer will pay that platform for all of the nodes in the cluster.

      • Kubernetes management applications

        In addition to cloud-based KaaS applications, there are some Kubernetes management applications that you can install and run on your own infrastructure. These provide a number of the same features as their cloud-hosted counterparts, including:

        While a customer will install and run these management applications on their own servers, the companies that author these applications may also offer support similar to cloud KaaS offerings.

        Note

        An example application in this category is Rancher from Rancher Labs.

      Advantages

      There are many reasons that developers would choose to use Kubernetes as a solution. Below is a short list of advantages and common use cases for implementing Kubernetes.

      Declarative in Nature

      Kubernetes is declarative: describe to Kubernetes the desired state of the cluster and Kubernetes will ensure that this state is always fulfilled. If you want five containers running at any given time, all you need to do is create a Deployment and set the number of replicas to five. And, each set of instructions is rendered in human-readable YAML, which results in further benefits:

      • Version control of your infrastructure. Because the resources in your cluster are declared in code, you can track changes to that code over time in version control systems like Git.

      • Minimization of human error. Kubernetes’ analysis of your configuration files will produce the same results every time it creates your declared resources.

      • Better collaboration among team members. Your configuration files can be tracked in a version control system, so your team members can all contribute to the same centralized code-base and work on your Kubernetes services together.

      Portable, Cloud Agnostic Codebase

      Kubernetes can run on virtually any public cloud, on-premise hardware, or even bare metal. Developing applications for Kubernetes means that code can be redeployed multiple times, allowing you to select the infrastructure of your choosing.

      Note

      There are some caveats to this point. Many cloud infrastructure providers support Kubernetes, but there is no guarantee that they support all of the features of Kubernetes. For example, not every cloud provider offers load balancing as a feature, so a Kubernetes cluster on those providers will not support Services of the type LoadBalancer.

      Microservice Architecture

      In contrast to monolithic applications whose constituent parts are not reusable and modular, Kubernetes encourages application developers to write code as microservices. Microservices are an application architecture that prescribes dividing code into independent, reusable, loosely coupled parts called services. These services run in separate containers that can be scaled depending on the needs of the application. Their small size and loose coupling make them easy to test and deploy in rapid fashion.

      Optimized Resource Usage

      Kubernetes determines which Worker Nodes a container should run on based on available resources. By using Kubernetes you can rest assured that all of your compute resources are utilized efficiently across the cluster. As a result, you may be able to reduce the number of cloud instances or servers you operate, which can lead to cost savings.

      Zero Downtime with Rolling Deployments

      Pods are the smallest unit of computing in Kubernetes, responsible for running your application’s containers. Like many features of Kubernetes, pods have the additional capability of increasing your applications overall uptime when compared to other solutions. For example, consider the process that takes place when the code for your application and its container images has been updated by your team. To update your application running in your cluster, you’ll need a way to update its Pods with the new container images.

      Kubernetes offers a solution with Deployments, which will create additional Pods with the newer image and assure that they are running and healthy before destroying the old Pods. Kubernetes will also roll back any changes should the newer containers fail. In this way there is limited downtime, ensuring a strong user experience.

      Self-Healing

      For many reasons, containers can fail. Kubernetes keeps deployments healthy by restarting containers that have failed, killing and replacing unresponsive containers according to user-defined health checks, and re-creating containers that were on a failed backend Node across other available Nodes. This helps to mitigate what is a common pain point of the application upkeep process.

      Service Discoverability

      It’s important that all services have a predictable way of communicating with one another. However, within Kubernetes, containers are created and destroyed many times over, so a particular service may not exist permanently at a particular location. This traditionally meant that some kind of service registry would need to be created or adapted to the application logic to keep track of each container’s location.

      Kubernetes has a native Service concept which groups your Pods and simplifies service discovery. Kubernetes will provide IP addresses for each Pod, assign a DNS name for each set of Pods, and then load-balance the traffic to the Pods in a set. This creates an environment where the service discovery can be abstracted away from the container level.

      Multi-Container Pods

      Kubernetes Pods often run a single container, but they are capable of running multiple containers as well. This makes adding a loosely coupled, reusable “sidecar” container to a Pod easy. These sidecar containers serve to enhance the primary container running in a Pod; frequent use-cases including adding logging or a service mesh. These coupled containers will share an IP address with the primary container.

      Network Policy as Part of Application Deployment

      By default, all Pods in Kubernetes can communicate with each other. A cluster administrator can declaratively apply networking policies, and these policies can restrict access to certain Pods or Namespaces. Basic network policy restrictions can be enforced by simply providing the name of Pods or Namespaces that you would like to give certain Pods egress and ingress capabilities to.

      Persistent Storage

      While Kubernetes provides a storage solution, called a Volume, that allows data to outlive the lifecycle of a container, the data is still tied to the longevity of the Pod. However, Kubernetes also provides a mechanisms for storing persistent data in cloud storage. In particular, the Container Storage Interface (CSI) specification standard allows Kubernetes to create storage volumes on any cloud platform which supports the CSI.

      For example, the Linode Container Storage Interface (CSI), makes it easy for you to create and attach Linode Block Storage Volumes to your Pods. Even if a Pod that’s attached to the Block Storage Volume is destroyed, the data will persist.

      Cron Jobs

      Kubernetes provides a Jobs object for completing single tasks, like running a one-off script. For regular scheduled tasks, Kubernetes also provides CronJob objects that can complete a task at a certain time, just like the the jobs you might find in a crontab file. This is particularly useful because it provides a declarative way to schedule cron jobs from within a cluster.

      Secrets Management

      One of the hurdles in container creation is the inclusion of secrets, tokens, and passwords. You simply don’t want these sensitive values in your container images, especially if your containers are stored in a public registry like DockerHub. Kubernetes helps to alleviate this burden by providing Secrets objects, an etcd database-backed secrets management solution. With Secrets, you can store sensitive data and later expose that data (for example, via environmental variables to the container), keeping the value out of the container’s code.

      Declarative DNS Management

      Ingress objects in Kubernetes allow for name based virtual hosting and HTTP routing in a straightforward, declarative manner. This means that Kubernetes is capable of directing multiple domains and URL paths to different Services. For instance, domain1.com and domain2.com can be hosted within the same cluster and target different services, and the URL paths /first-service and /second-service can be routed to the service service1 and to service2, respectively.

      Scalability

      Kubernetes makes it easy to horizontally scale the number of containers in use depending on the needs of the application. You can change this number from the command line, or you can use the Horizontal Pod Autoscaler to change the number of containers based on usage metrics.

      Free and Open Source

      Kubernetes is free and open source software (FOSS). While initially developed by Google, Kubernetes has been democratized and is now under the charter of the Cloud Native Computing Foundation (CNCF). Kubernetes is actively developed and maintained, with a number of high-profile companies championing its cause, all but ensuring it will have a long and influential tenure as the de-facto container orchestration solution.

      Additional Use Cases

      Testing Platform

      With Kubernetes it’s easy to create physical or virtual clusters that exactly mirror your production needs:

      • You could create a separate testing cluster and use kubectl contexts to switch between testing and production.

      • Virtual clusters are called Namespaces. You can create Namespaces for testing, staging, and production, and run them all on the same hardware. With ResourceQuotas you can easily limit the CPU and memory resource allocation of the Namespace, ensuring that every Namespace has exactly what it needs to run without stealing resources from other Namespaces.

      CI/CD Pipelines

      A common integration for Kubernetes is setting up a continuous integration/continuous delivery (CI/CD) pipeline. Kubernetes offers the predictability of containers with the ease of service discovery to test, build, and deploy quickly.

      Find answers, ask questions, and help others.

      This guide is published under a CC BY-ND 4.0 license.



      Source link

      Advantages of Using Kubernetes


      Updated by Linode

      Contributed by

      Linode

      What is Kubernetes

      Kubernetes is a container orchestration system that was initially designed by Google to help scale containerized applications in the cloud. Kubernetes can manage the lifecycle of containers, creating and destroying them depending on the needs of the application, as well as providing a host of other features. In the past few years Kubernetes has become one of the most discussed concepts in cloud based application development, and the rise of Kubernetes signals a shift in the way that applications are developed and deployed.

      In general, Kubernetes is formed by a cluster of servers, called Nodes, each running Kubernetes agent processes and communicating with one another. The Master Node is made up of a collection of processes called the control plane that help enact and maintain the desired state of the Kubernetes cluster, while Worker Nodes are responsible for running the containers that form your applications and services.

      For a more in-depth explanation of Kubernetes concepts, see our five-part Beginner’s Guide to Kubernetes.

      What is Managed Kubernetes

      Managed Kubernetes solutions are concerned with the management of one or more parts of a Kubernetes cluster. Because a cluster is formed from a number of different components, there are many different kinds of managed Kubernetes products, and each will solve a different set of problems.


      Why use a managed Kubernetes solution?

      Kubernetes can make managing containers and microservices easier, but Kubernetes itself also requires some administrative overhead. This includes:

      • Performing updates to the Kubernetes control plane and agent software,
      • Monitoring the health of those components, and
      • Monitoring the health of the underlying hardware systems.

      Managed Kubernetes solutions will help offload some or all of this work.

      Here’s a few common categories:

      • Hosted, Managed Kubernetes

        Several cloud computing companies offer products which provision clusters on their platform. The control plane and Master Nodes for these clusters are entirely managed by the platform, which means that all maintenance and updates for the control plane software are carried out by the platform, and the platform monitors the health of the Master Nodes and performs repairs as needed.

        The platform will provide interfaces for the customer to provision cloud instances that serve as Worker Nodes. These instances are pre-configured with Kubernetes’ agent software and are automatically joined to your cluster.

        The customer generally assumes responsibility for deploying and maintaining their applications on the cluster. The Master Nodes are often provided at no cost, and the customer only pays for the Worker Nodes they provision.

        Note

        The upcoming Linode Kubernetes Engine (LKE) is an example of this category.

      • Software-as-a-Service Kubernetes

        Other companies offer Kubernetes-as-a-Service (KaaS) products. These are cloud-based applications which assist in the provisioning and ongoing software maintenance of clusters. However, they do not necessarily provide the server instances which will act as your cluster’s nodes. A frequent use-case for these products is using Kubernetes with on-premise servers:

        • The customer will create or build servers in their on-premise facility. The customer will usually need to complete some prerequisite instructions to prepare their servers for use with the KaaS application.

        • The KaaS application will connect to the customer’s servers and form a cluster from them, where some servers are designated as Master Nodes and others as Worker Nodes. The KaaS product will install the appropriate Kubernetes control plane and agent software.

        • The KaaS application will continue to monitor the on-premise cluster and will perform software maintenance on them over time. The customer will need to perform repairs for any hardware issues on the cluster nodes.

        In this arrangement, the customer is responsible for the cost of the cluster nodes, but much of the administration complexity for Kubernetes is offloaded to the KaaS application.

        It’s also possible to use some KaaS applications with other cloud infrastructure platforms. The KaaS application will provision a cluster that’s formed from cloud instances on the platform, and the customer will pay that platform for all of the nodes in the cluster.

      • Kubernetes management applications

        In addition to cloud-based KaaS applications, there are some Kubernetes management applications that you can install and run on your own infrastructure. These provide a number of the same features as their cloud-hosted counterparts, including:

        While a customer will install and run these management applications on their own servers, the companies that author these applications may also offer support similar to cloud KaaS offerings.

        Note

        An example application in this category is Rancher from Rancher Labs.

      Advantages

      There are many reasons that developers would choose to use Kubernetes as a solution. Below is a short list of advantages and common use cases for implementing Kubernetes.

      Declarative in Nature

      Kubernetes is declarative: describe to Kubernetes the desired state of the cluster and Kubernetes will ensure that this state is always fulfilled. If you want five containers running at any given time, all you need to do is create a Deployment and set the number of replicas to five. And, each set of instructions is rendered in human-readable YAML, which results in further benefits:

      • Version control of your infrastructure. Because the resources in your cluster are declared in code, you can track changes to that code over time in version control systems like Git.

      • Minimization of human error. Kubernetes’ analysis of your configuration files will produce the same results every time it creates your declared resources.

      • Better collaboration among team members. Your configuration files can be tracked in a version control system, so your team members can all contribute to the same centralized code-base and work on your Kubernetes services together.

      Portable, Cloud Agnostic Codebase

      Kubernetes can run on virtually any public cloud, on-premise hardware, or even bare metal. Developing applications for Kubernetes means that code can be redeployed multiple times, allowing you to select the infrastructure of your choosing.

      Note

      There are some caveats to this point. Many cloud infrastructure providers support Kubernetes, but there is no guarantee that they support all of the features of Kubernetes. For example, not every cloud provider offers load balancing as a feature, so a Kubernetes cluster on those providers will not support Services of the type LoadBalancer.

      Microservice Architecture

      In contrast to monolithic applications whose constituent parts are not reusable and modular, Kubernetes encourages application developers to write code as microservices. Microservices are an application architecture that prescribes dividing code into independent, reusable, loosely coupled parts called services. These services run in separate containers that can be scaled depending on the needs of the application. Their small size and loose coupling make them easy to test and deploy in rapid fashion.

      Optimized Resource Usage

      Kubernetes determines which Worker Nodes a container should run on based on available resources. By using Kubernetes you can rest assured that all of your compute resources are utilized efficiently across the cluster. As a result, you may be able to reduce the number of cloud instances or servers you operate, which can lead to cost savings.

      Zero Downtime with Rolling Deployments

      Pods are the smallest unit of computing in Kubernetes, responsible for running your application’s containers. Like many features of Kubernetes, pods have the additional capability of increasing your applications overall uptime when compared to other solutions. For example, consider the process that takes place when the code for your application and its container images has been updated by your team. To update your application running in your cluster, you’ll need a way to update its Pods with the new container images.

      Kubernetes offers a solution with Deployments, which will create additional Pods with the newer image and assure that they are running and healthy before destroying the old Pods. Kubernetes will also roll back any changes should the newer containers fail. In this way there is limited downtime, ensuring a strong user experience.

      Self-Healing

      For many reasons, containers can fail. Kubernetes keeps deployments healthy by restarting containers that have failed, killing and replacing unresponsive containers according to user-defined health checks, and re-creating containers that were on a failed backend Node across other available Nodes. This helps to mitigate what is a common pain point of the application upkeep process.

      Service Discoverability

      It’s important that all services have a predictable way of communicating with one another. However, within Kubernetes, containers are created and destroyed many times over, so a particular service may not exist permanently at a particular location. This traditionally meant that some kind of service registry would need to be created or adapted to the application logic to keep track of each container’s location.

      Kubernetes has a native Service concept which groups your Pods and simplifies service discovery. Kubernetes will provide IP addresses for each Pod, assign a DNS name for each set of Pods, and then load-balance the traffic to the Pods in a set. This creates an environment where the service discovery can be abstracted away from the container level.

      Multi-Container Pods

      Kubernetes Pods often run a single container, but they are capable of running multiple containers as well. This makes adding a loosely coupled, reusable “sidecar” container to a Pod easy. These sidecar containers serve to enhance the primary container running in a Pod; frequent use-cases including adding logging or a service mesh. These coupled containers will share an IP address with the primary container.

      Network Policy as Part of Application Deployment

      By default, all Pods in Kubernetes can communicate with each other. A cluster administrator can declaratively apply networking policies, and these policies can restrict access to certain Pods or Namespaces. Basic network policy restrictions can be enforced by simply providing the name of Pods or Namespaces that you would like to give certain Pods egress and ingress capabilities to.

      Persistent Storage

      While Kubernetes provides a storage solution, called a Volume, that allows data to outlive the lifecycle of a container, the data is still tied to the longevity of the Pod. However, Kubernetes also provides a mechanisms for storing persistent data in cloud storage. In particular, the Container Storage Interface (CSI) specification standard allows Kubernetes to create storage volumes on any cloud platform which supports the CSI.

      For example, the Linode Container Storage Interface (CSI), makes it easy for you to create and attach Linode Block Storage Volumes to your Pods. Even if a Pod that’s attached to the Block Storage Volume is destroyed, the data will persist.

      Cron Jobs

      Kubernetes provides a Jobs object for completing single tasks, like running a one-off script. For regular scheduled tasks, Kubernetes also provides CronJob objects that can complete a task at a certain time, just like the the jobs you might find in a crontab file. This is particularly useful because it provides a declarative way to schedule cron jobs from within a cluster.

      Secrets Management

      One of the hurdles in container creation is the inclusion of secrets, tokens, and passwords. You simply don’t want these sensitive values in your container images, especially if your containers are stored in a public registry like DockerHub. Kubernetes helps to alleviate this burden by providing Secrets objects, an etcd database-backed secrets management solution. With Secrets, you can store sensitive data and later expose that data (for example, via environmental variables to the container), keeping the value out of the container’s code.

      Declarative DNS Management

      Ingress objects in Kubernetes allow for name based virtual hosting and HTTP routing in a straightforward, declarative manner. This means that Kubernetes is capable of directing multiple domains and URL paths to different Services. For instance, domain1.com and domain2.com can be hosted within the same cluster and target different services, and the URL paths /first-service and /second-service can be routed to the service service1 and to service2, respectively.

      Scalability

      Kubernetes makes it easy to horizontally scale the number of containers in use depending on the needs of the application. You can change this number from the command line, or you can use the Horizontal Pod Autoscaler to change the number of containers based on usage metrics.

      Free and Open Source

      Kubernetes is free and open source software (FOSS). While initially developed by Google, Kubernetes has been democratized and is now under the charter of the Cloud Native Computing Foundation (CNCF). Kubernetes is actively developed and maintained, with a number of high-profile companies championing its cause, all but ensuring it will have a long and influential tenure as the de-facto container orchestration solution.

      Additional Use Cases

      Testing Platform

      With Kubernetes it’s easy to create physical or virtual clusters that exactly mirror your production needs:

      • You could create a separate testing cluster and use kubectl contexts to switch between testing and production.

      • Virtual clusters are called Namespaces. You can create Namespaces for testing, staging, and production, and run them all on the same hardware. With ResourceQuotas you can easily limit the CPU and memory resource allocation of the Namespace, ensuring that every Namespace has exactly what it needs to run without stealing resources from other Namespaces.

      CI/CD Pipelines

      A common integration for Kubernetes is setting up a continuous integration/continuous delivery (CI/CD) pipeline. Kubernetes offers the predictability of containers with the ease of service discovery to test, build, and deploy quickly.

      Find answers, ask questions, and help others.

      This guide is published under a CC BY-ND 4.0 license.



      Source link