From 89e2885b947c446de68e226b3d7963d9aea75134 Mon Sep 17 00:00:00 2001 From: Gaurav Agarwal Date: Fri, 9 Aug 2019 15:21:30 +0530 Subject: [PATCH] Adding service.yaml. --- code-samples/11-kubernetes/README.md | 8 +++----- .../{create-cluster.sh => build-image.sh} | 1 - code-samples/11-kubernetes/config/service.yaml | 18 ++++++++++++++++++ code-samples/11-kubernetes/docker-config.json | 2 +- .../11-kubernetes/{commands.sh => exercise.sh} | 12 +++++++++--- code-samples/11-kubernetes/setup-proxy.md | 2 +- code-samples/11-kubernetes/source.sh | 11 ++++++++++- 7 files changed, 42 insertions(+), 12 deletions(-) rename code-samples/11-kubernetes/{create-cluster.sh => build-image.sh} (89%) create mode 100644 code-samples/11-kubernetes/config/service.yaml rename code-samples/11-kubernetes/{commands.sh => exercise.sh} (70%) diff --git a/code-samples/11-kubernetes/README.md b/code-samples/11-kubernetes/README.md index 16d3a16..c58fef7 100644 --- a/code-samples/11-kubernetes/README.md +++ b/code-samples/11-kubernetes/README.md @@ -19,10 +19,7 @@ Or clone the repo and run `./install.sh` ```bash minikube start --vm-driver=kvm2 - # ./source.sh - export NO_PROXY=$no_proxy,$(minikube ip) - - kubectl version + . source.sh ``` ### Multi node cluster using Kind @@ -32,7 +29,8 @@ Or clone the repo and run `./install.sh` Follow steps in [setup-proxy.md](https://github.com/AgarwalConsulting/java-training/blob/master/code-samples/11-kubernetes/setup-proxy.md) ```bash - kind build node-image + ./build-image.sh + kind create cluster --config kind-config.yml ``` diff --git a/code-samples/11-kubernetes/create-cluster.sh b/code-samples/11-kubernetes/build-image.sh similarity index 89% rename from code-samples/11-kubernetes/create-cluster.sh rename to code-samples/11-kubernetes/build-image.sh index d794138..07317ff 100755 --- a/code-samples/11-kubernetes/create-cluster.sh +++ b/code-samples/11-kubernetes/build-image.sh @@ -14,4 +14,3 @@ git clone https://github.com/kubernetes/kubernetes.git ~/.go/src/k8s.io/kubernet echo "Creating kind cluster..." # kind delete cluster kind build node-image -kind create cluster --config kind-config.yml diff --git a/code-samples/11-kubernetes/config/service.yaml b/code-samples/11-kubernetes/config/service.yaml new file mode 100644 index 0000000..6eff9aa --- /dev/null +++ b/code-samples/11-kubernetes/config/service.yaml @@ -0,0 +1,18 @@ +--- +apiVersion: extensions/v1beta1 +kind: Service +metadata: + name: gs-rest-service + labels: + name: gs-rest-service +spec: + # if your cluster supports it, uncomment the following to automatically create + # an external load-balanced IP for the frontend service. + # type: LoadBalancer + type: NodePort + ports: + # the port that this service should serve on + - port: 8080 + nodePort: 30080 + selector: + name: gs-rest diff --git a/code-samples/11-kubernetes/docker-config.json b/code-samples/11-kubernetes/docker-config.json index 1b939cf..210d5ee 100644 --- a/code-samples/11-kubernetes/docker-config.json +++ b/code-samples/11-kubernetes/docker-config.json @@ -5,7 +5,7 @@ { "httpProxy": "http://10.19.16.165:8080", "httpsProxy": "http://10.19.16.165:8080", - "noProxy": "localhost,127.0.0.0/8,::1" + "noProxy": "localhost,127.0.0.0/8,::1,172.17.0.0/16" } } } diff --git a/code-samples/11-kubernetes/commands.sh b/code-samples/11-kubernetes/exercise.sh similarity index 70% rename from code-samples/11-kubernetes/commands.sh rename to code-samples/11-kubernetes/exercise.sh index c5e67be..83f37c4 100644 --- a/code-samples/11-kubernetes/commands.sh +++ b/code-samples/11-kubernetes/exercise.sh @@ -1,8 +1,6 @@ #!/usr/bin/env bash -# Start a Kubernetes locally -minikube start - +# Start a Kubernetes locally using either minikube or Kind kubectl cluster-info # Create a deployment @@ -13,6 +11,7 @@ kubectl proxy & # Check if the server in the pod is accessible curl http://localhost:8001/version + 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/namespaces/default/pods/$POD_NAME/proxy/ @@ -20,8 +19,15 @@ curl http://localhost:8001/api/v1/namespaces/default/pods/$POD_NAME/proxy/ # Apply a nginx deployment kubectl apply -f https://k8s.io/examples/controllers/nginx-deployment.yaml +# Starting gs-rest-service as a deployment +kubectl create deployment gs-rest --image=gauravagarwalr/spring-greeting:latest +kubectl apply -f config/deployment.yaml +kubectl apply -f config/service.yaml + # Status kubectl get nodes kubectl get namespaces kubectl get pods -o wide kubectl get deployments +kubectl get rc +kubectl get services diff --git a/code-samples/11-kubernetes/setup-proxy.md b/code-samples/11-kubernetes/setup-proxy.md index 30447bb..64078a3 100644 --- a/code-samples/11-kubernetes/setup-proxy.md +++ b/code-samples/11-kubernetes/setup-proxy.md @@ -18,7 +18,7 @@ { "httpProxy": "http://10.19.16.165:8080", "httpsProxy": "http://10.19.16.165:8080", - "noProxy": "localhost,127.0.0.0/8,::1" + "noProxy": "localhost,127.0.0.0/8,::1,172.17.0.0/16" } } } diff --git a/code-samples/11-kubernetes/source.sh b/code-samples/11-kubernetes/source.sh index 8d86054..1d09941 100755 --- a/code-samples/11-kubernetes/source.sh +++ b/code-samples/11-kubernetes/source.sh @@ -1,3 +1,12 @@ #!/usr/bin/env bash -export NO_PROXY=$no_proxy,$(minikube ip) +export NO_PROXY=$no_proxy,172.17.0.0/16 +export HTTP_PROXY="http://10.19.16.165:8080" +export HTTPS_PROXY="http://10.19.16.165:8080" + +export no_proxy=$no_proxy,172.17.0.0/16 +export http_proxy="http://10.19.16.165:8080" +export https_proxy="http://10.19.16.165:8080" + +export NO_PROXY=$NO_PROXY,$(minikube ip) +export no_proxy=$no_proxy,$(minikube ip)