In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Kubernetes is one of the main topics I study. I know that not only me, but also a certain number of people are willing to further use and study it after work.
This article is about how to create an efficient Kubernetes cluster for development purposes using Terraform and Rancher 2.x on Scaleway. I assume you already know (or at least have heard of):
Kubernetes
Terraform
Rancher
Scaleway
Cloudflare
An overview
The following figure outlines what this article is trying to achieve:
Most of the deployment will be done automatically by Terraform. We will create a Rancher server and add a Rancher proxy to it to create and manage the Kubernetes cluster. Domain resolution will also be automatically configured to Cloudflare by Terraform. All the servers will be deployed on Scaleway, and they are very cheap (at the time of this writing, the Start1-S server only takes hours 3.99/mo and 0.008 hours! )
Why choose Rancher?
If you want to learn Kubernetes from scratch to become a kubectl magician, this is a good starting point, I have no objection. But in my opinion, just learning Kuberenetes is not enough, what is more important is what you want to do with it and what you want to achieve. For example, I often develop microservices and features for testing (especially webhook integration) and run it on Kubernetes. Of course, kubectl helps a lot in managing Kubernetes, but when I want to check the logs of some services or create some secrets, I have to use kubectl to type a lot of commands to create a lot of listings, which often make me tired. Sometimes I just want to simply deploy resources instead of using lists. I know there are many tools (such as stern, ksonnet, etc.) that can help implement these workflows, but I have been loyal users since Rancher 1.x, knowing that their UI can make work easier and intuitive. That's why I include Rancher in this toolset.
Let's get started!
Needless to say, let's start deploying some resources. Here are some preparations:
Prepare a Scaleway account
Prepare a Cloudflare account
Set at least 1 zone in Cloudflare (you can get a free service domain such as Freenom)
Clone kenfdev/rancher-scaleway repository
Install terraform
Install kubectl
I will not explain these contents in detail, because if all of them are written, this article will explode. You can search for relevant resources on your own.
Here is an important hint. We will deploy servers on Scaleway, none of which is free. So to confirm this beforehand, it will cost some money (but Scaleway is very cheap). I will not bear any responsibility for these costs, so if you finish them, be sure to destroy them.
Get information from Scaleway
We will automatically deploy the server on Scaleway, so we need to have a token for this. In Scaleway, go to the Credentials page and click Create new token. Make a note of the Secret key, because we will use this later.
At the same time, go to the Account page to find ORGANIZATION ID and make a record. So far you have finished the part of Scaleway, Terraform will take care of other things.
Get API token from Cloudflare
We need to set up DNS for the Rancher server we created, and to do this, we need to get the API token of Cloudflare. Go to My Profile under Cloudflare and you can find API Keys here. Click the View button for Global API Key as shown in the figure below.
Now record the token, and the work of gathering information here is over.
Prepare Terraform resources for the Rancher server
Now that we have the information we need to collect, the next step is to deploy it with Terraform. Let's go to the clone kenfdev/rancher-scaleway warehouse.
First, go to the rancherserver directory, create a tfvars file according to terraform.tfvars.sample, and open it:
The tfvars file looks like this:
These changes need to be made:
Scw_token.-your Scaleway Secret Token.
Scw_org.-your Scaleway Organization ID.
Admin_password-the password you will use on the Rancher server
Rancher_server_url-the URL used by the Rancher server. Terraform will set up a Rancher subdomain for your cloudflare zone. So if your zone is called example.com, then terraform will create a record link to rancher.example.com.
Cloudflare_email-Email in your Cloudflare
Cloudflare_token.-API token of your Cloudflare.
Cloudflare_zone.-your Cloudflare zone.
You can also modify other variables according to your own needs.
Deploy Rancher Server
Now that we're ready, let's deploy with Terraform! Click terraform apply and you will see a display like this:
Five resources?
"Why five resources? didn't we just deploy one server?" You might ask, but we did deploy more than one resource, we deployed:
1 server (Rancher server)
1 user data for booting the Rancher server for the cloud-init process
1 security group
A rule attached to a security group to control traffic
1 Cloudflare DNS record pointing to the Rancher server
So five resources have been added, now click yes. If all goes well, you should be able to see the message:
If you check the Scaleway:
It looks like the server is deployed, so what about DNS?
It also seems to have been added to Cloudflare! Now let's use this address to access the Rancher server:
Https://rancher.your.zone/
If you are using Chrome, you should see a warning.
This is because you have not set up a legal SSL certificate for the server. Click the button in the lower left corner to ignore the warning and force access to the page.
Look at that! We deployed a Rancher server with DNS with 1 command! Isn't that cool! Enter the password you set in tfvars and you should be able to log in.
Now you have a working Rancher server! You can start creating Kubernetes clusters for various locations on UI, but these use cases are not covered in this article. Instead, we will use Terraform here to create a Rancher proxy on Scaleway and automatically set up these clusters managed by the Rancher server.
Prepare Terraform resources for the Rancher agent
Return to the kenfdev/rancher-scaleway warehouse. Now, go to the rancheragent directory. Also copy a copy of terraform.tfvars.sample to terraform.tfvars.
Now open terraform.tfvars:
Fill in the credential information as in the Rancher server, and here are some variables to remember:
The address of rancher_server_address-Rancher Serve, which may be an IP or a domain name, but I suggest you set it as a domain name in the previous steps
Count_agent_all_nodes-Statistics the number of nodes created with all roles (etcd, controlplane, worker). If you just want to experience the Kubernetes cluster, then one is enough.
Count_agent_etcd_nodes-Statistics on the number of nodes with etcd role created
Count_agent_controlplane-Statistics on the number of nodes with controlplane role created
Count_agent_worker_nodes-Statistics on the number of nodes with worker role created
Deploy the Rancher agent
Now click terraform apply again to deploy the rancher agent to Scaleway.
Select yes and the server is deployed. After a few minutes, you can see that the resources have been deployed:
At the same time, under the UI of the Rancher server, you can see that a new cluster is registered.
After a while, you can see that the Kubernetes cluster has been deployed (Active)!
That's cool, too, right? We can create our own Kubernetes cluster on Internet (Scaleway) with just a few lines of command!
Test the Ingress controller
Now that we can use Kubernetes clustering, let's see if the Nginx Ingress controller works as expected. In the rancheragent directory, open the dns.tf file and add the following information:
This creates a Cloudflare record to point to the Rancher proxy node with all roles. Click terraform apply and set the DNS in Cloudflare.
Now that we have access to http://default.your.zone, we have not configured any Ingress on the cluster, so we need to access the default backend.
Hey! Hey! We can see that the Ingress controller is working as we expected.
Access the cluster through kubectl
Finally, let's see if we can access the cluster through kubectl. Pulling kubeconfig is very easy. Just find the button at the cluster layer:
Copy or download the config file to model:
Use kubectl and KUBECONFIG to get some information
What about pods when you successfully get the information about the node?
You can easily get information with a simple kubectl, and you can also deploy resources through Rancher UI or kubectl.
Clean up
If you want to continue to use the cluster, you can continue to use it from now on, but what I'm going to show you next is how to clean it up if you've finished using it.
Destroy Rancher agents and Cloudflare resources
Execute the following command:
Destroy Rancher servers and Cloudflare resources
Make sure there are no resources on the Scaleway (only the default security group). Otherwise you will have to pay for these resources.
Total knot
There are several ways to take advantage of this workflow, but I prefer not to use Rancher Server directly, but to create and destroy Rancher Agent (and Kubernetes clusters) frequently.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.