3 Steps To Auto-Install K8S with Cloud-config
Part-2: Deploy Bonus Examples K8S Cluster “For Beginner”
This article is the continuation of the previous one
In a real Prod Environment, the exposed services must use LoadBalancer or IngressController or both to communicate with the outside.
However for the bonus examples i’ll make it simple by exposing our services via NodePorts
The Goals is always to be familiarized with this techno 😉
Bonus 1 : Install Kubernetes Dashboard
To deploy K8s Dashboard, execute the following command:
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.2.0/aio/deploy/recommended.yaml
Create An Authentication Token (RBAC)
# created a service account
kubectl create serviceaccount dashboard-admin-sa# Bind the dashboard admin service account to the cluster-admin role
kubectl create clusterrolebinding dashboard-admin-sa --clusterrole=cluster-admin --serviceaccount=default:dashboard-admin-sa
Change the type of the Kubernetes-dashboard service to be a NodePort
kubectl edit svc kubernetes-dashboard -n kubernetes-dashboard
# in the file change type to be NodePort
Describe the service of Kubernetes Dashboard to get the NodePort :
kubectl describe service kubernetes-dashboard -n kubernetes-dashboardName: kubernetes-dashboard
...
NodePort: <unset> 32278/TCP
...
Reach your dashboard via the internet :
- Type this address in your navigator : HTTPS://[Public_Address_IP_Of Worker1]:[NodePort]
you can find the public IP address of your worker on your Azure Portal
- To get the token run on your master node :
kubectl get secret $(kubectl get sa/dashboard-admin-sa -o jsonpath=”{.secrets[0].name}”) -o go-template=”{{.data.token | base64decode}}”eyJhbGciOiJSUzI1NiIsImtpZCI6I...
Bonus 2: Run HelloWorld Example
Use these commands to deploy a simple Hello-world Example :
# run the hello-world pod
kubectl run hello-world --image=k8s.gcr.io/echoserver:1.4 --port=8080# expose the pod
kubectl expose pod hello-world --type=NodePort --port=80 --target-port=8080 --name hello-world-service# get or describe the service to get the node port
kubectl get svc hello-world-service
Verify if your pod is running with the Kubernetes dashboard
Reach your hello-world pod via internet : HTTPS://[Public_Address_IP_Of Worker1]:[NodePort]
Conclusion
It was a quick Tuto to deploy k8s Dashboard and the hello-world example.
In the next story, I’ll add another layer of automation by using terraform (IaC) with cloud-init and CI/CD to deploy the complete IAAS of K8S clusters with one button click 😀.