Kubernetes services allow exposing an application as a network service. The service is a static IP address that can be attached to a pod. The service and the pod are separate, so if a pod dies, the service and IP address remain.
Create a service using a YAML file, which is a configuration file. You could create a YAML file from the command line, but for this exercise, you can just use a text editor. Or you can download the service YAML file from this public Git repository
Open the Terminal.
Navigate to the Downloads folder.
cd ./Downloads
Use the following command to create an empty YAML file in your Downloads folder.
touch service.yaml
Use the nano text editor in the Terminal.
nano service.yaml
Copy and paste the configuration below into the text editor.
Press Cmd + X, then type Y and press Return to save the service.yaml file.
Open the command prompt.
Navigate to the Downloads folder.
cd ./Downloads
Use the following command to create an empty YAML file in your Downloads folder.
copy NUL service.yaml
Open the service.yaml file with a text editor. For example, use Notepad++ to edit the YAML file.
Copy and paste the configuration below into the text editor.
Save the service.yaml file.
Open the Terminal.
Navigate to the Downloads folder.
cd ./Downloads
Use the following command to create an empty YAML file in your Downloads folder.
touch service.yaml
Use the nano text editor in the Terminal.
nano service.yaml
Copy and paste the configuration below into the text editor.
Press Ctrl + X, then type Y and press Enter to save the service.yaml file.
In the Terminal or Command Prompt, add the service to your environment using a YAML file.
microk8s kubectl create -f service.yaml
List the services and see that development is now listed. You will need the NodePort port number. Example: 30007.
microk8s kubectl get services
Get the IP address for the microk8s-vm. It will be an IPv4 address. Example: 192.168.64.2.
multipass list
Test that the service is available using the IP address and the NodePort. Example: curl http://192.168.64.2:30007. A message should display and include the pod name; this is from the Deployment YAML file ("Hello from...").