Comment on page
Expose a Kubernetes workload in a track tab
This guide explains how to expose a Kubernetes **** workload in a track tab.
A Kubernetes workload is an application running on Kubernetes—for example, a webserver.
After installing a Kubernetes workload on a Kubernetes virtual machine in a track, you need to expose the workload in a tab so learners can interact with it. Exposing is done through a NodePort, which is an open port on every node of your Kubernetes cluster.
By setting the NodePort, for example, port
30001
, for the Kubernetes workload and the track tab, you expose the Kubernetes workload in the track tab. Because the NodePort then sits like a gateway between the Kubernetes workload and the track tab.Now let's install a Kubernetes workload and expose it in a track tab. You will use the NGINX web server as the Kubernetes workload that will be exposed.
🌐 Web UI
💻 Instruqt CLI
- 1.
- 2.Click Create track. Select Start from scratch from the dropdown. ↳ Instruqt creates an empty track and shows the Track dashboard page.
- 3.In the Settings section, click Edit. ↳ The Track details pop-up opens.
- 4.In the Track name field, enter the track name. ↳ As you enter the name, Instruqt automatically generates a URL in the Track URL field.
- 5.Leave the Track URL field as created by Instruqt or enter the URL of your liking.
If you have changed the automatically created track URL and then update the name again, Instruqt regenerates the track URL.
- 1.In the Description field, enter the track description in Markdown.
- 2.Click Save. ↳ Instruqt closes the Track details pop-up.
- 3.In the Sandbox section, click Edit. ↳ Instruqt shows the Sandbox page.
- 4.Click + Add a host.
- 5.Select the Virtual machine host type.
- 6.In the Hostname field, enter a name for the host—for example,
kubernetes-vm
. - 7.Select the Preset image type, followed by Kubernetes.
- 8.Click Save host, followed by Back to track. ↳ Instruqt returns to the Track dashboard page.
- 9.In the Challenges section, click Add new. ↳ Instruqt shows the New challenge pop-up.
- 10.In the Name field, enter the challenge name—for example,
NGINX
. - 11.In the Description field, enter the challenge description.
- 12.Pick the Assignment challenge type.
- 13.Click Save. ↳ Instruqt closes the New challenge pop-up.
- 14.Click the newly created challenge.
- 15.Click Assignment, and enter your assignment text in Markdown.
- 16.Click Save changes.
- 17.Click Tabs, followed by Add new tab. ↳ Instruqt shows the What's in this tab pop-up.
- 18.Select the Your applications tab type.
- 19.In the Tab name field, enter the name of the tab—for example,
NGINX
. - 20.In the Select your host list, select the
kubernetes-vm
sandbox. - 21.In the Port field, enter
30001
. ↳ This connects the tab to port30001
. - 22.Click Save, followed by Back to track. ↳ Instruqt shows the Track dashboard page.
- 1.Type the following command to create a track:instruqt track create
- 2.Enter your
TRACK_TITLE
:==> Track title: TRACK_TITLE - 3.Enter option 1 to select
From scratch
:==> Start with an empty track or use a template:[1] From scratchFor full flexibility, start with an empty track[2] From a templateTo get started quickly, start from one of our templatesPlease select your method: 1↳ Instruqt CLI creates the track and shows this output:==> Creating track TEAM/TRACK_TITLE==> Creating track filesCreated track directory and configuration files:TRACK_TITLE├── config.yml└── track.ymlOK⇨TEAM
andTRACK_TITLE
will contain your team and track title. - 4.Move into the newly created
TRACK_DIRECTORY
:cd TRACK_DIRECTORY - 5.Enter the following command to add a challenge to your new track:instruqt challenge create --title "CHALLENGE_TITLE"⇨ Replace
CHALLENGE_TITLE
with your title. - 6.Open the
config.yml
file in your code editor and replace its content with the following YAML to add a Kubernetes virtual machine to your track:version: "3"virtualmachines:- name: kubernetes-vmimage: instruqt/k3s-v1-21-1machine_type: n1-standard-1 - 7.Move back to Instruqt CLI and create a new directory for the track lifecycle scripts:md track_scripts
- 8.Move back to your code editor to create a track setup script that waits for Instruqt and Kubernetes to init. To do so, open a new file, and paste the following script into the file:#!/bin/bash# Wait for the Instruqt host bootstrap to finishuntil [ -f /opt/instruqt/bootstrap/host-bootstrap-completed ]dosleep 1done# Wait for the Kubernetes API server to become availablewhile ! curl --silent --fail --output /dev/null http://localhost:8001/apidosleep 1done# Enable bash completion for kubectlecho "source /usr/share/bash-completion/bash_completion" >> /root/.bashrcecho "complete -F __start_kubectl k" >> /root/.bashrc
- 9.Save the track setup file as
setup-kubernetes-vm
in thetrack_scripts
directory. ↳ Thekubernetes-vm
part in the filename refers to the earlier created Kubernetes virtual machine.
🌐 Web UI
💻 Instruqt CLI
- 1.In the Sandbox section, click Scripts, followed by setup. ↳ Instruqt shows an editor window for the setup script.
- 2.Paste the following script, which waits for Instruqt and Kubernetes to init, into the setup script:#!/bin/bash# Wait for the Instruqt host bootstrap to finishuntil [ -f /opt/instruqt/bootstrap/host-bootstrap-completed ]dosleep 1done# Wait for the Kubernetes API server to become availablewhile ! curl --silent --fail --output /dev/null http://localhost:8001/apidosleep 1done# Enable bash completion for kubectlecho "source /usr/share/bash-completion/bash_completion" >> /root/.bashrcecho "complete -F __start_kubectl k" >> /root/.bashrc
- 3.Click Save, followed by Back.
- 4.Click the NGINX challenge, followed by Scripts and setup. ↳ Instruqt shows an editor window for the challenge setup script.
- 5.Paste the following script into the setup script:#!/bin/bashcat <<EOF > service.ymlapiVersion: v1kind: Servicemetadata:labels:app: nginxmanagedFields:name: nginxnamespace: defaultspec:ports:- nodePort: 30001port: 80protocol: TCPselector:app: nginxtype: NodePortEOFkubectl create deployment nginx --image nginx