工作上用到 Microk8s,因架设在 Hyper-V 上,当电脑重新开机后 Hyper-V IP会浮动,导致 microk8s 指令无法正常运作,因此想到了使用固定IP来解决这个问题。
在 Windows 10 先安装好以下工具:
MicroK8sMultipass使用 Microk8s 架设 Kubernetes
安装Kubernetes
microk8s install
执行完后
Launched: microk8s-vm2022-01-19T15:40:30+08:00 INFO Waiting for automatic snapd restart...microk8s (1.22/stable) v1.22.5 from Canonical✓ installedmicrok8s-integrator-windows 0.1 from Canonical✓ installedMicroK8s is up and running. See the available commands with `microk8s --help`.
会在 Hyper-V 管理员看到 microk8s-vm 的虚拟机
查看 Microk8s 状态
microk8s status
microk8s is runninghigh-availability: no datastore master nodes: 127.0.0.1:19001 datastore standby nodes: noneaddons: enabled: ha-cluster # Configure high availability on the current node disabled: ambassador # Ambassador API Gateway and Ingress cilium # SDN, fast with full network policy dashboard # The Kubernetes dashboard dns # CoreDNS fluentd # Elasticsearch-Fluentd-Kibana logging and monitoring gpu # Automatic enablement of Nvidia CUDA helm # Helm 2 - the package manager for Kubernetes helm3 # Helm 3 - Kubernetes package manager host-access # Allow Pods connecting to Host services smoothly ingress # Ingress controller for external access istio # Core Istio service mesh services jaeger # Kubernetes Jaeger operator with its simple config kata # Kata Containers is a secure runtime with lightweight VMS keda # Kubernetes-based Event Driven Autoscaling knative # The Knative framework on Kubernetes. kubeflow # Kubeflow for easy ML deployments linkerd # Linkerd is a service mesh for Kubernetes and other frameworks metallb # Loadbalancer for your Kubernetes cluster metrics-server # K8s Metrics Server for API access to service metrics multus # Multus CNI enables attaching multiple network interfaces to pods openebs # OpenEBS is the open-source storage solution for Kubernetes openfaas # openfaas serverless framework portainer # Portainer UI for your Kubernetes cluster prometheus # Prometheus operator for monitoring and logging rbac # Role-Based Access Control for authorisation registry # Private image registry exposed on localhost:32000 storage # Storage class; allocates storage from host directory traefik # traefik Ingress controller for external access
虚拟交换器
建立虚拟交换器
填入名称 LANBridge
设定交换器
microk8s-vm 设定
停止 Microk8s
microk8s stop
设定 microk8s-vm 虚拟机网路介面卡
启动 Microk8s
microk8s start
查看 microk8s-vm 讯息
multipass info microk8s-vm
Name: microk8s-vmState: RunningIPv4: 172.21.68.80 10.1.254.64Release: Ubuntu 18.04.6 LTSImage hash: 7bd21b98e344 (Ubuntu 18.04 LTS)Load: 0.69 0.53 0.37Disk usage: 2.3G out of 48.3GMemory usage: 1.3G out of 3.9GMounts: --
透过 multipass 编辑 microk8s-vm 网路设定
multipass exec microk8s-vm -- sudo vi /etc/netplan/50-cloud-init.yaml
Vi 文字编辑器
按 A 或 I 键 可进入输入模式按 ESC 结束输入模式命令列模式输入 :wq 存档离开原有设定
network: ethernets: eth0: dhcp4: true match: macaddress: 52:54:00:5e:ec:bd set-name: eth0 version: 2
修改后设定
network: ethernets: eth0: dhcp4: true match: macaddress: 52:54:00:5e:ec:bd set-name: eth0 eth1: addresses: [192.168.1.101/24] version: 2
配置网路设定
multipass exec microk8s-vm -- sudo netplan apply
查看 microk8s-vm 讯息
multipass info microk8s-vm
Name: microk8s-vmState: RunningIPv4: 172.21.68.80 192.168.1.101 10.1.254.64Release: Ubuntu 18.04.6 LTSImage hash: 7bd21b98e344 (Ubuntu 18.04 LTS)Load: 0.78 0.59 0.41Disk usage: 2.3G out of 48.3GMemory usage: 1.3G out of 3.9GMounts: --
确认可以连到该主机
ping 192.168.1.101
Pinging 192.168.1.101 with 32 bytes of data:Reply from 192.168.1.101: bytes=32 time<1ms TTL=64Reply from 192.168.1.101: bytes=32 time<1ms TTL=64Reply from 192.168.1.101: bytes=32 time<1ms TTL=64Reply from 192.168.1.101: bytes=32 time<1ms TTL=64Ping statistics for 192.168.1.101: Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),Approximate round trip times in milli-seconds: Minimum = 0ms, Maximum = 0ms, Average = 0ms
更改 microk8s 主机IP
修改为 192.168.1.101
重新开机后输入指令,可以正常显示讯息就成功了
microk8s status
参考文章
使用 MicroK8s 架设 Kubernetes 丛集的完整过程解析