Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does Travix deploy the application to Kubernetes?

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how Travix deploys applications to Kubernetes". The explanation in this article is simple and clear, easy to learn and understand. Please follow the editor's ideas to study and learn "how to deploy applications to Kubernetes by Travix".

Connect to Kubernetes

Before we begin, make sure that you have created a Google GCE cluster on Google Cloud console and that you have installed the gcloud command-line tool on your computer.

The kubectl command line tool can be installed through gcloud cli.

With the following command, you can install kubectl to communicate with your cluster. Make sure that your own cluster replaces the name and zone with the correct values.

Namespace

In Kubernetes, you run your application in one of the namespace; in the same namespace, you can find other applications by service name. Quarantined namespace allows you to reuse the same service name on different namespace in order to run applications on those namespace. This allows you to create different "environments" on the same cluster if you want to. For development, testing, acceptance and production, you need to create 4 separate namespace.

Namespace is used to set up other components, so let's start by creating a namespace. Save a file named "namespace.yaml" with the following.

Then run the following command line to create a namespace in Kubernetes.

Service

Service in Kubernetes is the portal to communicate with the application. It can be used to access applications within the Kubernetes cluster or to expose applications through external load balancers connected to the public network. What we need to do here is the latter.

On the outside, you can use URL: http:///. To visit service. As long as it is in the same namespace, it automatically resolves to service. When configured as an external load balancer service, it is still feasible.

Externally, it uses a load balancer and a simple IP to direct to the same service.

Use this to create a file called "service.yaml".

Then create it in Kubernetes by running the following command.

In service, selectors are used to communicate directly with all applications by matching tags. The application needs to use the same name as the port for targetport. In this case, we named the port http, which you will see later in the configuration list.

With the type setting of the load balancer, the network connection load balancer is automatically created on Google's cloud platform and listens on port 80.

Wait for the IP address of the network load balancer to have a bash script.

You can now use this IP to connect to service or set a DNS record for it. In Travix, this is done automatically from the deployment script.

Pod

In order to run the container on Kubernetes, the concept of "pod" is used. A Pod is one or more closely related container groups. They turn on or run together, and they are on the same host.

Each Pod has a dedicated IP address on the Kubernetes cluster. Multiple pod can run on the same host, at the same time, the pod is independent of each other. Applications can communicate using the same port in different pod without causing any problems. Outside of pod, their ports are NAT, allowing multiple applications to run on the same host using the same port.

In pod, localhost resolves to pod instead of the host running pod. This can be used to allow multiple applications to run on the same pod to communicate with each other, using localhost and the original port on which the application listens. In this way, communication in pod is faster and more secure, because it does not attack the network.

At Travix, we use pod to move some crosscutting concerns out of our application and into dedicated containers. Each pod--, in addition to running on the main application deployed-- also runs HAProxy for the TLS terminal. In this blog post, we are just running a single container in pod. Next you will see how a pod is configured and used for your application.

Deployment

Now that service is set up, it has no place to send traffic, because there is no tagged pod in service to match the selector. Decoupling between these service and pods in Kubernetes allows you to create them in any order.

The easiest way to create these pod is to use deployment objects, even in beta. It uses a manifest that specifies what containers are running in pod, what environment variables are injected into these containers, which ports are exposed, and what pod is labeled.

Deployment is a high level of abstraction. When created, it creates a ReplicaSet to take care of the creation of some pod, which is equivalent to configuring a certain number of copies. For each new deployment, a new ReplicaSet is created, but for a quick rollback, it maintains the original, the maximum value of ReplicaSet equal to the value of revisionHistoryLimit. The rolling update of the deployment ensures that all old ReplicaSet has been updated to 0 replicas and that only the latest pods is running.

Create a file called "deployment.yaml" with the following and replace the container image with yours and the correct port it listens on.

To start the deployment, run the following command

The selector in the Deployment listing is used to match the ReplicaSets created by Deployment. When redeploying, be sure to be consistent, otherwise it will create a new ReplicaSet, do not need to set replica, set the other ReplicaSets to 0.

Although the application listener port 5000 dint service uses port 80, it automatically NAT the port because of the port name it uses-- http--, and hides the conversion process from the point of view of the service user.

Deploy the new version

When you want to deploy the next version, update the image tag and version tag in the list, and run it again.

It's that simple. Depoyment then runs a rolling update to replace pod with a new one at a time. In this way, when only three replicas are used, it usually takes less than half a minute.

The Kubectl apply command does not wait for deployment to finish, so you have to skip some steps.

At present, we use the following content to do.

You may want to make sure that you set a time limit to wait for the deployment to complete, and if it takes a long time to roll back using the following command.

Template list

Bash does not have a template engine, but the basic form of replacement in the list can be done as follows. Use variable tags in your list and be sure to use curly braces.

And run the following command to replace the variables in the list, and then create a namespace from the final list.

Or, if you have gettext installed, you can use a shorter command line.

For all objects, we have used the same list that can be reapplied, and if it does not exist, Kubernetes will create one, or if it already exists, Kubernetes will update. So, every time you deploy, you can re-apply service, namespace, and deployment without side effects.

Hopefully this article will give you the core concepts of Kubernetes, show you how easy it is to run your application on the container engine, and give you an overview of how to automate deployment.

Thank you for your reading, the above is the content of "how Travix deploys the application to Kubernetes". After the study of this article, I believe you have a deeper understanding of how Travix deploys the application to Kubernetes, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report