Tutorial: Hello Minikube
-
Compare the application logs before and after you exposed it as a Service. Try to open the app several times while the proxy into the Service is running. What do you see in the logs? Does the number of logs increase each time you open the app?
Before exposing the application as a service, we might have primarily seen logs related to the application itself running within the Docker container. These logs could include startup messages, any errors or warnings encountered during execution, and any other relevant information generated by the application.
After exposing the application as a service and accessing it through a proxy running in Minikube via
kubectl, the logs would likely show additional activity related to network communication and requests being handled by the service. Each time the app is opened through the proxy, there would be an increase in the number of logs reflecting incoming requests, the processing of those requests by the service, and any responses sent back to the client.The number of logs would indeed increase each time we open the app, as each interaction triggers logging activity in response to incoming requests and their processing by the service. This increase in logs provides a clear indication of the service's activity and its responsiveness to client requests.
-
Notice that there are two versions of
kubectl getinvocation during this tutorial section.The first does not have any option, while the latter has-noption with value set tokube-system. What is the purpose of the-noption and why did the output not list the pods/services that you explicitly created?The
-noption inkubectl getis used to specify the namespace in which to list resources. A Kubernetes namespace provides a way to logically partition cluster resources and allows multiple users or teams to share the same cluster without interfering with each other. When there is no namespace specified,kubectltypically defaults to thedefaultnamespace.In the tutorial, the first
kubectl getinvocation did not include the-noption, so it listed resources from the default namespace, which may not have included the resources we explicitly created if we created them in a different namespace.The second
kubectl getinvocation included the-noption with the value set tokube-system, so it listed resources specifically from thekube-systemnamespace. This namespace typically contains Kubernetes system components and infrastructure-related resources.If we explicitly created pods and services in a different namespace, we would need to specify that namespace using the
-noption inkubectl getto see those resources listed in the output. For example:kubectl get pods,services -n <namespace>Replace
<namespace>with the name of the namespace where we created the resources. This will list pods and services specifically from that namespace. If we created resources in thedefaultnamespace and want to see them, we can simply omit the-noption, as resources from thedefaultnamespace are listed by default.
Tutorial: Rolling Update Deployment
-
What is the difference between Rolling Update and Recreate deployment strategy?
Rolling Update and Recreate are two different deployment strategies in Kubernetes, each with its own characteristics and use cases:
-
Rolling Update:
- Strategy: Rolling Update performs a rolling update of the pods in a deployment. It gradually replaces old pods with new ones, ensuring that there is no downtime during the update process.
- Process: Rolling Update deploys new pods incrementally while gradually scaling down the old pods. It monitors the health of the new pods before scaling down the old ones, ensuring that the application remains available and responsive throughout the update.
- Benefits:
- Zero downtime: Rolling Update ensures that the application remains available to users throughout the update process.
- Controlled deployment: Updates are applied gradually, allowing for monitoring and validation of the new pods before fully transitioning to the new version.
- Drawbacks:
- Longer deployment time: Rolling Update may take longer to complete compared to Recreate, especially for large deployments, as it deploys updates gradually.
-
Recreate:
- Strategy: Recreate simply terminates all existing pods and creates new ones with the updated configuration. It effectively stops the old version of the application and starts the new version all at once.
- Process: Recreate terminates all existing pods in the deployment before creating new ones with the updated configuration. This results in a brief period of downtime during the update process.
- Benefits:
- Simplicity: Recreate is a straightforward deployment strategy that stops the old version and starts the new version, making it easy to understand and implement.
- Predictable behavior: Recreate ensures that the application is fully updated once the deployment process completes.
- Drawbacks:
- Downtime: Recreate results in a brief period of downtime during the update process, as all existing pods are terminated before new ones are created.
- Potential impact on users: Depending on the application's requirements, downtime during updates may not be acceptable for some users or applications.
In summary, Rolling Update is preferred for deployments that require zero downtime and gradual updates, while Recreate may be suitable for simpler deployments where a brief period of downtime is acceptable or when updates need to be applied quickly and predictably.
-
-
Try deploying the Spring Petclinic REST using Recreate deployment strategy and document your attempt.
Here are the detailed steps to deploy the Spring Petclinic REST application on Minikube using the Recreate deployment strategy:
-
Start Minikube: Start Minikube with the following command:
minikube start
This command will start a local Kubernetes cluster using Minikube.
-
Enable Metrics Server: Enable the Metrics Server addon to allow monitoring of resource usage:
minikube addons enable metrics-serverThis command installs the Metrics Server addon, which collects resource metrics from pods and nodes in the cluster.
-
Apply
recreate-deployment-before.yaml: Applyrecreate-deployment-before.yamlto create a Deployment with the following commandkubectl apply -f recreate-deployment-before.yaml
-
Apply
service.yaml: Applyservice.yamlto create a Service that exposes the Deployment created previously with the following commandkubectl apply -f service.yaml
-
Update the Deployment: Update the Deployment to use the latest version of
spring-petclinic-restusing the Recreate Deployment method by deploying a similar file asrecreate-deployment-before.yamlbut the image tag is changed to the latest.kubectl apply -f recreate-deployment-after.yaml
-
-
Prepare different manifest files for executing Recreate deployment strategy.
Here are the manifest files for deploying the Spring Petclinic REST application using the Recreate deployment strategy:
-
recreate-deployment-before.yaml:
apiVersion: apps/v1 kind: Deployment metadata: labels: app: spring-petclinic-rest name: spring-petclinic-rest spec: replicas: 4 selector: matchLabels: app: spring-petclinic-rest strategy: type: Recreate template: metadata: labels: app: spring-petclinic-rest spec: containers: - image: docker.io/springcommunity/spring-petclinic-rest:3.0.2 name: spring-petclinic-rest
-
service.yaml:
apiVersion: v1 kind: Service metadata: creationTimestamp: "2024-05-11T14:52:39Z" labels: app: spring-petclinic-rest name: spring-petclinic-rest namespace: default resourceVersion: "3920" uid: 45e9aa85-76a3-46a8-869f-9ae953930f82 spec: allocateLoadBalancerNodePorts: true clusterIP: 10.102.156.230 clusterIPs: - 10.102.156.230 externalTrafficPolicy: Cluster internalTrafficPolicy: Cluster ipFamilies: - IPv4 ipFamilyPolicy: SingleStack ports: - nodePort: 32697 port: 9966 protocol: TCP targetPort: 9966 selector: app: spring-petclinic-rest sessionAffinity: None type: LoadBalancer status: loadBalancer: {}
-
recreate-deployment-after.yaml:
apiVersion: apps/v1 kind: Deployment metadata: labels: app: spring-petclinic-rest name: spring-petclinic-rest spec: replicas: 4 selector: matchLabels: app: spring-petclinic-rest strategy: type: Recreate template: metadata: labels: app: spring-petclinic-rest spec: containers: - image: docker.io/springcommunity/spring-petclinic-rest:latest name: spring-petclinic-rest
These manifest files define a Deployment resource with the name
spring-petclinic-restand a Service resource with the same name. The Deployment resource specifies the Recreate deployment strategy, which recreates all pods when updates are applied. The Service resource exposes the application on port 9966 using a LoadBalancer type service.These files can be applied using
kubectl apply -f <filename.yaml>command. Adjust the image version or other parameters as needed for specific setup. -
-
What do you think are the benefits of using Kubernetes manifest files? Recall your experience in deploying the app manually and compare it to your experience when deploying the same app by applying the manifest files (i.e., invoking
kubectl apply -fcommand) to the cluster.Using Kubernetes manifest files provides several benefits:
-
Infrastructure as Code (IaC): Manifest files allow us to define the application's infrastructure in a declarative manner using code. This makes it easy to version control, track changes, and manage infrastructure configurations alongside application code.
-
Reproducibility: Manifest files ensure that the deployments are consistent across environments. By defining the desired state of the application in code, we can easily reproduce deployments in different environments, reducing the risk of configuration drift.
-
Automation: Kubernetes manifest files can be automated using continuous integration and continuous deployment (CI/CD) pipelines. This enables automation of the deployment process, reducing manual intervention and potential errors.
-
Visibility and Transparency: Manifest files provide a clear and transparent view of the application's configuration. We can easily see the desired state of the application and track changes over time.
-
Idempotent Operations: Applying manifest files using
kubectl apply -fcommand ensures idempotent operations. Kubernetes reconciles the desired state defined in the manifest files with the current state of the cluster, ensuring that only necessary changes are applied.
Comparing the experience of deploying an application manually versus using manifest files, deploying with manifest files offers:
-
Consistency: With manifest files, deployments are consistent and reproducible across environments. Manual deployments may lead to discrepancies between environments due to human error or differences in execution.
-
Efficiency: Using manifest files streamlines the deployment process, as we can define all configurations in code and apply them to the cluster with a single command. This reduces the time and effort required for deployment compared to manual steps.
-
Version Control: Manifest files can be version controlled using Git or other version control systems. This allows us to track changes, revert to previous configurations if needed, and collaborate with team members more effectively.
Overall, using Kubernetes manifest files enhances the deployment process by providing a standardized, automated, and version-controlled approach to managing application infrastructure.
-


