Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 270e305

Browse filesBrowse files
author
Ram Vennam
committed
Add instructions for IBM Kubernetes Service
1 parent 6fbcbbe commit 270e305
Copy full SHA for 270e305

File tree

Expand file treeCollapse file tree

6 files changed

+167
-0
lines changed
Filter options
Expand file treeCollapse file tree

6 files changed

+167
-0
lines changed

‎.dockerignore

Copy file name to clipboard
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.gitignore
2+
LICENSE
3+
README.md
4+
vcap-local.json

‎Dockerfile

Copy file name to clipboard
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
FROM python:2-alpine
2+
3+
COPY ./requirements.txt /app/requirements.txt
4+
5+
WORKDIR /app
6+
7+
RUN apk --update add python py-pip openssl ca-certificates py-openssl wget bash linux-headers
8+
RUN apk --update add --virtual build-dependencies libffi-dev openssl-dev python-dev py-pip build-base \
9+
&& pip install --upgrade pip \
10+
&& pip install --upgrade pipenv\
11+
&& pip install --upgrade -r /app/requirements.txt\
12+
&& apk del build-dependencies
13+
14+
COPY . /app
15+
16+
ENTRYPOINT [ "python" ]
17+
18+
CMD [ "hello.py" ]

‎README-kubernetes.md

Copy file name to clipboard
+97Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# Deploy to IBM Cloud Kubernetes Service
2+
3+
Follow these instructions to deploy this application to a Kubernetes cluster and connect it with a Cloudant database.
4+
5+
## Download
6+
7+
```bash
8+
https://github.com/IBM-Cloud/get-started-python
9+
cd get-started-python
10+
```
11+
12+
## Build Docker Image
13+
14+
1. Find your container registry **namespace** by running `ibmcloud cr namespaces`. If you don't have any, create one using `ibmcloud cr namespace-add <name>`
15+
16+
2. Identify your **Container Registry** by running `ibmcloud cr info` (Ex: registry.ng.bluemix.net)
17+
18+
3. Build and tag (`-t`)the docker image by running the command below replacing REGISTRY and NAMESPACE with he appropriate values.
19+
20+
```sh
21+
docker build . -t <REGISTRY>/<NAMESPACE>/myapp:v1.0.0
22+
```
23+
Example: `docker build . -t registry.ng.bluemix.net/mynamespace/myapp:v1.0.0
24+
25+
4. Push the docker image to your Container Registry on IBM Cloud
26+
27+
```sh
28+
docker push <REGISTRY>/<NAMESPACE>/myapp:v1.0.0
29+
```
30+
31+
## Deploy
32+
33+
#### Create a Kubernetes cluster
34+
35+
1. [Creating a Kubernetes cluster in IBM Cloud](https://console.bluemix.net/docs/containers/container_index.html#clusters).
36+
2. Follow the instructions in the Access tab to set up your `kubectl` cli.
37+
38+
#### Create a Cloudant Database
39+
40+
1. Go to the [Catalog](https://console.bluemix.net/catalog/) and create a new [Cloudant](https://console.bluemix.net/catalog/services/cloudant-nosql-db) database instance.
41+
42+
2. Choose `Legacy and IAM` for **Authentication**
43+
44+
3. Create new credentials under **Service Credentials** and copy value of the **url** field.
45+
46+
4. Create a Kubernetes secret with your Cloudant credentials (url, username and password).
47+
48+
```bash
49+
kubectl create secret generic cloudant --from-literal=url=<URL> --from-literal=username=<USERNAME> --from-literal=password=<PASSWORD>
50+
```
51+
Example:
52+
```bash
53+
kubectl create secret generic cloudant --from-literal=url=https://myusername:passw0rdf@username-bluemix.cloudant.com --from-literal=username=myusername --from-literal=password=passw0rd
54+
```
55+
56+
#### Create the deployment
57+
58+
1. Replace `<REGISTRY>` and `<NAMESPACE>` with the appropriate values in `kubernetes/deployment.yaml`
59+
2. Create a deployment:
60+
```shell
61+
kubectl create -f kubernetes/deployment.yaml
62+
```
63+
- **Paid Cluster**: Expose the service using an External IP and Loadbalancer
64+
```
65+
kubectl expose deployment get-started-python --type LoadBalancer --port 8000 --target-port 8000
66+
```
67+
68+
- **Free Cluster**: Use the Worker IP and NodePort
69+
```bash
70+
kubectl expose deployment get-started-python --type NodePort --port 8000 --target-port 8000
71+
```
72+
73+
### Access the application
74+
75+
Verify **STATUS** of pod is `RUNNING`
76+
77+
```shell
78+
kubectl get pods -l app=get-started-python
79+
```
80+
81+
**Standard (Paid) Cluster:**
82+
83+
1. Identify your LoadBalancer Ingress IP using `kubectl get service get-started-python`
84+
2. Access your application at t `http://<EXTERNAL-IP>:8000/`
85+
86+
**Free Cluster:**
87+
88+
1. Identify your Worker Public IP using `ibmcloud cs workers YOUR_CLUSTER_NAME`
89+
2. Identify the Node Port using `kubectl describe service get-started-python`
90+
3. Access your application at `http://<WORKER-PUBLIC-IP>:<NODE-PORT>/`
91+
92+
93+
## Clean Up
94+
```bash
95+
kubectl delete deployment,service -l app=get-started-python
96+
kubectl delete secret cloudant
97+
```

‎README.md

Copy file name to clipboardExpand all lines: README.md
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
To get started, we'll take you through a sample Python Flask app, help you set up a development environment, deploy to IBM Cloud and add a Cloudant database.
44

5+
The following instructions are for deploying the application as a Cloud Foundry application. To deploy as a container to **IBM Cloud Kubernetes Service** instead, [see README-kubernetes.md](README-kubernetes.md)
6+
57
## Prerequisites
68

79
You'll need the following:

‎hello.py

Copy file name to clipboardExpand all lines: hello.py
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
url = 'https://' + creds['host']
2121
client = Cloudant(user, password, url=url, connect=True)
2222
db = client.create_database(db_name, throw_on_exists=False)
23+
elif "CLOUDANT_URL" in os.environ:
24+
client = Cloudant(os.environ['CLOUDANT_USERNAME'], os.environ['CLOUDANT_PASSWORD'], url=os.environ['CLOUDANT_URL'], connect=True)
25+
db = client.create_database(db_name, throw_on_exists=False)
2326
elif os.path.isfile('vcap-local.json'):
2427
with open('vcap-local.json') as f:
2528
vcap = json.load(f)

‎kubernetes/deployment.yaml

Copy file name to clipboard
+43Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Update <REGISTRY> <NAMESPACE> values before use
2+
apiVersion: apps/v1
3+
kind: Deployment
4+
metadata:
5+
name: get-started-python
6+
labels:
7+
app: get-started-python
8+
spec:
9+
replicas: 1
10+
selector:
11+
matchLabels:
12+
app: get-started-python
13+
template:
14+
metadata:
15+
labels:
16+
app: get-started-python
17+
spec:
18+
containers:
19+
- name: get-started-python
20+
image: <REGISTRY>/<NAMESPACE>/myapp:v1.0.0
21+
ports:
22+
- containerPort: 8000
23+
imagePullPolicy: Always
24+
env:
25+
- name: CLOUDANT_URL
26+
valueFrom:
27+
secretKeyRef:
28+
name: cloudant
29+
key: url
30+
optional: true
31+
- name: CLOUDANT_USERNAME
32+
valueFrom:
33+
secretKeyRef:
34+
name: cloudant
35+
key: username
36+
optional: true
37+
- name: CLOUDANT_PASSWORD
38+
valueFrom:
39+
secretKeyRef:
40+
name: cloudant
41+
key: password
42+
optional: true
43+

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.