This post is about supported Kubernetes API versions on your cluster and services port forwarding to your localhost which can be really useful when troubleshooting or testing apps running on Kubernetes. Check other Kubernetes tips articles on my blog by using this tag kube-tips.
Kubernetes API Versions
If you are familiar with Kubernetes resources config files you already saw the
apiVersion field at the beginning of each file. It can be confusing, because you will see a lot of different versions there like
apps/v1beta1, etc. Things are moving really fast in the Kubernetes world and even if someone wrote a config for something in the blog post three months ago, since then the version can be changed and maybe not applicable on your cluster today. So, how to know which versions to use? You just need to ask API server for that with a simple command:
⚡ kubectl api-versions admissionregistration.k8s.io/v1alpha1 apiextensions.k8s.io/v1beta1 apiregistration.k8s.io/v1beta1 apps/v1beta1 authentication.k8s.io/v1 authentication.k8s.io/v1beta1 authorization.k8s.io/v1 authorization.k8s.io/v1beta1 autoscaling/v1 autoscaling/v2alpha1 batch/v1 batch/v2alpha1 certificates.k8s.io/v1beta1 enterprises.upmc.com/v1 extensions/v1beta1 networking.k8s.io/v1 policy/v1beta1 rbac.authorization.k8s.io/v1alpha1 rbac.authorization.k8s.io/v1beta1 settings.k8s.io/v1alpha1 storage.k8s.io/v1 storage.k8s.io/v1beta1 v1
If you are new to Kubernetes read this book first Kubernetes in Action
Service Port Forwarding to localhost
When working with Kubernetes you will often find it difficult to access to your services. With docker only, you can just expose the port, but with Kubernetes this is not an option. Your services are somehow isolated. Of course, you can create a
NodePort service to expose it. But, maybe you just need to verify that the service is up and running, and you don't want to expose it all the time or to outside world. There is the simple solution to this issue and it is called a
port-forward. Basically, you just need to run one
kubectl command. For example, you want to access to your Elasticsearch Pod:
⚡ kubectl port-forward <POD_NAME> 9200 Forwarding from 127.0.0.1:9200 -> 9200
http://localhost:9200 in your web browser and voila!
If there’s something Kubernetes related you want to hear about, let me know in the comments, or tweet me at @alenkomljen.