pod-ip-test.sh 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #!/bin/bash
  2. # Copyright 2014 The Kubernetes Authors.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. echoOK() {
  16. TC='\e['
  17. RegB="${TC}0m"
  18. if [ "$1" -eq "0" ]; then
  19. Green="${TC}32m"
  20. echo -e "[${Green}OK${RegB}]"
  21. else
  22. Red="${TC}31m"
  23. echo -e "[${Red}FAIL${RegB}]"
  24. echo "Check log file."
  25. exit 1
  26. fi
  27. }
  28. usage() {
  29. echo "Usage options: [--logfile <path to file>]"
  30. }
  31. logfile=/dev/null
  32. while [[ $# > 0 ]]; do
  33. key="$1"
  34. shift
  35. case $key in
  36. -l|--logfile)
  37. logfile="$1"
  38. if [ "$logfile" == "" ]; then
  39. usage
  40. exit 1
  41. fi
  42. shift
  43. ;;
  44. *)
  45. # unknown option
  46. usage
  47. exit 1
  48. ;;
  49. esac
  50. done
  51. KUBE_ROOT=$(dirname "${BASH_SOURCE}")/../..
  52. cd "${KUBE_ROOT}"
  53. echo All verbose output will be redirected to $logfile, use --logfile option to change.
  54. printf "Start the cluster with 2 nodes .. "
  55. export NUM_NODES=2
  56. export KUBERNETES_PROVIDER=vagrant
  57. (cluster/kube-up.sh >>"$logfile" 2>&1) || true
  58. echoOK $?
  59. printf "Check if node-1 can reach kubernetes master .. "
  60. vagrant ssh node-1 -- ping -c 10 kubernetes-master >>"$logfile" 2>&1
  61. echoOK $?
  62. printf "Check if node-2 can reach kubernetes master .. "
  63. vagrant ssh node-2 -- ping -c 10 kubernetes-master >>"$logfile" 2>&1
  64. echoOK $?
  65. printf "Pull an image that runs a web server on node-1 .. "
  66. vagrant ssh node-1 -- 'sudo docker pull kubernetes/serve_hostname' >>"$logfile" 2>&1
  67. echoOK $?
  68. printf "Pull an image that runs a web server on node-2 .. "
  69. vagrant ssh node-2 -- 'sudo docker pull kubernetes/serve_hostname' >>"$logfile" 2>&1
  70. echoOK $?
  71. printf "Run the server on node-1 .. "
  72. vagrant ssh node-1 -- sudo docker run -d kubernetes/serve_hostname >>"$logfile" 2>&1
  73. echoOK $?
  74. printf "Run the server on node-2 .. "
  75. vagrant ssh node-2 -- sudo docker run -d kubernetes/serve_hostname >>"$logfile" 2>&1
  76. echoOK $?
  77. printf "Run ping from node-1 to docker bridges and to the containers on both nodes .. "
  78. vagrant ssh node-1 -- 'ping -c 20 10.246.0.1 && ping -c 20 10.246.1.1 && ping -c 20 10.246.0.2 && ping -c 20 10.246.1.2' >>"$logfile" 2>&1
  79. echoOK $?
  80. printf "Same pinch from node-2 .. "
  81. vagrant ssh node-2 -- 'ping -c 20 10.246.0.1 && ping -c 20 10.246.1.1 && ping -c 20 10.246.0.2 && ping -c 20 10.246.1.2' >>"$logfile" 2>&1
  82. echoOK $?
  83. printf "tcp check, curl to both the running webservers from node-1 .. "
  84. vagrant ssh node-1 -- 'curl -sS 10.246.0.2:9376 && curl -sS 10.246.1.2:9376' >>"$logfile" 2>&1
  85. echoOK $?
  86. printf "tcp check, curl to both the running webservers from node-2 .. "
  87. vagrant ssh node-2 -- 'curl -sS 10.246.0.2:9376 && curl -sS 10.246.1.2:9376' >>"$logfile" 2>&1
  88. echoOK $?
  89. printf "All good, destroy the cluster .. "
  90. vagrant destroy -f >>"$logfile" 2>&1
  91. echoOK $?