Skip to content

Commit

Permalink
add support for local k8s deployment (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnazariah authored Oct 14, 2020
1 parent 419be66 commit 58551b1
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ test-docker-flow :
$(MAKE) -C $(test_install_root)/$(lang)/$(template)/ docker-build

test-dotnet-flow :
$(MAKE) -C $(test_install_root)/$(lang)/$(template)/ dotnet-secrets-init dotnet-build dotnet-test
$(MAKE) -C $(test_install_root)/$(lang)/$(template)/ dotnet-build dotnet-test

create-scratch-project :
mkdir -p $(test_install_root)
Expand Down
2 changes: 1 addition & 1 deletion templates/silo-and-client/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ dotnet-clean:
- rm -rf out/$(project)
dotnet clean $(project).sln

dotnet-secrets-init dotnet-publish dotnet-run:
dotnet-publish dotnet-run:
$(MAKE) -f $(silo).Makefile $@
$(MAKE) -f $(client).Makefile $@

Expand Down
5 changes: 1 addition & 4 deletions templates/silo-and-client/Template.Client.Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ image_tag = $(git_branch).$(git_latest_hash)
container_name:= $(acr)/$(project-lc):$(image_tag)

# Initialize
init : dotnet-secrets-init git-init
init : git-init
git status

git-init :
Expand All @@ -31,9 +31,6 @@ git-init :
git commit -m "Initial commit of Template"

# .NET commands
dotnet-secrets-init :
dotnet user-secrets init --project $(project)/$(project)._PROJ_SUFFIX_

dotnet-publish :
dotnet publish --no-build $(project)/$(project)._PROJ_SUFFIX_ -c $(config) -o out/$(project)
@echo Built DotNet projects
Expand Down
5 changes: 1 addition & 4 deletions templates/silo-and-client/Template.Silo.Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ image_tag = $(git_branch).$(git_latest_hash)
container_name:= $(acr)/$(project-lc):$(image_tag)

# Initialize
init : dotnet-secrets-init git-init
init : git-init
git status

git-init :
Expand All @@ -32,9 +32,6 @@ git-init :
git commit -m "Initial commit of Template"

# .NET commands
dotnet-secrets-init :
dotnet user-secrets init --project $(project)/$(project)._PROJ_SUFFIX_

dotnet-publish :
dotnet publish --no-build $(project)/$(project)._PROJ_SUFFIX_ -c $(config) -o out/$(project)
@echo Built DotNet projects
Expand Down
5 changes: 1 addition & 4 deletions templates/standalone-client/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ image_tag = $(git_branch).$(git_latest_hash)
container_name:= $(acr)/$(project-lc):$(image_tag)

# Initialize
init : dotnet-secrets-init git-init
init : git-init
git status

git-init :
Expand All @@ -31,9 +31,6 @@ git-init :
git commit -m "Initial commit of Template"

# .NET commands
dotnet-secrets-init :
dotnet user-secrets init --project $(project)/$(project)._PROJ_SUFFIX_

dotnet-publish :
dotnet publish --no-build $(project)/$(project)._PROJ_SUFFIX_ -c $(config) -o out/$(project)
@echo Built DotNet projects
Expand Down
5 changes: 1 addition & 4 deletions templates/standalone-silo/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ image_tag = $(git_branch).$(git_latest_hash)
container_name:= $(acr)/$(project-lc):$(image_tag)

# Initialize
init : dotnet-secrets-init git-init
init : git-init
git status

git-init :
Expand All @@ -32,9 +32,6 @@ git-init :
git commit -m "Initial commit of Template"

# .NET commands
dotnet-secrets-init :
dotnet user-secrets init --project $(project)/$(project)._PROJ_SUFFIX_

dotnet-publish :
dotnet publish --no-build $(project)/$(project)._PROJ_SUFFIX_ -c $(config) -o out/$(project)
@echo Built DotNet projects
Expand Down
32 changes: 28 additions & 4 deletions templates/webapi-directclient/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ image_tag = $(git_branch).$(git_latest_hash)

container_name:= $(acr)/$(project-lc):$(image_tag)

# k8s namespace
k8s_namespace=green

# Initialize
init : dotnet-secrets-init git-init
init : git-init
git status

git-init :
Expand All @@ -32,9 +35,6 @@ git-init :
git commit -m "Initial commit of Template"

# .NET commands
dotnet-secrets-init :
dotnet user-secrets init --project $(project)/$(project)._PROJ_SUFFIX_

dotnet-publish :
dotnet publish --no-build $(project)/$(project)._PROJ_SUFFIX_ -c $(config) -o out/$(project)
@echo Built DotNet projects
Expand Down Expand Up @@ -108,3 +108,27 @@ docker-kill : docker-stop
docker-clean : docker-kill
@echo Pruning all images
- docker image prune -af

# Local Kubernetes Commands
k8s-cleanup :
kubectl delete namespace $(k8s_namespace)

k8s-deploy : k8s-create-namespace k8s-replace-image-tag
kubectl apply -f local-k8s-deployment.yml

k8s-dashboard : k8s-deploy-dashboard k8s-setup-rbac
kubectl proxy

k8s-create-namespace :
kubectl create namespace $(k8s_namespace)
kubectl config set-context --current --namespace $(k8s_namespace)

k8s-replace-image-tag :
sed -e "s|{image-name}|$(container_name)|g" local-k8s-deployment-template.yml > local-k8s-deployment.yml

k8s-deploy-dashboard :
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.0/aio/deploy/recommended.yaml

k8s-setup-rbac :
kubectl apply -f local-k8s-rbac.yml
kubectl -n kubernetes-dashboard describe secret $(kubectl -n kubernetes-dashboard get secret | grep admin-user | awk '{print $1}')
74 changes: 74 additions & 0 deletions templates/webapi-directclient/local-k8s-deployment-template.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
kind: Deployment
apiVersion: apps/v1
metadata:
name: template-deployment
spec:
replicas: 3
selector:
matchLabels:
app: template-pod
template:
metadata:
labels:
app: template-pod
spec:
containers:
- name: template-container
image: {image-name}
resources:
limits:
memory: "512Mi"
cpu: "1000m"
requests:
memory: "128Mi"
cpu: "500m"
# env:
# - name: ENV_CLUSTER_AZURE_STORAGE
# valueFrom:
# secretKeyRef:
# name: {storage-secret-name}
# key: connection-string
# - name: ENV_PERSISTENCE_AZURE_TABLE
# valueFrom:
# secretKeyRef:
# name: {storage-secret-name}
# key: connection-string
# - name: ENV_DATA_STORAGE_CONNECTION_STRING
# valueFrom:
# secretKeyRef:
# name: {storage-secret-name}
# key: connection-string
# - name: ENV_DATA_STORAGE_COLLECTION_NAME
# valueFrom:
# secretKeyRef:
# name: {storage-secret-name}
# key: collection-name
ports:
- name: http
containerPort: 80
protocol: TCP
- name: gateway
containerPort: 30000
protocol: TCP
- name: silo
containerPort: 11111
protocol: TCP
- name: dashboard
containerPort: 8080
protocol: TCP
---
kind: Service
apiVersion: v1
metadata:
name: template-service
spec:
selector:
app: template-pod
type: LoadBalancer
ports:
- name: dashboard
port: 8080
targetPort: 8080
- name: http
port: 80
targetPort: 80
19 changes: 19 additions & 0 deletions templates/webapi-directclient/local-k8s-rbac.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: admin-user
namespace: kubernetes-dashboard

---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: admin-user
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: admin-user
namespace: kubernetes-dashboard

0 comments on commit 58551b1

Please sign in to comment.