From 82a7ad1558a92d50a81e05cd2e5814c7effbc111 Mon Sep 17 00:00:00 2001 From: Egor Guz Date: Sun, 11 Oct 2015 19:46:11 -0700 Subject: [PATCH] Update Kubernetes examples Update Kubernetes examples base on official walkthrough http://kubernetes.io/v1.0/docs/user-guide/walkthrough/README.html and add cheat sheet to test/verify/troubleshoot cluster setup. Closes-Bug: #1505536 Change-Id: I9d454c6f58ea2d61e7d457382d8a018354f2b1af --- .../fragments/kube-examples.yaml | 110 +++++++++++++++--- 1 file changed, 96 insertions(+), 14 deletions(-) diff --git a/magnum/templates/heat-kubernetes/fragments/kube-examples.yaml b/magnum/templates/heat-kubernetes/fragments/kube-examples.yaml index d148ad8dfb..809a5911f5 100644 --- a/magnum/templates/heat-kubernetes/fragments/kube-examples.yaml +++ b/magnum/templates/heat-kubernetes/fragments/kube-examples.yaml @@ -1,35 +1,117 @@ #cloud-config merge_how: dict(recurse_array)+list(append) write_files: - - path: /etc/kubernetes/examples/web-pod.yaml + - path: /etc/kubernetes/examples/replication-controller.yaml + owner: "root:root" + permissions: "0644" + content: | + apiVersion: v1 + kind: ReplicationController + metadata: + name: nginx-controller + spec: + replicas: 2 + # selector identifies the set of pods that this + # replication controller is responsible for managing + selector: + name: nginx + # template defines the 'cookie cutter' used for creating + # new pods when necessary + template: + metadata: + labels: + # Important: these labels need to match the selector above + # The api server enforces this constraint. + name: nginx + spec: + containers: + - name: nginx + image: nginx + ports: + - containerPort: 80 + + - path: /etc/kubernetes/examples/pod-nginx-with-label.yaml owner: "root:root" permissions: "0644" content: | apiVersion: v1 kind: Pod metadata: + name: nginx labels: - name: web - name: web + app: nginx spec: containers: - - name: web - image: larsks/thttpd - ports: - - name: web - containerPort: 80 - - path: /etc/kubernetes/examples/web-service.yaml + - name: nginx + image: nginx + ports: + - containerPort: 80 + + - path: /etc/kubernetes/examples/service.yaml owner: "root:root" permissions: "0644" content: | apiVersion: v1 kind: Service metadata: - name: web + name: nginx-service spec: ports: - - name: web - port: 8000 - targetPort: 80 + - port: 8000 # the port that this service should serve on + # the container on each pod to connect to, can be a name + # (e.g. 'www') or a number (e.g. 80) + targetPort: 80 + protocol: TCP + # just like the selector in the replication controller, + # but this time it identifies the set of pods to load balance + # traffic to. selector: - name: web + app: nginx + + - path: /etc/kubernetes/examples/README.md + owner: "root:root" + permissions: "0644" + content: | + Kubernetes 101 (http://kubernetes.io/v1.0/docs/user-guide/walkthrough/README.html) + ================================================================================== + + List all nodes: + + kubectl get nodes + + Replication Controllers: + + kubectl create -f /etc/kubernetes/examples/replication-controller.yaml + kubectl get rc + kubectl delete rc nginx-controller + + Pods: + + kubectl create -f /etc/kubernetes/examples/pod-nginx-with-label.yaml + kubectl get pods + curl http://$(kubectl get pod nginx -o=template -t={{.status.podIP}}) + + Services: + + kubectl create -f /etc/kubernetes/examples/service.yaml + kubectl get services + + export SERVICE_IP=$(kubectl get service nginx-service -o=template -t={{.spec.clusterIP}}) + export SERVICE_PORT=$(kubectl get service nginx-service -o=template '-t={{(index .spec.ports 0).port}}') + curl http://${SERVICE_IP}:${SERVICE_PORT} + + kubectl delete service nginx-service + + Troubleshooting: + + kubectl get events + + kubectl describe rc nginx-controller + + kubectl describe pod nginx + + kubectl describe service nginx-service + + kubectl exec nginx env + + kubectl exec -ti nginx -- bash