In Kubernetes, understanding core concepts such as Pods, ReplicaSets, and Deployments is essential for effectively managing and orchestrating containerized applications. These concepts form the foundation of Kubernetes, enabling scalable, resilient, and manageable applications. This lesson will delve into these core concepts and more, providing a comprehensive understanding of their roles, functions, and interactions.
kubectl
is installed and configured to interact with your Minikube cluster. You can install kubectl
from Kubernetes' official documentation.Verify your installations with the following commands:
minikube version
kubectl version --client
kubectl
.docker --version
minikube stop --profile=spn-cluster-2 --alsologtostderr=false --v=0
spn-cluster-2
. The --alsologtostderr=false --v=0
options reduce the verbosity of the output. The expected outcome is a confirmation message indicating that the Minikube cluster has been stopped. If the cluster does not exist, you may receive an error message indicating that the profile is not found.minikube delete --profile=spn-cluster-2 --alsologtostderr=false --v=0
spn-cluster-2
. The --alsologtostderr=false --v=0
options reduce the verbosity of the output. The expected outcome is a message confirming that all traces of the specified Minikube cluster have been removed. If the cluster does not exist, a message will indicate that the profile does not exist but has been removed anyway.minikube start --profile=spn-cluster-2 --alsologtostderr=false --v=0
spn-cluster-2
. The --alsologtostderr=false --v=0
options reduce the verbosity of the output. The expected outcome is that Minikube will initialize and set up a new Kubernetes cluster using the specified profile. You will see output messages indicating the progress of the cluster's creation and readiness.kubectl create deployment nginx --image=nginx
nginx
image. The expected outcome is that a deployment named nginx
will be created, and you will see a confirmation message indicating its creation. This deployment manages a set of identical pods running the NGINX container.apiVersion: v1 kind: Service metadata: name: nginx namespace: default spec: selector: app: nginx ports: - protocol: TCP port: 80 targetPort: 80 nodePort: 31000 type: NodePort
nginx-service.yaml
. This YAML file defines a Kubernetes Service that exposes the NGINX deployment. The service listens on port 80 and forwards traffic to port 80 on the NGINX pods. The nodePort
field specifies the external port (31000) on each node that forwards to the service.kubectl apply -f nginx-service.yaml
nginx-service.yaml
file, creating the Service to expose the NGINX deployment. The expected outcome is a confirmation message indicating that the service has been created.kubectl get pods
kubectl describe pod <nginx-pod-name> kubectl describe pod nginx-676b6c5bbc-wb5wg
<nginx-pod-name>
with the actual pod name from the previous command. This helps diagnose any issues if the pod is not running.kubectl logs <nginx-pod-name>
<nginx-pod-name>
with the actual pod name.kubectl delete deployment nginx kubectl create deployment nginx --image=nginx
kubectl get svc nginx -n default
nodePort
.minikube service nginx --profile=spn-cluster-2 --url
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.7.0/aio/deploy/recommended.yaml
apiVersion: v1 kind: ServiceAccount metadata: name: admin-user namespace: kubernetes-dashboard --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: name: admin-user roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: cluster-admin subjects: - kind: ServiceAccount name: admin-user namespace: kubernetes-dashboard
admin-user.yaml
. This YAML file defines an Admin User ServiceAccount and a ClusterRoleBinding to grant cluster-admin privileges to the admin-user in the kubernetes-dashboard
namespace. This user will be used to log in to the Kubernetes Dashboard.kubectl apply -f admin-user.yaml
admin-user.yaml
file, creating the Admin User and granting the necessary permissions. The expected outcome is a confirmation message indicating that the ServiceAccount and ClusterRoleBinding have been created.kubectl -n kubernetes-dashboard create token admin-user
admin-user
. The expected outcome is a token string that you will use to log in to the Kubernetes Dashboard. Save this token as you will need it for the next steps.kubectl proxy --port=32000
--port=32000
option, the proxy will listen on port 32000. The expected outcome is a running proxy server ready to handle requests to the dashboard.Access the Kubernetes Dashboard
http://localhost:32000/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/
. The expected outcome is that the URL opens the Kubernetes Dashboard login page in your browser.Log in to the Dashboard
kubectl delete -f nginx-service.yaml
nginx-service.yaml
file. The expected outcome is a confirmation message indicating that the service has been deleted. This ensures that there are no lingering services consuming resources.kubectl delete deployment nginx
kubectl delete -f admin-user.yaml
admin-user.yaml
file. The expected outcome is a confirmation message indicating that the ServiceAccount and ClusterRoleBinding have been deleted. This removes the admin user and its permissions.kubectl delete -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.7.0/aio/deploy/recommended.yaml
minikube stop --profile=spn-cluster-2
spn-cluster-2
. The expected outcome is a confirmation message indicating that the Minikube cluster has been stopped. This ensures that the cluster is not running and consuming resources.minikube delete --profile=spn-cluster-2
spn-cluster-2
. The expected outcome is a confirmation message indicating that all traces of the specified Minikube cluster have been removed. This ensures that the environment is fully cleaned up.In this lesson, we successfully set up Minikube, deployed an NGINX application, and exposed it to the internet. We also set up the Kubernetes Dashboard for easy cluster management. This hands-on experience helps solidify your understanding of Kubernetes basics and prepares you for more advanced topics.
Explore the contents of the other lectures - by click a lecture.
In the dynamic world of containers, Kubernetes is the captain that navigates through the seas of scale, steering us towards efficiency and innovation.😊✨ - The Alchemist "