2017-08-14 132 views
1

我是Kubernetes的新手& Docker。我創建了一個簡單的nodejs應用程序並部署在BlueMix Kubernetes上。但我無法訪問互聯網上的應用程序。 kubernetes中提到的端口ip &無法訪問。有人可以幫助我嗎?我試過http://10.76.193.146:31972,但它沒有通過。我不確定這個公衆ip是否是它的第10個系列。部署在Kubernetes上的應用程序無法從Internet訪問

我也試過公共ip(http://184.173.1.79:31972)中提到的藍色混合kubernetes集羣 - 截圖如下。但那也失敗了。

這是我遵循的步驟。

  1. 在本地創建nodejs應用程序。它運行在本地
// Load the http module to create an http server. 
var http = require('http'); 

// Configure our HTTP server to respond with Hello World to all requests. 
var server = http.createServer(function (request, response) { 
    response.writeHead(200, {"Content-Type": "text/plain"}); 
    response.end("Hello World\n"); 
}); 

// Listen on port 8000, IP defaults to 127.0.0.1 
server.listen(8000); 

// Put a friendly message on the terminal 
console.log("Server running at http://127.0.0.1:8000/"); 

----------的package.json如期望

{ 
    "name": "helloworld-nodejs", 
    "version": "0.0.1", 
    "description": "First Docker", 
    "main": "app.js", 
    "scripts": { 
    "start": "PORT=8000 node ./app.js" 
    }, 
    "author": "", 
    "license": "ISC" 
} 
  • 在本地創建碼頭集裝箱並運行碼頭工人。一切正常

  • 上傳於Bluemix註冊表中的泊塢窗容器作爲

    registry.ng.bluemix.net/testkubernetes/helloworld-nodejs:0.0。1

  • 創建於Kubernetes節點和服務,使用下面的YAML文件

  • ----------節點YAML文件

    apiVersion: v1 
    kind: Pod 
    metadata: 
        name: helloworld-nodejs 
        labels: 
        name: helloworld-nodejs 
    spec: 
        containers: 
        - name: helloworld-nodejs 
         image: registry.ng.bluemix.net/testkubernetes/helloworld-nodejs:0.0.1 
         ports: 
         - containerPort: 8000 
    

    ----------服務YAML

    apiVersion: v1 
    kind: Service 
    metadata: 
        name: helloworld-nodejs 
        labels: 
        name: helloworld-nodejs 
    spec: 
        type: NodePort 
        selector: 
        name: helloworld-nodejs 
        ports: 
        - port: 8080 
    
  • 應用程序獲取正確部署和也在運行,我可以從日誌中確認的
  • enter image description here enter image description here

    結果kubectl GET services & kubectl get nodes命令

    Result of kubectl get services

    Result of kubectl get nodes

    enter image description here

    回答

    3

    由於您服務的port是從吊艙的containerPort,你將不得不在你的服務指定targetPort不同。

    spec: 
        type: NodePort 
        selector: 
        name: helloworld-nodejs 
        ports: 
        - port: 8080 
         targetPort: 8000 
    

    據對targetPort的Kubernetes documentation,它是:

    號碼或姓名端口的訪問由 服務針對的豆莢。 ....如果未指定,則使用「端口」字段 的值(一個標識映射)。

    +0

    謝謝ivan ...問題已解決 – bukubapi

    相關問題