Create pod and launch NGINX server
Setup a virtual machine (master node) and create 2 worker nodes with same configuration as master node (opens in a new tab)
Create a cluster
Step 1: Launch Dashboard Proxy and login using provided token.
sudo microk8s dashboard-proxy
Output:
student@int363:~$ sudo microk8s dashboard-proxy
Checking if Dashboard is running.
Infer repository core for addon dashboard
Waiting for Dashboard to come up.
Trying to get token from microk8s-dashboard-token
Waiting for secret token (attempt 0)
Dashboard will be available at https://127.0.0.1:10443
Use the following token to login:
eyJhbGciOiJSUzI1NiIsImtpZCI6ImVwcnVfWHAwMWw0V0hvb3g3Z0tlYzZlbE5GX0hhdmJnTHZVWmRoT29MUjgifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlLXN5c3RlbSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJtaWNyb2s4cy1kYXNoYm9hcmQtdG9rZW4iLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC5uYW1lIjoiZGVmYXVsdCIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50LnVpZCI6ImI0MDQ4OWRiLTJmZWQtNDRlMy04ODRmLTdiNzM1NDQ0ZTNjZiIsInN1YiI6InN5c3RlbTpzZXJ2aWNlYWNjb3VudDprdWJlLXN5c3RlbTpkZWZhdWx0In0.GlY0sPY8-BtgMQ8bW55DFRXVOaKt9tq13_SOzFPQeRFi1Yj3lzFHlRWc6sQRVZPJjyXyjQj2JJTOkiZOdkwtkw3E5n6T8ApytoG7Y__FJb5UtsT780zuaUf8fypYBkT2d7IXuuGRUj4m7NA-RGiJcJ_wEzFfQ1sOzZBkiIWzs4N_wOQC6VzVM_Pd3cSwUi1zEJJBngAxw_pvJCkYORFk5ieItnJn-F0OfEqu3rzZ0Cs9Ge8-VtjrEnE2JEAc2hTG3JhptKKM-VD82YUyaotARBqs2SxhhaU75W1eP8RE7t-7EpVI-w4h9DYy5BmK-ZXwGHnZ1xM-2f46y1AKQ3wX-w
Step 3: In the dashboard go to Dashboard > Pods > Click on Add icon (+).
Step 4: Write the follwoing configuration to create a NGINX pod in the space provided.
apiVersion: v1
kind: Pod
metadata:
name: nginx-pod
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:latest
ports:
- containerPort: 80
Click on Upload button
Step 2: Verify the pods
kubectl get pods
Step 2: Verify the services
kubectl get services
Step 2: Expose the port 80 for nginx pod
microk8s kubectl expose pod nginx-pod --type=NodePort --port=80 --name=nginx-service
Repeat the step 2
Step 3: Now verify the namespace (using kubectl get all -A
) and look for service/nginx-service
and note the port (generated and assigned randomly)
default service/nginx-service NodePort 10.152.183.251 <none> 80:32246/TCP 21m
Open the browser and open the port -
Command | Description |
---|---|
Local machine | http://localhost:PORT |
Remote machine | http://PUBLIC_ADDRESS:PORT |