Kubernetes — GKE — Ingress

Containers and Containers and Containers
docker build --build-arg docker_env=staging --build-arg=v1-2 -t myapp .
docker run -d -p 80:8080 --name MyDockerApp myapp:latest
docker tag myapp:latest gcr.io/Your-Project-ID/myapp:v1 docker tag myapp:latest gcr.io/Your-Project-ID/myapp:latest docker push gcr.io/Your-Project-ID/myapp:v1 docker push gcr.io/Your-Project-ID/myapp:latest
gcloud config set project Your-Project-ID gcloud config set compute/zone us-east1-b gcloud config set compute/region us-east1
gcloud container --project "Your-Project-ID" clusters create "myapp-staging" --zone "us-east1-b" --username "admin" --cluster-version "1.11.7-gke.4" --machine-type "n1-standard-2" --image-type "COS" --disk-type "pd-standard" --disk-size "100" --scopes "https://www.googleapis.com/auth/cloud-platform" --num-nodes "3" --enable-cloud-logging --enable-cloud-monitoring --no-enable-ip-alias --network "projects/Your-Project-ID/global/networks/default" --subnetwork "projects/Your-Project-ID/regions/us-east1/subnetworks/default" --addons HorizontalPodAutoscaling,HttpLoadBalancing --enable-autoupgrade --enable-autorepair --enable-autoscaling --min-nodes 3 --max-nodes 6
curl https://raw.githubusercontent.com/kubernetes/helm/master/scripts/get > get_helm.sh chmod 700 get_helm.sh ./get_helm.sh kubectl create namespace staging helm init --tiller-namespace staging
kubectl create serviceaccount --namespace staging tiller kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=staging:tiller helm init --service-account tiller --tiller-namespace staging --upgrade
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
annotations:
deployment.kubernetes.io/revision: "1"
generation: 1
labels:
app: myapp-staging
name: myapp-staging
namespace: staging
spec:
progressDeadlineSeconds: 600
replicas: 3
revisionHistoryLimit: 10
selector:
matchLabels:
app: myapp-staging
strategy:
rollingUpdate:
maxSurge: 5
maxUnavailable: 2
type: RollingUpdate
template:
metadata:
creationTimestamp: null
labels:
app: myapp-staging
spec:
containers:
- image: gcr.io/Your-Project-ID/myapp:latest
imagePullPolicy: IfNotPresent
name: myapp-staging
resources:
requests:
memory: "128Mi"
cpu: "250m"
limits:
memory: "1Gi"
cpu: "500m"
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
kubectl apply -f app-deploy.yaml
kubectl expose deployment myapp-staging --port=8080 --namespace staging
kubectl create secret tls tls-secret-staging --key yourdomain.com.key --cert yourdomain.com.crt -n staging
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: ingress-resource-staging
namespace: staging
annotations:
kubernetes.io/ingress.class: nginx
ingress.kubernetes.io/ssl-redirect: "true"
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- host: staging.yourdomain.com
http:
paths:
- backend:
serviceName: myapp-staging
servicePort: 8080
path: /
- host: staging2.yourdomain.com
http:
paths:
- backend:
serviceName: myapp-staging
servicePort: 8080
path: /
tls:
- hosts:
- staging.yourdomain.com
- staging2.yourdomain.com
secretName: tls-secret-staging
kubectl get pods -n staging
NAME READY STATUS RESTARTS AGE myapp-staging-c56f35-8kshd 1/1 Running 0 3h myapp-staging-c56f35-c29db 1/1 Running 0 3h tiller-deploy-778c56f35-bb8 1/1 Running 0 8d
helm install --name nginx-ingress-myapp-staging stable/nginx-ingress --set rbac.create=true --tiller-namespace staging
kubectl get svc

A fun loving developer who likes to write about, talk about, and teach tech solutions, and help others succeed!

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store