This repository contains Kubernetes files for clustering the node.api.gateway back-end, and the react.antd.fuse front-end.
The instructions below are for your local development environment.
- Install Docker for Mac, alternatively use Minikube Minikube
- Enable Kubernetes via Docker for Mac. (Not required if using Minikube)
- Install Kubectl:
brew install kubernetes-cli
- Check Kubernetes Nodes:
kubectl get nodes
- Install Helm:
brew install kubernetes-helm && helm init --upgrade
- Follow the instructions in either the Development or Production sections.
Further reading: Learn Kubernetes in under 3 hours
Some of the instructions below are for Minikube user only, if you are not using Minikube you may ignore those sections.
If you are not using Minikube you can install the Kubernetes dashboard by following the instructions below:
- Add the dashboard as a pod:
kubectl create -f https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml
- Ensure it was created:
kubectl get pods --namespace=kube-system
- Setup port-forwarding:
kubectl port-forward <your-kubernetes-dashboard-name> 8443:8443 --namespace=kube-system
, e.g.kubectl port-forward kubernetes-dashboard-7b9c7bc8c9-chvng 8443:8443 --namespace=kube-system
- Go to the dashboard: https://localhost:8443. You can skip # if prompted.
Check the available docker images: docker image ls
If you do not have the required images for this project you will need to build them from existing repositories.
- Clone the React project:
git clone https://github.com/nicolaspearson/react.antd.fuse.git
- Clone the Node API Gateway project:
git clone https://github.com/nicolaspearson/node.api.gateway.git
- Open and build the React project:
cd react.antd.fuse && docker-compose build
- Open and build the API project:
cd node.api.gateway && docker-compose build
- Verify the built images:
docker image ls
- Deploy All:
./dev-deploy.sh
- Undeploy All:
./dev-undeploy.sh
Visit the Traefik dashboard: http://dashboard.localhost
Add the API Gateway to your hosts file:
echo "127.0.0.1 gateway.localhost" | sudo tee -a /etc/hosts
Add the React Client Frontend to your hosts file:
echo "127.0.0.1 react.client.localhost" | sudo tee -a /etc/hosts
The API Gateway is created at gateway.localhost
by the deploy script, navigate to http://gateway.localhost/api/v1/auth/authorize using your browser, and make sure you see an appropriate response to verify that the gateway is available.
The React Client App is created at react.client.localhost
by the deploy script, navigate to http://react.client.localhost using your browser.
If you are using Minikube, follow the instructions below.
If you are building the Docker images locally you need to expose it to Minikube:
- Start Minikube:
minikube start
- Check Kubernetes Nodes:
kubectl get nodes
To view the kubernetes dashboard: minikube dashboard
Share the docker env with minikube: eval $(minikube docker-env)
Check the available docker images: docker image ls
You will notice that it displays the images available to Minikube, but not the images that have already been created on your local machine. Minikube runs in a VM and therefore your images cannot be simply be shared, you will need to create the images within the Minikube context, e.g.
- Open the project:
cd react-lupinemoon-client
/ Open the api project:cd node.api.gateway
- View local images:
docker image ls
- Switch to Minikube Docker Env:
eval $(minikube docker-env)
- View Minikube images:
docker image ls
- Build the image in the Minikube context:
docker-compose up --build
- View built images:
docker image ls
- Your Minikube instance now has your local images built within it's context
- Stop Minikube:
minikube stop
Get a shell to the running Container: kubectl exec -it <pod-name> -- /bin/bash
This section will remain empty until the deployment pipeline has been built.
Below are some tips for using Kubernetes, the commands provided are NOT specific to this project.
-
Setup autocomplete in bash; bash-completion package should be installed first
source <(kubectl completion bash)
-
View Kubernetes config
kubectl config view
-
View specific config items by json path
kubectl config view -o jsonpath='{.users[?(@.name == "k8s")].user.password}'
-
Get documentation for pod or service
kubectl explain pods,svc
-
Create resource(s) like pods, services or daemon sets
kubectl create -f ./my-manifest.yaml
-
Apply a configuration to a resource
kubectl apply -f ./my-manifest.yaml
-
Start a single instance of Nginx
kubectl run nginx --image=nginx
-
Create a secret with several keys
``` cat <<EOF | kubectl create -f - apiVersion: v1 kind: Secret metadata: name: mysecret type: Opaque data: password: $(echo -n "s33msi4" | base64) username: $(echo -n "jane" | base64) EOF ```
-
Delete a resource
kubectl delete -f ./my-manifest.yaml
-
List all services in the namespace
kubectl get services
-
List all pods in all namespaces in wide format
kubectl get pods -o wide --all-namespaces
-
List all pods in json (or yaml) format
kubectl get pods -o json
-
Describe resource details (node, pod, svc)
kubectl describe nodes my-node
-
List services sorted by name
kubectl get services --sort-by=.metadata.name
-
List pods sorted by restart count
kubectl get pods --sort-by='.status.containerStatuses[0].restartCount'
-
Rolling update pods for frontend-v1
kubectl rolling-update frontend-v1 -f frontend-v2.json
-
Scale a replicaset named 'foo' to 3
kubectl scale --replicas=3 rs/foo
-
Scale a resource specified in "foo.yaml" to 3
kubectl scale --replicas=3 -f foo.yaml
-
Execute a command in every pod / replica
for i in 0 1; do kubectl exec foo-$i -- sh -c 'echo $(hostname) > /usr/share/nginx/html/index.html'; done
-
Deploy Heapster from Github repository https://github.com/kubernetes/heapster
kubectl create -f deploy/kube-config/standalone/
-
Show metrics for nodes
kubectl top node
kubectl top node my-node-1
-
Show metrics for pods
kubectl top pod
kubectl top pod my-pod-1
-
Show metrics for a given pod and its containers
kubectl top pod pod_name --containers
-
Dump pod logs (stdout)
kubectl logs pod_name
-
Stream pod container logs (stdout, multi-container case)
kubectl logs -f pod_name -c my-container