Dev in K8s Env

build a side-car pod for dev, in this way we can use all service power by k8s;
in one k8s env, pods expose their entrypoint(service) by Service;
it’s ok for one single port exposing by nodeport, but for cluster, e.g. kafka or redis cluster, it’s hard way, like the flow bellow:

it’s much more convenient to use one cluster service inner k8s network, and we use DNS but no directly ip( 192.168.1.1) to visit one service; k8s handle the DNS discovery automatically, but the DNS works only inner k8s network; to solve this problem, we can run one pod which built all dev tools we may need for development;

for easy access to the sidecar pod, I built one image base on 18.04.5 LTS which pre-install dev-tools, open-ssh for sure, the image size has 3G+ ^_^!

for dev pod; we can mount the common dir in pod to the real disk on node(system),
e.g.: in pod /data mounts to /home/$user, in this way, many users can share files, each one is isolated but by sharing the k8s network, the speed is fast.

by default, one DNS issue may occurs that one pod of namespace A has no access to another pod of namespace B, the sidecar-dev pod can’t use the service from other namespace, to solve this issue, we can just add the root DNS of the namespace we want at the field search in the file /etc/resolv.conf in the container of sidecar-dev pod, for example, I can’t visit the kafka service from my dev container until I add kafka.svc.cluster.local to the search field, check the image below:

最后是中文简化描述我所想要表达的内容
使用k8s 更容易搭建服务集群(k8s是就是自动化的docker,比手动docker run 效率高多了),但是集群在k8s大内网,一种解决方法是加一个pod,开发者可以在这个Pod里面开发调试:
k8s会自动生成集群服务的DNS地址,不同的namespace中,如果无法访问其它namespace的服务,需要在pod中的DNS本地文件/etc/resolv.conf中增加搜索根域名比如图中:

kafka-cp-kafka-headless属于kafka namepaces中的Pod服务域名,而kafka namepace的根DNS为kafka.svc.cluster.local, 要想在mysql namespace的pod中(非kafka namespace) 访问kafka-cp-kafka-headless 服务,得把kafka.svc.cluster.local 地址加入到search 域中,即/etc/resolv.conf文件中

2021-03-03