Skip to content

Instantly share code, notes, and snippets.

@carlessanagustin
Created March 15, 2017 15:53
Show Gist options
  • Save carlessanagustin/b048e516e74709ed880df7f69618065f to your computer and use it in GitHub Desktop.
Save carlessanagustin/b048e516e74709ed880df7f69618065f to your computer and use it in GitHub Desktop.
Kubernetes tutorial steps

1. Create cluster

Cluster up and running

minikube version
minikube start
kubectl version

Cluster details

kubectl cluster-info
kubectl get nodes

2. Deploy an App

kubectl get nodes

Deploy our app

kubectl run kubernetes-bootcamp \
    --image=docker.io/jocatalin/kubernetes-bootcamp:v1 \
    --port=8080
kubectl get deployments

View our app

kubectl proxy

export POD_NAME=$(kubectl get pods -o go-template \
    --template '{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}')
echo Name of the Pod: $POD_NAME
curl http://localhost:8001/api/v1/proxy/namespaces/default/pods/$POD_NAME/

3. Explore Your App

Check application configuration

kubectl get pods
kubectl describe pods

Show the app in the terminal

kubectl proxy

export POD_NAME=$(kubectl get pods -o go-template \
    --template '{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}')
echo Name of the Pod: $POD_NAME
curl http://localhost:8001/api/v1/proxy/namespaces/default/pods/$POD_NAME/

View the container logs

kubectl logs $POD_NAME

Executing command on the container

kubectl exec $POD_NAME env
kubectl exec -ti $POD_NAME bash
exit

4. Expose Your App Publicly

Create a new service

kubectl get pods
kubectl get services
kubectl expose deployment/kubernetes-bootcamp --type="NodePort" --port 8080
kubectl get services
kubectl describe services/kubernetes-bootcamp

export NODE_PORT=$(kubectl get services/kubernetes-bootcamp \
    -o go-template='{{(index .spec.ports 0).nodePort}}')
echo NODE_PORT=$NODE_PORT
curl host01:$NODE_PORT

Using labels

kubectl describe deployment
kubectl get pods -l run=kubernetes-bootcamp
kubectl get services -l run=kubernetes-bootcamp

export POD_NAME=$(kubectl get pods -o go-template \
    --template '{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}')
echo Name of the Pod: $POD_NAME

kubectl label pod $POD_NAME app=v1
kubectl describe pods $POD_NAME
kubectl get pods -l app=v1

Deleting a service

kubectl delete service -l run=kubernetes-bootcamp
kubectl get services
curl host01:$NODE_PORT
kubectl exec -ti $POD_NAME curl localhost:8080

5. Scale Your App

Scaling a deployment

kubectl get deployments
kubectl scale deployments/kubernetes-bootcamp --replicas=4
kubectl get deployments
kubectl get pods -o wide
kubectl describe deployments/kubernetes-bootcamp

Load Balancing

kubectl describe services/kubernetes-bootcamp
export NODE_PORT=$(kubectl get services/kubernetes-bootcamp \
    -o go-template='{{(index .spec.ports 0).nodePort}}')
echo NODE_PORT=$NODE_PORT
curl host01:$NODE_PORT

Scale Down

kubectl scale deployments/kubernetes-bootcamp --replicas=2
kubectl get deployments
kubectl get pods -o wide

6. Update Your App

Update the version of the app

kubectl get deployments
kubectl get pods
kubectl describe pods
kubectl set image deployments/kubernetes-bootcamp \
    kubernetes-bootcamp=jocatalin/kubernetes-bootcamp:v2
kubectl get pods

Verify an update

kubectl describe services/kubernetes-bootcamp

export NODE_PORT=$(kubectl get services/kubernetes-bootcamp \
    -o go-template='{{(index .spec.ports 0).nodePort}}')
echo NODE_PORT=$NODE_PORT
curl host01:$NODE_PORT

kubectl rollout status deployments/kubernetes-bootcamp
kubectl describe pods

Rollback an update

kubectl set image deployments/kubernetes-bootcamp \
    kubernetes-bootcamp=jocatalin/kubernetes-bootcamp:v10
kubectl get deployments
kubectl get pods
kubectl describe pods
kubectl rollout undo deployments/kubernetes-bootcamp
kubectl get pods
kubectl describe pods
@tariq1890
Copy link

Thanks for this gist. I want to point out a minor issue though. In the explore your app section, the command to call the POD API directly is incomplete

curl http://localhost:8001/api/v1/proxy/namespaces/default/pods/$POD_NAME/proxy/

You need to the add the /proxy after $POD_NAME.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment