Create a Minikube cluster
With minikube you can quickly create a local Kubernetes cluster. To get started, use the following flags:
--profilesets the cluster name todc1.--memorysets the cluster to use 4GB of memory.--kubernetes-versionspecifies the cluster kubernetes version tov1.22.0.
|
|
Deploy Consul
Create a values file
To customize your deployment, create a values.yaml file to customization your Consul deployment.
|
|
Install Consul in your cluster
|
|
|
|
Run the command kubectl get pods to verify the Consul resources were successfully created.
|
|
Configure your CLI to interact with Consul cluster
Retrieve the ACL bootstrap token from the respective Kubernetes secret and set it as an environment variable.
|
|
Set the Consul destination address. By default, Consul runs on port 8500 for http and 8501 for https.
|
|
Remove SSL verification checks to simplify communication to your Consul cluster.
|
|
View Consul services
Open a separate terminal window and expose the Consul server with kubectl port-forward using the consul-ui service name as the target.
|
|
In your original terminal, run the CLI command consul catalog services to return the list of services registered in Consul. Notice this returns only the consul service since it is the only running service in your Consul cluster.
|
|
Agents run in either server or client mode. Server agents store all state information, including service and node IP addresses, health checks, and configuration. Client agents are lightweight processes that make up the majority of the datacenter. They report service health status to the server agents. Clients must run on every pod where services are running.
Run the CLI command consul members to return the list of Consul agents in your environment.
|
|
Deploy services into your service mesh
Now that you have a running Consul service mesh, you can deploy services to it.
Deploy two demo services
Create a deployment definition, service, and service account for the counting service named counting.yaml.
|
|
Create a deployment definition, service, and service account for the dashboard service named dashboard.yaml.
|
|
Use kubectl to deploy the counting and dashboard services.
|
|
To verify the services were deployed, run kubectl get pods until you see both services are ready or refresh the Consul UI until you observe that the counting and dashboard services are running.
Test the demo application
Open a separate terminal window and expose the dashboard UI with kubectl port-forward using the dashboard service name as the target.
|
|
Open http://localhost:9002 in your browser. Notice that the service will display a message that the “Counting Service is Unreachable”, and the count will display as “-1”. This is expected behavior as dashboard cannot reach the counting backend since you have not defined any intentions yet.
Create intentions
To see how intentions affect communication between the services in your service mesh, you will create intentions following the “least-privilege” principle that allow communication between your services.
Create a file named intentions.yaml to define intentions that allow the dashboard service to communicate with the counting service.
|
|
Deploy the service intentions to allow the HashiCups services to interact with each other..
|
|
Confirm applied intentions
|
|
Check out the dashboard UI at http://localhost:9002. Refresh the page and notice that the application is now fully functional. It will display the dashboard UI with a number retrieved from the counting service using Consul service discovery and service mesh functionality.
Clean up
|
|
Next steps
- Get Started with Consul on Kubernetes
- Consul Docs
- Consul Kubernetes Deployment Guide
- Consul Kubernetes Security