Workload with NodePort Quick Start


Prerequisite

You have a running cluster with at least 1 node.

1. Deploying a Workload

You’re ready to create your first Kubernetes workload. A workload is an object that includes pods along with other files and info needed to deploy your application.

For this workload, you’ll be deploying the application Rancher Hello-World.

  1. Click ☰ > Cluster Management.
  2. From the Clusters page, go to the cluster where the workload should be deployed and click Explore.
  3. Click Workload.
  4. Click Create.
  5. Enter a Name for your workload.
  6. From the Container Image field, enter rancher/hello-world. This field is case-sensitive.
  7. Click Add Port.
  8. From the Service Type drop-down, make sure that NodePort is selected.

    As a dropdown, NodePort (On every node selected)

  9. From the Publish the container port field, enter port 80.

    Publish the container port, 80 entered

  10. Click Create.

Result:

  • Your workload is deployed. This process might take a few minutes to complete.
  • When your workload completes deployment, it’s assigned a state of Active. You can view this status from the project’s Workloads page.

2. Viewing Your Application

From the Workloads page, click the link underneath your workload. If your deployment succeeded, your application opens.

Attention: Cloud-Hosted Sandboxes

When using a cloud-hosted virtual machine, you may not have access to the port running the container. In this event, you can test Nginx in an ssh session on the local machine using Execute Shell. Use the port number after the : in the link under your workload if available, which is 31568 in this example.

  1. gettingstarted@rancher:~$ curl http://localhost:31568
  2. <!DOCTYPE html>
  3. <html>
  4. <head>
  5. <title>Rancher</title>
  6. <link rel="icon" href="img/favicon.png">
  7. <style>
  8. body {
  9. background-color: white;
  10. text-align: center;
  11. padding: 50px;
  12. font-family: "Open Sans","Helvetica Neue",Helvetica,Arial,sans-serif;
  13. }
  14. button {
  15. background-color: #0075a8;
  16. border: none;
  17. color: white;
  18. padding: 15px 32px;
  19. text-align: center;
  20. text-decoration: none;
  21. display: inline-block;
  22. font-size: 16px;
  23. }
  24. #logo {
  25. margin-bottom: 40px;
  26. }
  27. </style>
  28. </head>
  29. <body>
  30. <img id="logo" src="img/rancher-logo.svg" alt="Rancher logo" width=400 />
  31. <h1>Hello world!</h1>
  32. <h3>My hostname is hello-world-66b4b9d88b-78bhx</h3>
  33. <div id='Services'>
  34. <h3>k8s services found 2</h3>
  35. <b>INGRESS_D1E1A394F61C108633C4BD37AEDDE757</b> tcp://10.43.203.31:80<br />
  36. <b>KUBERNETES</b> tcp://10.43.0.1:443<br />
  37. </div>
  38. <br />
  39. <div id='rancherLinks' class="row social">
  40. <a class="p-a-xs" href="https://rancher.com/docs"><img src="img/favicon.png" alt="Docs" height="25" width="25"></a>
  41. <a class="p-a-xs" href="https://slack.rancher.io/"><img src="img/icon-slack.svg" alt="slack" height="25" width="25"></a>
  42. <a class="p-a-xs" href="https://github.com/rancher/rancher"><img src="img/icon-github.svg" alt="github" height="25" width="25"></a>
  43. <a class="p-a-xs" href="https://twitter.com/Rancher_Labs"><img src="img/icon-twitter.svg" alt="twitter" height="25" width="25"></a>
  44. <a class="p-a-xs" href="https://www.facebook.com/rancherlabs/"><img src="img/icon-facebook.svg" alt="facebook" height="25" width="25"></a>
  45. <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>
  46. </div>
  47. <br />
  48. <button class='button' onclick='myFunction()'>Show request details</button>
  49. <div id="reqInfo" style='display:none'>
  50. <h3>Request info</h3>
  51. <b>Host:</b> 172.22.101.111:31411 <br />
  52. <b>Pod:</b> hello-world-66b4b9d88b-78bhx </b><br />
  53. <b>Accept:</b> [*/*]<br />
  54. <b>User-Agent:</b> [curl/7.47.0]<br />
  55. </div>
  56. <br />
  57. <script>
  58. function myFunction() {
  59. var x = document.getElementById("reqInfo");
  60. if (x.style.display === "none") {
  61. x.style.display = "block";
  62. } else {
  63. x.style.display = "none";
  64. }
  65. }
  66. </script>
  67. </body>
  68. </html>
  69. gettingstarted@rancher:~$

Finished

Congratulations! You have successfully deployed a workload exposed via a NodePort.

What’s Next?

When you’re done using your sandbox, destroy the Rancher Server and your cluster. See one of the following: