This is a part of the series of posts on Getting memcache up and running on Kubernetes which explained how to create your first cluster and Installing memcache with Kubernetes which installed some memcache instances on your cluster. I recommend that you save your commands in various scripts so you can repeat them or modify them later.
Exposing the memcache service
If you are just keeping the memcache instance private to your cluster you don’t need to bother with this. However, for demo purposes, I need to expose the memcache service outside of the Kubernetes cluster. That way, I can develop a small app to test from an external development environment such as cloud9.
Creating a loadbalancer
In the world of Kubernetes, a service is the way to communicate with the pods that are running instances of your app. We already have a memcache service, created by Helm, in the previous post. This service is accessible within the cluster just by referencing its name (which Kubernetes handily maintains from its DNS service), but it can’t be seen outside the cluster.
$ kubectl get service NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes ClusterIP 10.27.240.1 <none> 443/TCP 22h mycache-memcached ClusterIP None <none> 11211/TCP 21h
What we need to do now is expose that mycache-memcached service to the outside world. For that we need to attach a loadbalancer service.
$ kubectl expose service mycache-memcached --port=11211 --target-port=11211 --name=mc --type=LoadBalancer
After a little while, we’ll see this new Loadbalancer created with a public IP address assigned. It can take a few minutes to complete.
$ kubectl get service NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes ClusterIP 10.27.240.1 <none> 443/TCP 23h mc LoadBalancer 10.27.244.1 35.xxx.xxx.xxx 11211:30588/TCP 47s mycache-memcached ClusterIP None <none> 11211/TCP 22h
You can now access your memcache service on the given IP address and port number. I should remind you that this service is now public and accessible so be careful how you use it. I won’t bother with it for this demo, but if you are interested in how to use ssl with Kubernetes, see HTTPS ingress for Kubernetes service
Next step
Testing memcache from outside the cluster by creating a test apps for memcache on Kubernetes