diff --git a/README.md b/README.md new file mode 100644 index 0000000..b9f2ba9 --- /dev/null +++ b/README.md @@ -0,0 +1,65 @@ +## Serverless Kubernetes Examples + +[Serverless Kubernetes](https://www.aliyun.com/product/kubernetes) is part of Container Service for Alibaba Cloud. It enable you to run Kubernetes application without effort for managing servers or clusters. Serverless Kubernetes lets you focus on building your applications instead of managing the infrastructure. + +This directory contains a number of examples of how to run real applications with Serverless Kubernetes of Alibaba Cloud + + +## Quick Start + +Create the Serverless Kubernetes and copy the cluster config file to ```~/.kube/config``` + +![image-20180503115812022](/Users/yili/work/serverless-k8s-examples/cluster.png) + + + +![config](/Users/yili/work/serverless-k8s-examples/config.png) + + + +## Test it Out + + + +Deploy nginx application + +``` +kubectl run nginx --image nginx:1.13 --replicas=3 +``` + +Expose nginx with Elastic Load Balancer(ELB) service + +``` +kubectl expose deployment nginx --port=80 --target-port=80 --name=nginx-svc --type=LoadBalancer +``` + + +Get the application status + +``` +kubectl get deployment nginx +kubectl get pod -l run=nginx +kubectl get service nginx-svc +``` + +Access nginx application + +``` +LB_ENDPOINT=$(kubectl get service nginx-svc -o jsonpath="{.status.loadBalancer.ingress[*].ip}") + +# Open browser with URL in MacOSX +open http://${LB_ENDPOINT} +``` + + +Delete the nginx application + +``` +kubectl delete deploy nginx +``` + +Delete the nginx service + +``` +kubectl delete --name=nginx-svc +``` diff --git a/cluster.png b/cluster.png new file mode 100644 index 0000000..431f696 Binary files /dev/null and b/cluster.png differ diff --git a/config.png b/config.png new file mode 100644 index 0000000..eac26b8 Binary files /dev/null and b/config.png differ diff --git a/javaweb-tomcat-sidecar/README.md b/javaweb-tomcat-sidecar/README.md new file mode 100644 index 0000000..52c613a --- /dev/null +++ b/javaweb-tomcat-sidecar/README.md @@ -0,0 +1,43 @@ +## Java Web Application with Tomcat and Sidecar Container + +The following document describes the deployment of a Java Web application using Tomcat. Instead of packaging `war` file inside the Tomcat image or mount the `war` as a volume, we use a sidecar container as `war` file provider. + +The orginal example is from Kubernetes examples project + +https://github.com/kubernetes/examples/blob/master/staging/javaweb-tomcat-sidecar/ + +## Test It Out + +Deploy application + +``` +kubectl apply -f javaweb.yaml +``` + +Check status of the deployments/pods/services: + +``` +kubectl get all +``` + +Check the external endpoint for load balancer + +``` +kubectl get svc tomcat-app-svc +``` + +Access the sample application + +``` +LB_ENDPOINT=$(kubectl get service tomcat-app-svc -o jsonpath="{.status.loadBalancer.ingress[*].ip}") + +# Open browser with URL in MacOSX +open http://${LB_ENDPOINT}:8080/sample/ +``` + +Delete application + + +``` +kubectl delete -f javaweb.yaml +``` diff --git a/javaweb-tomcat-sidecar/javaweb.yaml b/javaweb-tomcat-sidecar/javaweb.yaml new file mode 100644 index 0000000..523bfeb --- /dev/null +++ b/javaweb-tomcat-sidecar/javaweb.yaml @@ -0,0 +1,60 @@ +apiVersion: v1 +kind: Service +metadata: + name: tomcat-app-svc +spec: + ports: + - port: 8080 + protocol: TCP + targetPort: 8080 + selector: + app: tomcat-app + type: LoadBalancer +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: tomcat-app + labels: + app: tomcat-app +spec: + replicas: 1 + selector: + matchLabels: + app: tomcat-app + template: + metadata: + labels: + app: tomcat-app + spec: + initContainers: + - image: resouer/sample:v2 + name: war + imagePullPolicy: IfNotPresent + volumeMounts: + - mountPath: /app + name: app-volume + command: + - "cp" + - "-r" + - "/sample.war" + - "/app" + containers: + - image: tomcat:8-jre8-alpine + name: tomcat + imagePullPolicy: IfNotPresent + volumeMounts: + - mountPath: /usr/local/tomcat/webapps + name: app-volume + ports: + - containerPort: 8080 + resources: + requests: + memory: "256Mi" + cpu: "500m" + limits: + memory: "256Mi" + cpu: "500m" + volumes: + - name: app-volume + emptyDir: {}