In this section, we will test our connections to our Kubernetes clusters one at a time and then lastly connect to the Kubernetes dashboard and view our Kubernetes clusters’ information. To test our connections we must ensure that the right ports are open, set our cluster’s context with the DC/OS Kubernetes service, get Kubernetes nodes’ information, and test with a simple NGINX deployment.
:6443
and :6444
are open.
Check that Port Before attempting to connect kubectl
to the MKE clusters, you will want to check to ensure that ports :6443
and :6444
are accessible by your local machine to the DC/OS Cluster. Closed ports :6443
and :6444
will cause kubectl
commands to just hang. Typically, these settings are handled by your systems administrator. Or, if using a cloud provider such as AWS, these would be rules configured in your EC2–>Security Groups tab.
kubernetes-cluster1
at port :6443
Test the connection to -
First, configure your
context
tokubernetes-cluster1
at port:6443
.If using Edge-LB Auto Pools, in your CLI, enter the following snippet:
dcos kubernetes cluster kubeconfig \ --insecure-skip-tls-verify \ --context-name=kubernetes-cluster1 \ --cluster-name=kubernetes-cluster1 \ --apiserver-url=https://${EDGELB_PUBLIC_AGENT_IP}:6443/kubernetes-cluster1
If not using Edge-LB Auto Pools, enter the following snippet:
dcos kubernetes cluster kubeconfig \ --insecure-skip-tls-verify \ --context-name=kubernetes-cluster1 \ --cluster-name=kubernetes-cluster1 \ --apiserver-url=https://${EDGELB_PUBLIC_AGENT_IP}:6443
which will configure DC/OS Kubernetes to connect to
kubernetes-cluster1
from the Kubernetes CLI,kubectl
. TheEDGELB_PUBLIC_AGENT_IP
should still be cached in your terminal environment from the previous section, if not, make sure to insert the proper value. -
Next, get your Kubernetes nodes’ info for
kubernetes-cluster1
.In your CLI, enter:
kubectl get nodes
to receive details regarding your the nodes of
kubernetes-cluster1
.If you do not get an almost immediate response, check your firewall settings and ensure that you can communicate with your public agent node.
-
Then, create a NGINX deployment on
kubernetes-cluster1
.Enter the following in your CLI:
kubectl apply -f https://k8s.io/examples/application/deployment.yaml
to launch the deployment.
-
View the NGINX deployment just launched.
In your CLI, run:
kubectl get deployments
The resulting output should look similar to the following:
$ kubectl get deployments NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE nginx-deployment 2 2 2 2 23s
-
Lastly, delete the NGINX deployment to finish up this connection test for
kubernetes-cluster1
.Run the following command in your CLI:
kubectl delete deployment nginx-deployment
and the deployment will be deleted.
kubernetes-cluster2
Test the connection to Now you will do the same to test kubernetes
-
Connect the second Kubernetes cluster to the
kubeconfig
to sendkubectl
commands to it.If using Edge-LB Auto Pools, in your CLI, paste in the following, again, your
EDGELB_PUBLIC_AGENT_IP
should still be cached in your terminal environment from the previous section:dcos kubernetes cluster kubeconfig \ --insecure-skip-tls-verify \ --context-name=kubernetes-cluster2 \ --cluster-name=kubernetes-cluster2 \ --apiserver-url=https://${EDGELB_PUBLIC_AGENT_IP}:6443/kubernetes-cluster2
If not using Edge-LB Auto Pools, enter the following snippet:
dcos kubernetes cluster kubeconfig \ --insecure-skip-tls-verify \ --context-name=kubernetes-cluster2 \ --cluster-name=kubernetes-cluster2 \ --apiserver-url=https://${EDGELB_PUBLIC_AGENT_IP}:6444
Your
kubectl
commands should now connect tokubernetes-cluster2
.Once the 2 contexts are configured, they will be saved in
~/.kube/config
. To switch, you can either set the context generally:kubectl config use-context kubernetes-cluster2
Or use the flag
--context kubernetes-cluster1
in commands like so:kubectl get nodes --context kubernetes-cluster1
-
As before for
kubernetes-cluster1
, get the nodes’ information forkubernetes-cluster2
.In your CLI, enter:
kubectl get nodes
and note that the output should show that you are now using
kubernetes-cluster2
, similar to the following:$ kubectl get nodes NAME STATUS ROLES AGE VERSION kube-control-plane-0-instance.kubernetes-cluster2.mesos Ready master 145m v1.19.2 kube-node-0-kubelet.kubernetes-cluster2.mesos Ready <none> 142m v1.19.2
-
Next, create a NGINX deployment on
kubernetes-cluster1
:Enter the following in your CLI:
kubectl apply -f https://k8s.io/examples/application/deployment.yaml
and the deployment will begin.
-
View that NGINX deployment in action:
kubectl get deployments
The resulting output should look similar to below:
$ kubectl get deployments NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE nginx-deployment 2 2 2 2 23s Delete NGINX deployment:
-
Finally, delete your test deployment.
Simply enter:
kubectl delete deployment nginx-deployment
and the deployment will be shut down.
Access the Kubernetes Dashboard from your browser
In one simple but satisfying validation of our connection into our Kubernetes cluster manager from outside the cluster, we will access the Kubernetes Dashboard and view our cluster currently in context.
-
Access the Kubernetes dashboard.
In your CLI, enter:
kubectl proxy
which should start the proxy server.
-
Then, navigate to: http://127.0.0.1:8001/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/ and you should see your Kubernetes dashboard and information.
When the Kubernetes login screen is shown, you should choose the kubeconfig option, click the Choose kubeconfig file text box and pick the location of your kubeconfig
file (typically, $HOME/.kube/config
).
Note: When accessed, and depending on whether you are running DC/OS or DC/OS EE you may be presented a warning indicating that the TLS certificate being used by the Kubernetes Dashboard is not trusted. It is generally safe to permanently trust this TLS certificate by adding an exception in your browser, or to skip past it. To learn more about TLS certificates, visit the Kubernetes Dashboard section.
Mission Complete!
Well done! You have successfully completed the Getting Started Guide for Kubernetes. You have set up your DC/OS Enterprise cluster to be able to run Kubernetes as a service on DC/OS.
For more information regarding operating Kubernetes as a service on DC/OS, check out the Operations section.