diff --git a/content/en/blog/_posts/2016-01-00-Simple-Leader-Election-With-Kubernetes.md b/content/en/blog/_posts/2016-01-00-Simple-Leader-Election-With-Kubernetes.md index f2e059561ac5b..51be4e6e0e270 100644 --- a/content/en/blog/_posts/2016-01-00-Simple-Leader-Election-With-Kubernetes.md +++ b/content/en/blog/_posts/2016-01-00-Simple-Leader-Election-With-Kubernetes.md @@ -100,41 +100,41 @@ var http = require('http'); // This will hold info about the current master var master = {}; - // The web handler for our nodejs application - var handleRequest = function(request, response) { - response.writeHead(200); - response.end("Master is " + master.name); - }; - - // A callback that is used for our outgoing client requests to the sidecar - var cb = function(response) { - var data = ''; - response.on('data', function(piece) { data = data + piece; }); - response.on('end', function() { master = JSON.parse(data); }); - }; - - // Make an async request to the sidecar at http://localhost:4040 - var updateMaster = function() { - var req = http.get({host: 'localhost', path: '/', port: 4040}, cb); - req.on('error', function(e) { console.log('problem with request: ' + e.message); }); - req.end(); - }; - - / / Set up regular updates - updateMaster(); - setInterval(updateMaster, 5000); - - // set up the web server - var www = http.createServer(handleRequest); - www.listen(8080); - ``` - Of course, you can use this sidecar from any language that you choose that supports HTTP and JSON. +// The web handler for our nodejs application +var handleRequest = function(request, response) { + response.writeHead(200); + response.end("Master is " + master.name); +}; + +// A callback that is used for our outgoing client requests to the sidecar +var cb = function(response) { + var data = ''; + response.on('data', function(piece) { data = data + piece; }); + response.on('end', function() { master = JSON.parse(data); }); +}; + +// Make an async request to the sidecar at http://localhost:4040 +var updateMaster = function() { + var req = http.get({host: 'localhost', path: '/', port: 4040}, cb); + req.on('error', function(e) { console.log('problem with request: ' + e.message); }); + req.end(); +}; + +/ / Set up regular updates +updateMaster(); +setInterval(updateMaster, 5000); + +// set up the web server +var www = http.createServer(handleRequest); +www.listen(8080); +``` +Of course, you can use this sidecar from any language that you choose that supports HTTP and JSON. #### Conclusion - Hopefully I've shown you how easy it is to build leader election for your distributed application using Kubernetes. In future installments we'll show you how Kubernetes is making building distributed systems even easier. In the meantime, head over to [Google Container Engine][2] or [kubernetes.io][3] to get started with Kubernetes. +Hopefully I've shown you how easy it is to build leader election for your distributed application using Kubernetes. In future installments we'll show you how Kubernetes is making building distributed systems even easier. In the meantime, head over to [Google Container Engine][2] or [kubernetes.io][3] to get started with Kubernetes. - [1]: https://github.com/kubernetes/contrib/pull/353 - [2]: https://cloud.google.com/container-engine/ - [3]: http://kubernetes.io/ +[1]: https://github.com/kubernetes/contrib/pull/353 +[2]: https://cloud.google.com/container-engine/ +[3]: http://kubernetes.io/ diff --git a/content/zh-cn/blog/_posts/2016-01-00-Simple-Leader-Election-With-Kubernetes.md b/content/zh-cn/blog/_posts/2016-01-00-Simple-Leader-Election-With-Kubernetes.md index 897c2828d7e05..a15246fac28ae 100644 --- a/content/zh-cn/blog/_posts/2016-01-00-Simple-Leader-Election-With-Kubernetes.md +++ b/content/zh-cn/blog/_posts/2016-01-00-Simple-Leader-Election-With-Kubernetes.md @@ -212,35 +212,35 @@ var http = require('http'); // This will hold info about the current master var master = {}; - // The web handler for our nodejs application - var handleRequest = function(request, response) { - response.writeHead(200); - response.end("Master is " + master.name); - }; - - // A callback that is used for our outgoing client requests to the sidecar - var cb = function(response) { - var data = ''; - response.on('data', function(piece) { data = data + piece; }); - response.on('end', function() { master = JSON.parse(data); }); - }; - - // Make an async request to the sidecar at http://localhost:4040 - var updateMaster = function() { - var req = http.get({host: 'localhost', path: '/', port: 4040}, cb); - req.on('error', function(e) { console.log('problem with request: ' + e.message); }); - req.end(); - }; - - / / Set up regular updates - updateMaster(); - setInterval(updateMaster, 5000); - - // set up the web server - var www = http.createServer(handleRequest); - www.listen(8080); - ``` - Of course, you can use this sidecar from any language that you choose that supports HTTP and JSON. +// The web handler for our nodejs application +var handleRequest = function(request, response) { + response.writeHead(200); + response.end("Master is " + master.name); +}; + +// A callback that is used for our outgoing client requests to the sidecar +var cb = function(response) { + var data = ''; + response.on('data', function(piece) { data = data + piece; }); + response.on('end', function() { master = JSON.parse(data); }); +}; + +// Make an async request to the sidecar at http://localhost:4040 +var updateMaster = function() { + var req = http.get({host: 'localhost', path: '/', port: 4040}, cb); + req.on('error', function(e) { console.log('problem with request: ' + e.message); }); + req.end(); +}; + +/ / Set up regular updates +updateMaster(); +setInterval(updateMaster, 5000); + +// set up the web server +var www = http.createServer(handleRequest); +www.listen(8080); +``` +Of course, you can use this sidecar from any language that you choose that supports HTTP and JSON. --> 例如,这里有一个简单的 Node.js 应用程序,它连接到 leader election sidecar 并打印出它当前是否是 master。默认情况下,leader election sidecar 将其标识符设置为 `hostname`。 @@ -250,52 +250,52 @@ var http = require('http'); // This will hold info about the current master var master = {}; - // The web handler for our nodejs application - var handleRequest = function(request, response) { - response.writeHead(200); - response.end("Master is " + master.name); - }; - - // A callback that is used for our outgoing client requests to the sidecar - var cb = function(response) { - var data = ''; - response.on('data', function(piece) { data = data + piece; }); - response.on('end', function() { master = JSON.parse(data); }); - }; - - // Make an async request to the sidecar at http://localhost:4040 - var updateMaster = function() { - var req = http.get({host: 'localhost', path: '/', port: 4040}, cb); - req.on('error', function(e) { console.log('problem with request: ' + e.message); }); - req.end(); - }; - - / / Set up regular updates - updateMaster(); - setInterval(updateMaster, 5000); - - // set up the web server - var www = http.createServer(handleRequest); - www.listen(8080); - ``` - 当然,您可以从任何支持 HTTP 和 JSON 的语言中使用这个 sidecar。 +// The web handler for our nodejs application +var handleRequest = function(request, response) { + response.writeHead(200); + response.end("Master is " + master.name); +}; + +// A callback that is used for our outgoing client requests to the sidecar +var cb = function(response) { + var data = ''; + response.on('data', function(piece) { data = data + piece; }); + response.on('end', function() { master = JSON.parse(data); }); +}; + +// Make an async request to the sidecar at http://localhost:4040 +var updateMaster = function() { + var req = http.get({host: 'localhost', path: '/', port: 4040}, cb); + req.on('error', function(e) { console.log('problem with request: ' + e.message); }); + req.end(); +}; + +/ / Set up regular updates +updateMaster(); +setInterval(updateMaster, 5000); + +// set up the web server +var www = http.createServer(handleRequest); +www.listen(8080); +``` +当然,您可以从任何支持 HTTP 和 JSON 的语言中使用这个 sidecar。 #### 结论 - 希望我已经向您展示了使用 Kubernetes 为您的分布式应用程序构建 leader election 是多么容易。在以后的部分中,我们将向您展示 Kubernetes 如何使构建分布式系统变得更加容易。同时,转到[Google Container Engine][2]或[kubernetes.io][3]开始使用Kubernetes。 +希望我已经向您展示了使用 Kubernetes 为您的分布式应用程序构建 leader election 是多么容易。在以后的部分中,我们将向您展示 Kubernetes 如何使构建分布式系统变得更加容易。同时,转到[Google Container Engine][2]或[kubernetes.io][3]开始使用Kubernetes。 - [1]: https://github.com/kubernetes/contrib/pull/353 - [2]: https://cloud.google.com/container-engine/ - [3]: http://kubernetes.io/ \ No newline at end of file +[1]: https://github.com/kubernetes/contrib/pull/353 +[2]: https://cloud.google.com/container-engine/ +[3]: http://kubernetes.io/ \ No newline at end of file