Essential Maven, Docker, Kubernetes, and Helm Commands for Modern Development
Mastering the tools of modern software development is crucial for any backend developer. This blog post covers essential commands for Maven, Docker, Kubernetes, and Helm, often encountered in real-world development and deployment scenarios.
Maven Commands
Maven Command
Description
mvn clean install -Dmaven.test.skip=true
Generates a JAR file inside the target folder, skipping tests.
mvn spring-boot:run
Starts a Spring Boot Maven project.
mvn spring-boot:build-image
Generates a Docker image using Buildpacks without needing a Dockerfile.
mvn compile jib:dockerBuild
Creates a Docker image using Google Jib without needing a Dockerfile.
Docker Commands
Docker Command
Description
docker build . -t gavebegin/accounts:s4
Builds a Docker image from a Dockerfile.
docker run -p 8080:8080 gavebegin/accounts:s4
Runs a Docker container from a given image.
docker images
Lists all Docker images.
docker image inspect image-id
Displays detailed information about an image.
docker image rm image-id
Removes an image.
docker image push docker.io/gavebegin/accounts:s4
Pushes an image to a registry.
docker image pull docker.io/gavebegin/accounts:s4
Pulls an image from a registry.
docker ps
Lists running containers.
docker ps -a
Lists all containers, including stopped ones.
docker container start container-id
Starts a stopped container.
docker container pause container-id
Pauses a container.
docker container unpause container-id
Unpauses a container.
docker container stop container-id
Stops a running container.
docker container kill container-id
Kills a running container immediately.
docker container restart container-id
Restarts a container.
docker container inspect container-id
Inspects container details.
docker container logs container-id
Fetches container logs.
docker container logs -f container-id
Follows container logs.
docker container rm container-id
Removes a container.
docker container prune
Removes all stopped containers.
docker compose up
Creates and starts containers using a docker-compose file.
docker compose down
Stops and removes containers created via docker-compose.
docker compose start
Starts containers defined in a docker-compose file.
docker run -p 3306:3306 --name accountsdb -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=accountsdb -d mysql
Creates a MySQL container.
docker run -p 6379:6379 --name gavebeginredis -d redis
Creates a Redis container.
docker run -p 8080:8080 -e KEYCLOAK_ADMIN=admin -e KEYCLOAK_ADMIN_PASSWORD=admin quay.io/keycloak/keycloak:22.0.3 start-dev
Creates a Keycloak container.
Apache Benchmark (ab) Command
Command
Description
ab -n 10 -c 2 -v 3 http://localhost:8072/gavebegin/cards/api/contact-info
Load tests an API by sending 10 requests with concurrency level 2.
Kubernetes Commands
Kubernetes Command
Description
kubectl apply -f filename
Deploys resources defined in a YAML file.
kubectl get all
Lists all resources in the cluster.
kubectl get pods
Lists all pods.
kubectl get pod pod-id
Describes a specific pod.
kubectl describe pod pod-id
Shows detailed information about a pod.
kubectl delete pod pod-id
Deletes a pod.
kubectl get services
Lists all services.
kubectl get service service-id
Describes a specific service.
kubectl describe service service-id
Shows detailed information about a service.
kubectl get nodes
Lists all nodes.
kubectl get node node-id
Describes a specific node.
kubectl get replicasets
Lists all replica sets.
kubectl get replicaset replicaset-id
Describes a specific replica set.
kubectl get deployments
Lists all deployments.
kubectl get deployment deployment-id
Describes a specific deployment.
kubectl get configmaps
Lists all ConfigMaps.
kubectl get configmap configmap-id
Describes a specific ConfigMap.
kubectl get events --sort-by=.metadata.creationTimestamp
The kubectl logs command is used to fetch logs from containers in Kubernetes pods. Below is a detailed list of kubectl logs command variations and options:
Basic Usage
kubectl logs <pod-name>
Fetches logs from the default container of the specified pod.
Specify Namespace
kubectl logs <pod-name> -n <namespace>
Retrieves logs from a pod in a specific namespace.
Specify Container
kubectl logs <pod-name> -c <container-name>
Fetch logs from a specific container in a pod (useful when a pod has multiple containers).
Follow Logs (Real-time Streaming)
kubectl logs -f <pod-name>
Continuously stream logs until stopped.
kubectl logs -f <pod-name> -c <container-name>
Stream logs of a specific container.
Tail Last N Lines
kubectl logs --tail=<number> <pod-name>
Displays only the last N lines of logs.
Show Logs with Timestamps
kubectl logs --timestamps <pod-name>
Adds timestamps to each log entry.
Retrieve Logs from Previous Instance of a Pod
kubectl logs --previous <pod-name>
Fetch logs from a crashed pod's previous instance.
Retrieve Logs for a Pod Running on a Specific Node
kubectl logs <pod-name> --limit-bytes=<number>
Limits the number of bytes fetched.
Combine Logs from All Containers in a Pod
kubectl logs <pod-name> --all-containers=true
Fetch logs from all containers in the pod.
Retrieve Logs for a Specific Time Range (If Supported by Log Aggregator)
Would you like any specific details on debugging or advanced log retrieval?
Helm Commands
Helm Command
Description
helm create [NAME]
Creates a new chart.
helm dependencies build
Recompiles chart dependencies.
helm install [NAME] [CHART]
Installs a chart.
helm upgrade [NAME] [CHART]
Upgrades a release.
helm history [NAME]
Shows revision history.
helm rollback [NAME] [REVISION]
Rolls back a release.
helm uninstall [NAME]
Uninstalls a release.
helm template [NAME] [CHART]
Renders chart templates locally.
helm list
Lists all Helm releases.
Mastering these commands will give you confidence in building, containerizing, deploying, and managing applications in production environments. Bookmark this page as a quick reference for your day-to-day development journey. Happy coding!
Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.
Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.
Top comments (0)