এটি স্কেলওয়ে বেয়ার-মেটাল এআরএম এবং x86-64-এ কুবারনেটস সেট আপ করার জন্য ধাপে ধাপে নির্দেশিকা। আমি এই প্রকল্পে কাজ করার প্রধান কারণ হল যে আমি ARM-এ OpenFaaS এবং Weave Net-এর জন্য পরীক্ষার পরিবেশ তৈরিকে স্বয়ংক্রিয় করতে চেয়েছিলাম। আমি ইন্টিগ্রেশন পরীক্ষা চালানোর জন্য একটি সস্তা সমাধান খুঁজছিলাম এবং বেশ কয়েকটি ক্লাউড প্রদানকারীর চেষ্টা করার পরে আমি স্কেলওয়েতে বসতি স্থাপন করেছি। স্কেলওয়ে হল একটি ফ্রেঞ্চ ক্লাউড প্রদানকারী যা সাশ্রয়ী মূল্যে বেয়ার-মেটাল এআরএম এবং x86-64 সার্ভার সরবরাহ করে। কিউবিএডিএম সহ টেরাফর্ম স্কেলওয়ে প্রদানকারী ব্যবহার করে আপনি দশ মিনিটের মধ্যে একটি সম্পূর্ণ কার্যকরী কুবারনেটস ক্লাস্টার পেতে পারেন প্রাথমিক সেটআপ সংগ্রহস্থল ক্লোন করুন এবং নির্ভরতাগুলি ইনস্টল করুন: $ git ক্লোন httpsgithub.com/stefanprodan/k8s-scw-baremetal.git $ cd k8s-scw-baremetal $ terraform init মনে রাখবেন যে এই প্রকল্পটি চালানোর জন্য আপনার Terraform v0.10 বা তার থেকে নতুন প্রয়োজন হবে প্রকল্পটি চালানোর আগে আপনাকে Scaleway API-এর সাথে সংযোগ করার জন্য Terraform-এর জন্য একটি অ্যাক্সেস টোকেন তৈরি করতে হবে। টোকেন এবং আপনার অ্যাক্সেস কী ব্যবহার করে, দুটি পরিবেশের ভেরিয়েবল তৈরি করুন: $export SCALEWAY_ORGANIZATIONACCESS-KEY>"$export SCALEWAY_TOKENACCESS-TOKEN>"ব্যবহার একটি মাস্টার এবং দুটি নোড সহ একটি ARMv7 বেয়ার-মেটাল কুবারনেটস ক্লাস্টার তৈরি করুন: $ টেরাফর্ম ওয়ার্কস্পেস নতুন আর্ম $ টেরাফর্ম প্রয়োগ করুন \ -var অঞ্চল=par1 \ -var arch=arm \ -var server_type=C1 \ -var nodes=2 \ -var weave_passwd=ChangeMe \ -var k8s_version=stable-1.9 \ -var docker_version =17.03.0~ce-0~ubuntu-xenial এটি নিম্নলিখিত কাজ করবে: - প্রতিটি সার্ভারের জন্য পাবলিক আইপি সংরক্ষণ করে - উবুন্টু 16.04.1 LTS সহ তিনটি বেয়ার-মেটাল সার্ভারের ব্যবস্থা করে - SSH এর মাধ্যমে মাস্টার সার্ভারের সাথে সংযোগ করে এবং Docker CE এবং kubeadm armhf apt প্যাকেজ ইনস্টল করে - মাস্টার সার্ভারে kubeadm init চালায় এবং kubectl কনফিগার করে - আপনার স্থানীয় মেশিনে kubectl অ্যাডমিন কনফিগার ফাইল ডাউনলোড করে এবং ব্যক্তিগত আইপিকে সর্বজনীন একটি দিয়ে প্রতিস্থাপন করে - ওয়েভ নেট পাসওয়ার্ড দিয়ে একটি কুবারনেটস সিক্রেট তৈরি করে - এনক্রিপ্ট করা ওভারলে সহ ওয়েভ নেট ইনস্টল করে - ক্লাস্টার অ্যাড-অন ইনস্টল করে (কুবারনেটস ড্যাশবোর্ড, মেট্রিক্স সার্ভার এবং হিপস্টার) - সমান্তরালভাবে কর্মী নোডগুলি শুরু করে এবং Docker CE এবং kubeadm ইনস্টল করে - মাস্টার থেকে প্রাপ্ত kubeadm টোকেন ব্যবহার করে ক্লাস্টারে কর্মী নোডগুলিতে যোগদান করে নোডের সংখ্যা বাড়িয়ে স্কেল আপ করুন: $ টেরাফর্ম প্রযোজ্য -var নোড = 3 এর সাথে পুরো অবকাঠামো ভেঙে ফেলুন: terraform-force একটি মাস্টার এবং একটি নোড সহ একটি AMD64 বেয়ার-মেটাল কুবারনেটস ক্লাস্টার তৈরি করুন: $ টেরাফর্ম ওয়ার্কস্পেস নতুন amd64 $ terraform প্রযোজ্য \ -var region=par1 \ -var arch=x86_64 \ -var server_type=C2S \ -var nodes=1 \ -var weave_passwd=ChangeMe \ -var k8s_version=stable-1.9 \ -var docker_version =17.03.0~ce-0~ubuntu-xenial দূরবর্তী নিয়ন্ত্রণ টেরাফর্ম প্ল্যানটি প্রয়োগ করার পরে আপনি মাস্টার পাবলিক আইপি, kubeadmn জয়েন কমান্ড এবং বর্তমান ওয়ার্কস্পেস অ্যাডমিন কনফিগারেশনের মতো বেশ কয়েকটি আউটপুট ভেরিয়েবল দেখতে পাবেন চালানোর জন্য স্কেলওয়ে ক্লাস্টারের বিরুদ্ধে kubectl কমান্ড ব্যবহার করতে পারেন kubectl_config আউটপুট ভেরিয়েবল: হিপস্টার কাজ করে কিনা তা পরীক্ষা করুন: $ kubectl --kubeconfig টেরাফর্ম আউটপুট kubectl_config) শীর্ষ নোড NAME CPU(cores) CPU% MEMORY(বাইট) মেমরি% arm-master-1 655m 16% 873Mi 45% arm-node-1 147m 3% 618Mi%de22- 2 101m 2% 584Mi 30% দ্য kubectl কনফিগারেশন ফাইল ফরম্যাট .conf as in arm.conf or amd64.conf In order to access the dashboard you’ll need to find its cluster IP: $ kubectl --kubeconfig terraform output kubectl_config) \ -n kube-system get svc --selector=k8s-app=kubernetes-dashboard NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes-dashboard ClusterIP 10.107.37.220 80/TCP 6m Open a SSH tunnel: ssh -L 8888::80 [email protected] Now you can access the dashboard on your computer at httplocalhost:8888 Expose services outside the cluster Since we’re running on bare-metal and Scaleway doesn’t offer a load balancer, the easiest way to expose applications outside of Kubernetes is using a NodePort service Let’s deploy the podinfo app in the default namespace. Podinfo has a multi-arch Docker image and it will work on arm, arm64 or amd64 Create the podinfo nodeport service: $ kubectl --kubeconfig terraform output kubectl_config) \ apply -f httpsraw.githubusercontent.com/stefanprodan/k8s-podinfo/master/deploy/auto-scaling/podinfo-svc-nodeport.yaml service "podinfo-nodeport" created Create the podinfo deployment: $ kubectl --kubeconfig terraform output kubectl_config) \ apply -f httpsraw.githubusercontent.com/stefanprodan/k8s-podinfo/master/deploy/auto-scaling/podinfo-dep.yaml deployment "podinfo" created Inspect the podinfo service to obtain the port number: $ kubectl --kubeconfig terraform output kubectl_config) \ get svc --selector=app=podinfo NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE podinfo-nodeport NodePort 10.104.132.14 9898:31190/TCP 3m You can access podinfo at httpMASTER_PUBLIC_IP>:31190 or using curl: $ curl httpterraform output k8s_master_public_ip):31190 runtime: arch: arm max_procs: "4" num_cpu: "4" num_goroutine: "12" os: linux version: go1.9.2 labels: app: podinfo pod-template-hash: "1847780700" annotations: kubernetes.io/config.seen: 2018-01-08T00:39:45.580597397Z kubernetes.io/config.source: api environment: HOME: /root HOSTNAME: podinfo-5d8ccd4c44-zrczc KUBERNETES_PORT: tcp10.96.0.1:443 KUBERNETES_PORT_443_TCP: tcp10.96.0.1:443 KUBERNETES_PORT_443_TCP_ADDR: 10.96.0.1 KUBERNETES_PORT_443_TCP_PORT: "443" KUBERNETES_PORT_443_TCP_PROTO: tcp KUBERNETES_SERVICE_HOST: 10.96.0.1 KUBERNETES_SERVICE_PORT: "443" KUBERNETES_SERVICE_PORT_HTTPS: "443" PATH: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin externalIP: IPv4: 163.172.139.112 OpenFaaS You can deploy OpenFaaS on Kubernetes with Helm or by using the YAML files form the faas-netes repository Clone the faas-netes repo: git clone httpsgithub.com/openfaas/faas-netes cd faas-netes Deploy OpenFaaS for ARM: $ kubectl --kubeconfig terraform output kubectl_config) \ apply -f ./namespaces.ymlyaml_armhf Deploy OpenFaaS for AMD64: $ kubectl --kubeconfig terraform output kubectl_config) \ apply -f ./namespaces.ymlyaml You can access the OpenFaaS gateway at httpMASTER_PUBLIC_IP>:31112 Horizontal Pod Autoscaling Starting from Kubernetes 1.9 kube-controller-manager is configured by default with horizontal-pod-autoscaler-use-rest-clients In order to use HPA we need to install the metrics server to enable the new metrics API used by HPA v2 Both Heapster and the metrics server have been deployed from Terraform when the master node was provisioned The metric server collects resource usage data from each node using Kubelet Summary API. Check if the metrics server is running: $ kubectl --kubeconfig terraform output kubectl_config) \ get --raw "/apis/metrics.k8s.io/v1beta1/nodes" | jq { "kind": "NodeMetricsList", "apiVersion": "metrics.k8s.io/v1beta1", "metadata": { "selfLink": "/apis/metrics.k8s.io/v1beta1/nodes" }, "items": [ { "metadata": { "name": "arm-master-1", "selfLink": "/apis/metrics.k8s.io/v1beta1/nodes/arm-master-1", "creationTimestamp": "2018-01-08T15:17:09Z" }, "timestamp": "2018-01-08T15:17:00Z", "window": "1m0s", "usage": { "cpu": "384m", "memory": "935792Ki" } }, { "metadata": { "name": "arm-node-1", "selfLink": "/apis/metrics.k8s.io/v1beta1/nodes/arm-node-1", "creationTimestamp": "2018-01-08T15:17:09Z" }, "timestamp": "2018-01-08T15:17:00Z", "window": "1m0s", "usage": { "cpu": "130m", "memory": "649020Ki" } }, { "metadata": { "name": "arm-node-2", "selfLink": "/apis/metrics.k8s.io/v1beta1/nodes/arm-node-2", "creationTimestamp": "2018-01-08T15:17:09Z" }, "timestamp": "2018-01-08T15:17:00Z", "window": "1m0s", "usage": { "cpu": "120m", "memory": "614180Ki" } } ] } Let’s define a HPA that will maintain a minimum of two replicas and will scale up to ten if the CPU average is over 80% or if the memory goes over 200Mi apiVersion: autoscaling/v2beta1 kind: HorizontalPodAutoscaler metadata: name: podinfo spec: scaleTargetRef: apiVersion: apps/v1beta1 kind: Deployment name: podinfo minReplicas: 2 maxReplicas: 10 metrics: - type: Resource resource: name: cpu targetAverageUtilization: 80 - type: Resource resource: name: memory targetAverageValue: 200Mi Apply the podinfo HPA: $ kubectl --kubeconfig terraform output kubectl_config) \ apply -f httpsraw.githubusercontent.com/stefanprodan/k8s-podinfo/master/deploy/auto-scaling/podinfo-hpa.yaml horizontalpodautoscaler "podinfo" created After a couple of seconds the HPA controller will contact the metrics server and will fetch the CPU and memory usage: $ kubectl --kubeconfig terraform output kubectl_config) get hpa NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE podinfo Deployment/podinfo 2826240 / 200Mi, 15% / 80% 2 10 2 5m In order to increase the CPU usage we could run a load test with hey: #install hey go get -u github.com/rakyll/hey #do 10K requests rate limited at 20 QPS hey -n 10000 -q 10 -c 5 httpterraform output k8s_master_public_ip):31190 You can monitor the autoscaler events with: $ kubectl --kubeconfig terraform output kubectl_config) describe hpa Events: Type Reason Age From MessageNormal SuccessfulRescale 7m horizontal-pod-autoscaler New size: 4; reason: cpu resource utilization (percentage of request) above target Normal SuccessfulRescale 3m horizontal-pod-autoscaler New size: 8; reason: cpu resource utilization (percentage of request) above target After the load tests finishes the autoscaler will remove replicas until the deployment reaches the initial replica count: Events: Type Reason Age From MessageNormal SuccessfulRescale 20m horizontal-pod-autoscaler New size: 4; reason: cpu resource utilization (percentage of request) above target Normal SuccessfulRescale 16m horizontal-pod-autoscaler New size: 8; reason: cpu resource utilization (percentage of request) above target Normal SuccessfulRescale 12m horizontal-pod-autoscaler New size: 10; reason: cpu resource utilization (percentage of request) above target Normal SuccessfulRescale 6m horizontal-pod-autoscaler New size: 2; reason: All metrics below target Conclusions Thanks to kubeadm and Terraform, bootstrapping a Kubernetes cluster on bare-metal can be done with a single command and it takes just ten minutes to have a fully functional setup. If you have any suggestion on improving this guide please submit an issue or PR on GitHub at stefanprodan/k8s-scw-baremetal. Contributions are more than welcome!