Kubenetics hand-on document

docker

#1

Install kubectl cli

  1. sudo apt update && sudo apt install -y apt-transport-https
  2. curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
  3. echo "deb http://apt.kubernetes.io/ kubernetes-xenial main" |sudo tee /etc/apt/sources.list.d/kubernetes.list
  4. sudo apt update
  5. sudo apt install -y kubectl
  6. kubectl
  7. kubectl version
  8. source <(kubectl completion bash)
  9. kubectl completion bash |sudo tee /etc/bash_completion.d/kubectl

Deploying apps into clusters

  1. docker login
  2. docker image ls
  3. docker image tag hello-world:1 <docker hub id>/hello-world:1
  4. docker image ls
  5. docker image push <docker hub id>/hello-world:1
  6. docker image tag hello-world:2 <docker hub id>/hello-world:2
  7. docker image push <docker hub id>/hello-world:2
  8. kubectl version --short
  9. kubectl run hello-world-deployment --image=<docker hub id>/hello-world:1
  10. kubectl get deployment
  11. kubectl get deployment hello-world-deployment
  12. kubectl get deployment hello-world-deployment -o yaml
  13. kubectl describe deployment hello-world-deployment
  14. kubectl get replicaset
  15. kubectl get replicaset -o yaml
  16. kubectl describe replicaset
  17. kubectl get pod
  18. kubectl get pod -o yaml
  19. kubectl describe pod
  20. kubectl expose deployment/hello-world-deployment --type=NodePort --port=8080 --name=hello-world-service --target-port=8080
  21. kubectl describe service hello-world-service
  22. http://워커아이피:노드포트/ 접속
  23. kubectl edit deployment hello-world-deployment
    1. :q! 입력 후 엔터 쳐서 탈출
  24. kubectl scale --replicas=5 deployment hello-world-deployment
  25. kubectl get pod
  26. kubectl rollout status deployment hello-world-deployment
  27. kubectl describe replicaset
  28. watch -n 1 curl http://워커아이피:노드포트/
    1. ctrl-c 눌러 종료
  29. kubectl set image deployment hello-world-deployment hello-world-deployment=<docker hub id>/hello-world:3
  30. kubectl rollout status deployment hello-world-deployment
  31. kubectl describe pod
  32. kubectl rollout undo deployment hello-world-deployment
  33. kubectl get pod
  34. kubectl set image deployment hello-world-deployment hello-world-deployment=<docker hub id>/hello-world:2
  35. kubectl get pod
  36. kubectl rollout status deployment hello-world-deployment
  37. watch -n 1 curl http://워커아이피:노드포트/
    1. ctrl-c 눌러 종료