Skip to content

Kubernetes Lab

Install Tools

Clone Lab Repo

  • git clone https://github.com/tejasparikh/csye7374-labs-spring2019

Setup Kubernetes Dashboard

  • Find create-service-account.yaml and cluster-role-binding.yaml in csye7374-labs-spring2019/kubernetes/dashboard directory.
  • Execute kubectl apply -f create-service-account.yaml and kubectl apply -f cluster-role-binding.yaml.
  • Deploy dashboard with command kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v1.10.1/src/deploy/recommended/kubernetes-dashboard.yaml.
  • Get dashboard login token using the command kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep admin-user | awk '{print $1}').
  • Dashboard can now be accessed locally via kubectl proxy at http://localhost:8001/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/.

AWS Container Registry IAM Setup

1
aws iam attach-group-policy --policy-arn arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryFullAccess  --group-name kops

Create ECR Repository Using AWS CLI

1
aws ecr create-repository --repository-name csye7374

Deploying App to Kubernetes Cluster

  • A simple Node.js application is located in csye7374-labs-spring2019/webapp directory.
  • A Docker file to build the image is in csye7374-labs-spring2019/webapp directory.

Build & Push Docker Container Image to Amazon ECR

Retrieve the login command to use to authenticate your Docker client to your registry

1
aws ecr get-login --no-include-email --region us-east-1

Build Docker Image

1
docker build -t csye7374 .

Tag Docker Image

1
docker tag csye7374:latest <AWS_ACCOUNT_ID>.dkr.ecr.us-east-1.amazonaws.com/csye7374:latest

Push Docker Image

1
docker push <AWS_ACCOUNT_ID>.dkr.ecr.us-east-1.amazonaws.com/csye7374:latest

Run Application

Create Deployment

  • Pod deployment file can be found in csye7374-labs-spring2019/kubernetes/app directory.
  • Create deployment using kubectl apply -f csye7374-pod.yaml

Access Application

Make REST calls to your application by creating a proxy

1
2
kubectl port-forward csye7374 8888:8080
curl http://localhost:8888