如何藉助 AI 搭建 Kubernetes 環境
Yes.. It Is Possible to Assemble Kubernetes Environment with AI
作者藉助 AI 規劃並搭建 Kubernetes 環境,並分享安裝過程中遇到的問題。重新安裝後需輪替節點間的握手憑證,並確認 Kubernetes 與作業系統相容;首次安裝時亦應清理未使用的 Pod、查看 Pod 日誌以排查錯誤。
*With the help of AI
Intro
We all know the broad possibilities of what AI can do, especially in development. They can code, can execute plans, can find bugs, etc. Agentic AI can even do tasks on your PC, then send notifications to you about what the results and review for approval.
But what about some complex architecture? Like kubernetes for example. Do AI can build it?
Yes of course, I built it. They made the plan, and then I execute it.
About Kubernetes
Kubernetes is not a framework. It is a architecture concept.
Imagine you want to hosts your application online, what you do? Simple, just access a server's SSH, install libraries and perquisites, do a git clone, then just run the app installation, ie. npm install and npm run dev. Then voila, it is running on localhost:3000.
But what if the app crash? On some occasion they have an unhandled exceptions? Kubernetes allows you to restart the app automatically.
What if you wanted to allow more bandwidth and more access to your app? Kubernetes allows you to scale the app to several app instance to provide the bandwitdh needed.
What if the network suddenly spiked during peak hour? Kubernetes allows you to automatically scale the app instances up and down accordingly to the network load.
What if the server suddenly down and all the app instances are gone? Kubernetes allows you to manage several server nodes with same app instances to keep your app online.
What if only one server loaded with network, and the other server are idle. Kubernetes allows you to loadbalance the network automatically.
So what is kubernetes? RKE2, K3s, Kubeadm, OpenShift, MicroK8s they all are kubernetes. You can pick one. But they offer the same feature which I explained above.
Prequisites
Well, for starters, the real kubernetes are not cheap. They needed servers, or the kubernetes call it Nodes. You can have only one Node for Kubernetes. But it is not production ready and do not have High-Availability feature from kubernetes.
- Server Spec | The specification for the servers may vary through all the requirement for the application load and computation. But at least one linux server with 2 vCPU, 8 GB RAM, and 50GB Storage is enough for one node kubernetes launching a K3s.
- Network Availability | Well for kubernetes to work, all the Nodes need to be on the same network, so they can interact each other either with public IP Address or private IP Address
- Internet Access | Most of the tools used to install kubernetes, like
helmneeded internet access. So basically all type of server, except air-gapped servers, have internet access. - Container Basic Knowledge | Kubernetes works with containers. If you familiar with Docker, you should be able to catch up fast
- AI | This is main tools you need to install kubernetes
How To Assemble Kubernetes (The Missing Guide)
Now is the fun part. The copy-paste situation.
Mostly all the commands you can get from AI. I just wanted to share the missing part from the bugs and errors I found.
- Certificate | Certainly you don't need a SSL Certificate, but this is the handshake certificate generated by the kubernetes throughout all the nodes. If you failed to connect the nodes several times, uninstall and reinstalled the kubernetes because you missed some parts, you will fail again. Because the servers can't trust each other of the missing handshake certificate. You need to rotate the certificate each time you uninstalled kubernetes, and setup a new certificate for the new kubernetes setup.
- Pods Can't Start Up Correctly | Some kind of kubernetes like RKE2 or K3s only compatible with Ubuntu in my case, but some other kind of kubernetes might have compatibility with other OS as well. So you might find on internet of what kubernetes you install and with what OS it compatible with.
- Pods "Caches" | They install alot, like ALOT of Pods for first installation, and some of them might get stuck on your servers and eat up memory. Maybe not much, but it is best to clean all the unused pods.
- Always Check Pods Logs | This is your bread and butter for your first installation. Check the error logs on your Pod Logs and find the solution for the bugs to the AI.
Conclusions
Well, with the help of AI. Almost anything is possible without much of hard work. But we still need to take notes of small detail which is important to our apps, especially the missing details one. The faster we can find the source of the bugs, the faster the apps will run.
來源:DEV Community · dev.to