- google cloud SDK: https://cloud.google.com/sdk/docs/
- kubectl: https://kubernetes.io/docs/tasks/tools/install-kubectl/
- docker: https://docs.docker.com/install/
- NodeJs: https://nodejs.org/en/
Link to Repo: https://github.com/raymundoxmartinez/StoreService
Step 1: Create an App
For this part, we’ll create a basic app using express to generate a simple web server without a view engine.
You should end up with the following file structure:
Let's make a few changes to the app. First, we’ll change the port that the server is listening to.
Navigate to bin/www
All we did is change the port number from 3000 to 8080.
Next, we’ll edit the response of the /users route
Navigate to routes/users.js
Now run your server
and test your service on Postman.
We now have a working service!
Step 2: Create a Docker Image
First, we’ll add a Dockerfile to the root directory.
Your Dockerfile should look like this:
Note that the CMD [“node”, “./bin/www”] is the command that runs the application. Alter the command if you have a different one (e.g node server.js).
in the root directory to build and tag the docker image.
You should end up with something like this:
View your images by running
you should be able to see a list of the built images.
Now let's run the container!!
here we map the port of the server 8080 to the container port 49160.
Let’s test our container on Postman:
Now we are communicating with a service inside a docker container!
Step 3: Push Image to a Registry
Let’s Create a new project in the Google Cloud Platform.
Login to gcloud:
Now authorize your gcloud account to connect with docker:
You should see this:
Now let’s tag and push the image to the gcloud repository:
Check the container registry to make sure your image was pushed successfully.
Step 4: Create a Cluster
Go to the gcloud platform and create a new cluster.
Rename the cluster to store-cluster and change the location type to regional.
Now make sure that you enable the istio setting!!
We will use this feature to communicate with the cluster.
Step 5: Configure Settings to Connect Kubernetes with Your New Cluster
Connect to the project you created in Step 3:
Now connect to the cluster created in Step 4:
Check that kubernetes is communicating with your gcloud cluster:
You should see gke_YOUR_PROJECT_ID_REGION_CLUSTER_NAME
Step 6: Create a Yaml File Defining Your Service
Create a new file in the root directory called store-service.yaml
There will be 3 parts in this file:
make sure to include the “ — -” at the end of the section.
Replace “URL_TO_DOCKER_IMAGE” with the url of the image pushed to the registry in Step 3.
You can find the url in the Container Registry section
Click the store repository.
Now copy the ‘full image name’ and add it to the Deployment section above.
Let’s deploy our container!
Check that the service was deployed successfully:
You should see:
Check the status of the deployed container:
You should see:
Great now let's open a gateway to our service!!
Step 7: Create a Gateway Yaml File
Add a new file to the root directory called store-gateway.yaml.
There are 2 sections to this file:
Deploy the gateway:
Check that it deployed successfully.
You should see:
Now its time to test! :D
Step 8: Test Your Service
Let’s get the IP address of the gateway we created above.
you should see:
Copy the EXTERNAL-IP.
Now go to Postman and test your service by calling:
Now you are free to explore the limits of docker, gcloud and kubernetes.
Enjoy your journey!!