Deploy the app using Kubernetes Services and Deployments
Different ways exist to make your app accessible from the internet. To choose the best networking option for your application, you can follow the decision tree available here.
In this lab, we will test the Ingress.
Deploy with Ingress
Navigate to the folder kubernetes.
cd kubernetes
Let's use the online web editor to modify the deployment file. Click the pen on the top right corner
Open the project mytodos you cloned before. Select File on the left hand side, then Open Workspace and search for the downloaded project
Select the file
ingress-tls-deploy.yaml
.Replace all the values wrapped in <...> with the appropriate values: registry-region such as
us
for Dallas, registry-namespace such aspyrk8s
, cluster-name such asus-south
for Dallas, cluster-name such asworkshop-cs-jp-pyrk8s10
Your YAML file should look as follows:
--- # Application to deploy apiVersion: apps/v1 kind: Deployment metadata: name: mytodos spec: replicas: 2 # tells deployment to run 2 pods matching the template selector: matchLabels: app: mytodos template: # create pods using pod definition in this template metadata: labels: app: mytodos tier: frontend spec: containers: - name: mytodos image: <registry-region>.icr.io/<registry-namespace>/todo-<lastname>:1.0 imagePullPolicy: Always resources: requests: cpu: 250m # 250 millicores = 1/4 core memory: 128Mi # 128 MB limits: cpu: 500m memory: 384Mi # envFrom: # - secretRef: # name: database-credentials --- apiVersion: extensions/v1beta1 kind: Ingress metadata: name: mytodos-ingress annotations: ingress.bluemix.net/rewrite-path: "serviceName=mytodos rewrite=/" # Force the use of https if the request is http ingress.bluemix.net/redirect-to-https: "True" spec: tls: - hosts: - <cluster-name>.<cloud-region>.containers.appdomain.cloud secretName: <cluster-name> rules: - host: <cluster-name>.<cloud-region>.containers.appdomain.cloud http: paths: - path: /todo/ backend: serviceName: mytodos servicePort: 8080 --- # Service to expose frontend apiVersion: v1 kind: Service metadata: name: mytodos labels: app: mytodos tier: frontend spec: ports: - protocol: TCP port: 8080 selector: app: mytodos tier: frontend
Deploy the app into your Kubernetes cluster.
kubectl apply -f ingress-tls-deploy.yaml
Result:
deployment.apps/mytodos created ingress.extensions/mytodos-ingress created service/mytodos created
Open a browser and check out the app with the following URL:
https://<cluster-name>.us-south.containers.appdomain.cloud/todo/
In this example, the url would be
https://workshop-cs-jp-pyrk8s10.us-south.containers.appdomain.cloud/todo/