使用 NodePort 的工作負載快速入門
先決條件
您有一個至少包含 1 個節點的執行中叢集。
1. 部署工作負載
您已準備好建立第一個 Kubernetes 工作負載。工作負載是一個物件,包含 Pod 以及部署應用程式所需的其他檔案和資訊。
在此工作負載中,您將部署 Rancher Hello-World 應用程式。
-
點擊 ☰ > Cluster Management。
-
從 Clusters 頁面,前往應部署工作負載的叢集並點擊 Explore。
-
點擊 Workload。
-
點擊 Create。
-
為您的工作負載輸入 Name。
-
在 Container Image 欄位中,輸入
rancher/hello-world。此欄位區分大小寫。 -
點擊 Add Port。
-
從 Service Type 下拉選單中,確保已選擇 NodePort。
-
在 Publish the container port 欄位中,輸入連接埠
80。 -
點擊 Create。
結果:
- 您的工作負載已部署。此過程可能需要幾分鐘才能完成。
- 當您的工作負載完成部署後,它會被指派為 Active 狀態。您可以從專案的 Workloads 頁面查看此狀態。
2. 檢視您的應用程式
從 Workloads 頁面,點擊您的工作負載下方的連結。如果您的部署成功,您的應用程式將會開啟。
注意:雲端託管的沙盒
使用雲端託管的虛擬機器時,您可能無法存取執行容器的連接埠。在這種情況下,您可以使用 Execute Shell 在本機的 ssh 工作階段中測試 Nginx。如果可用,請使用您的工作負載下方連結中 : 後面的連接埠號碼,在此範例中為 31568。
gettingstarted@rancher:~$ curl http://localhost:31568
<!DOCTYPE html>
<html>
<head>
<title>Rancher</title>
<link rel="icon" href="img/favicon.png">
<style>
body {
background-color: white;
text-align: center;
padding: 50px;
font-family: "Open Sans","Helvetica Neue",Helvetica,Arial,sans-serif;
}
button {
background-color: #0075a8;
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
}
#logo {
margin-bottom: 40px;
}
</style>
</head>
<body>
<img id="logo" src="img/rancher-logo.svg" alt="Rancher logo" width=400 />
<h1>Hello world!</h1>
<h3>My hostname is hello-world-66b4b9d88b-78bhx</h3>
<div id='Services'>
<h3>k8s services found 2</h3>
<b>INGRESS_D1E1A394F61C108633C4BD37AEDDE757</b> tcp://10.43.203.31:80<br />
<b>KUBERNETES</b> tcp://10.43.0.1:443<br />
</div>
<br />
<div id='rancherLinks' class="row social">
<a class="p-a-xs" href="https://rancher.com/docs"><img src="img/favicon.png" alt="Docs" height="25" width="25"></a>
<a class="p-a-xs" href="https://slack.rancher.io/"><img src="img/icon-slack.svg" alt="slack" height="25" width="25"></a>
<a class="p-a-xs" href="https://github.com/rancher/rancher"><img src="img/icon-github.svg" alt="github" height="25" width="25"></a>
<a class="p-a-xs" href="https://twitter.com/Rancher_Labs"><img src="img/icon-twitter.svg" alt="twitter" height="25" width="25"></a>
<a class="p-a-xs" href="https://www.facebook.com/rancherlabs/"><img src="img/icon-facebook.svg" alt="facebook" height="25" width="25"></a>
<a class="p-a-xs" href="https://www.linkedin.com/groups/6977008/profile"><img src="img/icon-linkedin.svg" height="25" alt="linkedin" width="25"></a>
</div>
<br />
<button class='button' onclick='myFunction()'>Show request details</button>
<div id="reqInfo" style='display:none'>
<h3>Request info</h3>
<b>Host:</b> 172.22.101.111:31411 <br />
<b>Pod:</b> hello-world-66b4b9d88b-78bhx </b><br />
<b>Accept:</b> [*/*]<br />
<b>User-Agent:</b> [curl/7.47.0]<br />
</div>
<br />
<script>
function myFunction() {
var x = document.getElementById("reqInfo");
if (x.style.display === "none") {
x.style.display = "block";
} else {
x.style.display = "none";
}
}
</script>
</body>
</html>
gettingstarted@rancher:~$
完成
恭喜!您已成功部署透過 NodePort 公開的工作負載。
下一步是什麼?
當您使用完沙盒後,請銷毀 Rancher 伺服器和您的叢集。請參閱以下其中一項: