Skip to content

Commit

Permalink
Merge pull request #98 from chibiegg/feat/k8s
Browse files Browse the repository at this point in the history
kubernatesに変更
  • Loading branch information
chibiegg authored Sep 18, 2019
2 parents 542756f + fe3b26f commit 5f14214
Show file tree
Hide file tree
Showing 13 changed files with 350 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@ README.md
.gitignore
.git/
media/icons/*
docs/
kubernates/
nginx/
logs/
data/
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,5 @@ venv.bak/
# mypy
.mypy_cache/

log/
logs/
data/
25 changes: 25 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
all: nginx app

.PHONY: nginx app apply delete

nginx: nginx/Dockerfile
cd nginx && docker build -t isucon/portal-nginx .

app: Dockerfile
docker build -t isucon/portal-app .

apply:
kubectl apply -f kubernates/00-*.yml
kubectl apply -f kubernates/01-*.yml
kubectl apply -f kubernates/02-*.yml
kubectl apply -f kubernates/03-*.yml
kubectl apply -f kubernates/04-*.yml
kubectl apply -f kubernates/05-*.yml

delete:
kubectl delete -f kubernates/05-*.yml
kubectl delete -f kubernates/04-*.yml
kubectl delete -f kubernates/03-*.yml
kubectl delete -f kubernates/02-*.yml
kubectl delete -f kubernates/01-*.yml
kubectl delete -f kubernates/00-*.yml
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ python manage.py runserver
```


## kubernates (minikube)

```bash
make
make apply
```

## docker-compose

```bash
Expand Down
4 changes: 2 additions & 2 deletions isucon/portal/docker_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
'NAME': 'isucon',
'USER': 'isucon',
'PASSWORD': 'password',
'HOST': 'postgres',
'HOST': os.environ.get('POSTGRES_HOST', "postgres"),
'PORT': '5432',
'ATOMIC_REQUESTS': True,
}
Expand All @@ -54,7 +54,7 @@
else:
raise ValueError("Invalid DJANGO_DATABASE_TYPE '{}'".format(DATABASE_TYPE))

REDIS_HOST = 'redis'
REDIS_HOST = os.environ.get('REDIS_HOST', "redis")
REDIS_RANKING_TOPN = os.getenv('REDIS_RANKING_TOPN', 30)

SOCIAL_AUTH_GITHUB_KEY = os.environ.get("GITHUB_KEY", "")
Expand Down
18 changes: 18 additions & 0 deletions kubernates/00-secret.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: v1
kind: Secret
metadata:
name: portal-secret
type: Opaque
data:
github_key: NjUwYjFjODVkMTVjOWJlMzgzNmU=
# 650b1c85d15c9be3836e
github_secret: YmY4OWE0MTBmNDk5YzY3NGI0ZTllOTljZjE0Nzg2ZWU3MDhjM2YzZQ==
# bf89a410f499c674b4e9e99cf14786ee708c3f3e
django_allowed_host: cG9ydGFsLmlzdWNvbi5uZXQ=
# portal.isucon.net
slack_endpoint_url: aHR0cHM6Ly9ob29rcy5zbGFjay5jb20vc2VydmljZXMvVDA1MDZWOEpLL0JMOEE1MFJBNy96M0xXR0t0TVdFMHVONlluYm5CaTFGbHA=
# https://hooks.slack.com/services/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
alibaba_access_key_id: TFRBSXpjVGptU3h3bzhwSg==
# LTAIzcTjmSxwo8pJ
alibaba_access_key_secret: ZFE4dmkwYnBpNzE0aFlLblZmQ2YySzNwb2h2Sjhn
# dQ8vi0bpi714hYKnVfCf2K3pohvJ8g
33 changes: 33 additions & 0 deletions kubernates/01-redis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
apiVersion: v1
kind: Service
metadata:
name: portal-redis
spec:
ports:
- port: 6379
selector:
app: portal-redis

---

apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: portal-redis
spec:
selector:
matchLabels:
app: portal-redis
strategy:
type: Recreate
template:
metadata:
labels:
app: portal-redis
spec:
containers:
- image: redis:5.0-alpine
name: portal-redis
ports:
- containerPort: 6379
name: portal-redis
47 changes: 47 additions & 0 deletions kubernates/02-postgres.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
apiVersion: v1
kind: Service
metadata:
name: portal-db
spec:
ports:
- port: 5432
selector:
app: portal-db

---

apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: portal-db
spec:
selector:
matchLabels:
app: portal-db
strategy:
type: Recreate
template:
metadata:
labels:
app: portal-db
spec:
containers:
- image: postgres:12-alpine
name: portal-db
env:
- name: POSTGRES_DB
value: isucon
- name: POSTGRES_USER
value: isucon
- name: POSTGRES_PASSWORD
value: password
ports:
- containerPort: 5432
name: portal-db
volumeMounts:
- name: postgress-volume
mountPath: /var/lib/postgresql/data
volumes:
- name: postgress-volume
hostPath:
path: /opt/portal/data/postgresql
57 changes: 57 additions & 0 deletions kubernates/03-volume.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
kind: PersistentVolume
apiVersion: v1
metadata:
name: portal-static-volume
spec:
storageClassName: manual
capacity:
storage: 100Gi
accessModes:
- ReadWriteOnce
hostPath:
path: /opt/portal/data/static

---

kind: PersistentVolume
apiVersion: v1
metadata:
name: portal-static-nginx-volume
spec:
storageClassName: manual
capacity:
storage: 100Gi
accessModes:
- ReadWriteOnce
hostPath:
path: /opt/portal/data/static

---

kind: PersistentVolume
apiVersion: v1
metadata:
name: portal-media-volume
spec:
storageClassName: manual
capacity:
storage: 100Gi
accessModes:
- ReadWriteOnce
hostPath:
path: /opt/portal/data/media

---

kind: PersistentVolume
apiVersion: v1
metadata:
name: portal-media-nginx-volume
spec:
storageClassName: manual
capacity:
storage: 100Gi
accessModes:
- ReadWriteOnce
hostPath:
path: /opt/portal/data/media
93 changes: 93 additions & 0 deletions kubernates/04-app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
apiVersion: v1
kind: Service
metadata:
name: portal-app
spec:
ports:
- port: 5000
selector:
app: portal-app

---

apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: portal-app
spec:
selector:
matchLabels:
app: portal-app
strategy:
type: Recreate
template:
metadata:
labels:
app: portal-app
spec:
containers:
- image: isucon/portal-app:latest
imagePullPolicy: IfNotPresent
name: portal-app
env:
- name: REDIS_HOST
value: portal-redis
- name: DJANGO_DATABASE_TYPE
value: postgres
- name: POSTGRES_HOST
value: portal-db
- name: DJANGO_DEBUG
value: "false"
- name: CONTEST
value: "false"
- name: GITHUB_KEY
valueFrom:
secretKeyRef:
name: portal-secret
key: github_key
- name: GITHUB_SECRET
valueFrom:
secretKeyRef:
name: portal-secret
key: github_secret
- name: DJANGO_ALLOWED_HOST
valueFrom:
secretKeyRef:
name: portal-secret
key: django_allowed_host
- name: SLACK_ENDPOINT_URL
valueFrom:
secretKeyRef:
name: portal-secret
key: slack_endpoint_url
- name: ALIBABA_ACCESS_KEY_ID
valueFrom:
secretKeyRef:
name: portal-secret
key: alibaba_access_key_id
- name: ALIBABA_ACCESS_KEY_SECRET
valueFrom:
secretKeyRef:
name: portal-secret
key: alibaba_access_key_secret
ports:
- containerPort: 5000
name: portal-app
volumeMounts:
- name: static-volume
mountPath: /opt/app/static
- name: media-volume
mountPath: /opt/app/media
- name: log-volume
mountPath: /var/log/django/

volumes:
- name: static-volume
hostPath:
path: /opt/portal/data/static
- name: media-volume
hostPath:
path: /opt/portal/data/media
- name: log-volume
hostPath:
path: /opt/portal/logs/django
56 changes: 56 additions & 0 deletions kubernates/05-nginx.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
apiVersion: v1
kind: Service
metadata:
name: portal-nginx
spec:
type: NodePort
ports:
- name: "http-port"
port: 80
targetPort: 80
nodePort: 30080
selector:
app: portal-nginx

---

apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: portal-nginx
spec:
selector:
matchLabels:
app: portal-nginx
strategy:
type: Recreate
template:
metadata:
labels:
app: portal-nginx
spec:
containers:
- image: isucon/portal-nginx:latest
imagePullPolicy: IfNotPresent
name: portal-nginx
ports:
- containerPort: 80
name: portal-nginx
volumeMounts:
- name: static-volume
mountPath: /opt/app/static
- name: media-volume
mountPath: /opt/app/media
- name: log-volume
mountPath: /var/log/nginx/

volumes:
- name: static-volume
hostPath:
path: /opt/portal/data/static
- name: media-volume
hostPath:
path: /opt/portal/data/media
- name: log-volume
hostPath:
path: /opt/portal/logs/nginx
4 changes: 4 additions & 0 deletions nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM nginx:latest

ADD nginx.conf /etc/nginx/
ADD conf.d/ /etc/nginx/conf.d/
2 changes: 1 addition & 1 deletion nginx/conf.d/default.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
upstream portal {
server django:5000;
server portal-app:5000;
keepalive 128;
}

Expand Down

0 comments on commit 5f14214

Please sign in to comment.