Scenario-101: 1-Node K8S Deployment I
- Objective: Get familiar with K8S concept. Here K8S stands for Kubernetes.
- Requirements:
1. Start one node of k8s in your laptop. Mac or Linux
2. Start a nginx webserver with one instance
3. Scale nginx service into 2 instances.
4. Get familiar with k8s dashboard. Find pods from GUI, check nginx log.
-
Q: How to use your own docker image?
-
Q: What does "kubectl expose deployment .." do behind the scene?
For single node deployment, we have multiple choices. Here we use minikube.
- Install virtualbox and minikube
which minikube
which kubectl
- Start env
# start a VM to host our deployment
minikube start
# Create k8s deployment and export service
kubectl apply -f .
- Check k8s web UI Dashboard
minikube dashboard
- List k8s resources
# list deployments
kubectl get deployment
# list service
kubectl get services
# list pods
kubectl get pods
- Check the first pod
# Get all pods
kubectl get pods -l app="nginx"
# Get the first pod
POD_NAME=$(kubectl get pods -l app="nginx" -o jsonpath="{.items[0].metadata.name}")
echo "POD_NAME: $POD_NAME"
# Login to the first pod
kubectl exec -ti $POD_NAME hostname
# Check log of the first pd
kubectl logs -f $POD_NAME
- Run functional test
# Get endpoint url of nginx service
kubectl get services
# Send requests
service_url="$(minikube service my-nginx-service --url)"
for((i=0; i< 5; i++)); do { curl -I "$service_url";}; done
Destroy env:
- Delete k8s resources
kubectl apply -R -f .
- Remove VM
minikube delete