microk8s使用

news/2024/12/21 8:57:54/

microk8s使用

在使用microk8s时,可以设置一些别名,使用起来保持与k8s习惯一样,具体如下

sudo snap alias microk8s.kubectl kubectl
sudo snap alias microk8s.ctr ctr
sudo snap alias microk8s.helm helm
sudo snap alias microk8s.helm3 helm3

部署microk8s后,排查集群状态

microk8s status
microk8s.inspect

docker-registry搭建私有镜像仓库

docker pull registry:2
docker create volume registry_data
mkdir  /opt/data/auth
docker run  --entrypoint htpasswd registry:2 -Bbn  admin  Harbor@dmin.mec > auth/htpasswd
docker run -d -p 5000:5000 --restart=always --name registry \-v registry_data:/var/lib/registry \-v /opt/data/auth:/auth \-e "REGISTRY_AUTH=htpasswd" \-e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" \-e  REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd \registry:2
docker login -u username -p userpasswd 192.168.1.33:5000    

保存镜像

docker save docker.io/calico/cni:v3.25.1 docker.io/calico/kube-controllers:v3.25.1 docker.io/calico/node:v3.25.1 docker.io/cdkbot/hostpath-provisioner:1.5.0 docker.io/coredns/coredns:1.10.1 docker.io/library/busybox:1.28.4 registry.k8s.io/ingress-nginx/controller:v1.8.0 registry.k8s.io/metrics-server/metrics-server:v0.6.3 registry.k8s.io/pause:3.7 -o microk8s.tar

导入镜像

microk8s ctr i import microk8s.tar

配置集群与访问

microk8s config > ~/.kube/config
kubectl get node -o wide
kubectl get pod -A

启用插件host-path和ingress-controller,metrics-server.

microk8s status
microk8s enable hostpath-storage
microk8s enable ingress
microk8s enable metrics-server

验证

kubectl get pod -A
microk8s status

资源占用量

root@xww-nuc8i5beh:/media/xww/sda1/server/microk8s# kubectl describe node
Name:               xww-nuc8i5beh
Roles:              <none>
Labels:             beta.kubernetes.io/arch=amd64beta.kubernetes.io/os=linuxkubernetes.io/arch=amd64kubernetes.io/hostname=xww-nuc8i5behkubernetes.io/os=linuxmicrok8s.io/cluster=truenode.kubernetes.io/microk8s-controlplane=microk8s-controlplane
Annotations:        node.alpha.kubernetes.io/ttl: 0projectcalico.org/IPv4Address: 192.168.10.102/24projectcalico.org/IPv4VXLANTunnelAddr: 10.1.181.128volumes.kubernetes.io/controller-managed-attach-detach: true
CreationTimestamp:  Fri, 12 Jan 2024 20:24:04 +0800
Taints:             <none>
Unschedulable:      false
Lease:HolderIdentity:  xww-nuc8i5behAcquireTime:     <unset>RenewTime:       Sat, 13 Jan 2024 11:12:38 +0800
Conditions:Type                 Status  LastHeartbeatTime                 LastTransitionTime                Reason                       Message----                 ------  -----------------                 ------------------                ------                       -------NetworkUnavailable   False   Sat, 13 Jan 2024 11:01:36 +0800   Sat, 13 Jan 2024 11:01:36 +0800   CalicoIsUp                   Calico is running on this nodeMemoryPressure       False   Sat, 13 Jan 2024 11:09:49 +0800   Fri, 12 Jan 2024 20:24:04 +0800   KubeletHasSufficientMemory   kubelet has sufficient memory availableDiskPressure         False   Sat, 13 Jan 2024 11:09:49 +0800   Fri, 12 Jan 2024 20:24:04 +0800   KubeletHasNoDiskPressure     kubelet has no disk pressurePIDPressure          False   Sat, 13 Jan 2024 11:09:49 +0800   Fri, 12 Jan 2024 20:24:04 +0800   KubeletHasSufficientPID      kubelet has sufficient PID availableReady                True    Sat, 13 Jan 2024 11:09:49 +0800   Sat, 13 Jan 2024 11:01:40 +0800   KubeletReady                 kubelet is posting ready status. AppArmor enabled
Addresses:InternalIP:  192.168.10.102Hostname:    xww-nuc8i5beh
Capacity:cpu:                8ephemeral-storage:  245084444Kihugepages-1Gi:      0hugepages-2Mi:      0memory:             32867920Kipods:               110
Allocatable:cpu:                8ephemeral-storage:  244035868Kihugepages-1Gi:      0hugepages-2Mi:      0memory:             32765520Kipods:               110
System Info:Machine ID:                 105c044a9dba42f5a4740ef13b5692ebSystem UUID:                B17F28E3-2822-F3FD-A1F3-94C691A75966Boot ID:                    6bac866c-d336-4606-9c47-6b01f110baefKernel Version:             4.15.0-109-genericOS Image:                   Ubuntu 18.04.4 LTSOperating System:           linuxArchitecture:               amd64Container Runtime Version:  containerd://1.6.15Kubelet Version:            v1.28.3Kube-Proxy Version:         v1.28.3
Non-terminated Pods:          (6 in total)Namespace                   Name                                       CPU Requests  CPU Limits  Memory Requests  Memory Limits  AGE---------                   ----                                       ------------  ----------  ---------------  -------------  ---kube-system                 calico-node-dp5tr                          250m (3%)     0 (0%)      0 (0%)           0 (0%)         14hkube-system                 calico-kube-controllers-77bd7c5b-fph2n     0 (0%)        0 (0%)      0 (0%)           0 (0%)         14hkube-system                 coredns-864597b5fd-n5pzq                   100m (1%)     0 (0%)      70Mi (0%)        170Mi (0%)     14hingress                     nginx-ingress-microk8s-controller-z5plk    0 (0%)        0 (0%)      0 (0%)           0 (0%)         3m36skube-system                 hostpath-provisioner-7df77bc496-q4zp6      0 (0%)        0 (0%)      0 (0%)           0 (0%)         3m36skube-system                 metrics-server-848968bdcd-k5w78            100m (1%)     0 (0%)      200Mi (0%)       0 (0%)         3m35s
Allocated resources:(Total limits may be over 100 percent, i.e., overcommitted.)Resource           Requests    Limits--------           --------    ------cpu                450m (5%)   0 (0%)memory             270Mi (0%)  170Mi (0%)ephemeral-storage  0 (0%)      0 (0%)hugepages-1Gi      0 (0%)      0 (0%)hugepages-2Mi      0 (0%)      0 (0%)
Events:              <none>

运行nginx进行测试

apiVersion: v1 #类型为Namespace
kind: Namespace  #类型为Namespace
metadata:name: ns-test  #命名空间名称labels:name: label-test  #pod标签
---
apiVersion: apps/v1
kind: Deployment
metadata:namespace: ns-testname: nginx-deployment
spec:selector:matchLabels:app: nginxreplicas: 2template:metadata:labels:app: nginxspec:containers:- name: nginximage: nginx:alpineports:- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:namespace: ns-testname: nginx-service
spec:selector:app: nginxtype: NodePortports:- protocol: TCPport: 80targetPort: 80nodePort: 30080

部署和验证

kubectl apply -f nginx.yaml
curl http://192.168.10.102:30080

部署有状态服务

# cat pvc.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:name: mypvc1namespace: ns-test
spec:accessModes:- ReadWriteOnceresources:requests:storage: 1GistorageClassName: microk8s-hostpath

有状态的nginx服务

# cat nginx.yaml
apiVersion: v1 #类型为Namespace
kind: Namespace  #类型为Namespace
metadata:name: ns-test  #命名空间名称labels:name: label-test  #pod标签
---
apiVersion: apps/v1
kind: Deployment
metadata:namespace: ns-testname: nginx-deployment
spec:selector:matchLabels:app: nginxreplicas: 2template:metadata:labels:app: nginxspec:containers:- name: nginximage: nginx:alpineports:- containerPort: 80volumeMounts:- mountPath: "/mydata"name: mydatavolumes:- name: mydatapersistentVolumeClaim:claimName: mypvc1
---
apiVersion: v1
kind: Service
metadata:namespace: ns-testname: nginx-service
spec:selector:app: nginxtype: NodePortports:- protocol: TCPport: 80targetPort: 80nodePort: 30080

验证

kubectl apply -f pvc.yaml
kubectl apply -f nginx.yaml
kubectl get pvc -A
kubectl get pod -A

http://www.ppmy.cn/news/1556882.html

相关文章

DFS入门

目录 概念应用场景基本模型例题 概念 这是一种用于遍历或搜索图&#xff08;包括树&#xff0c;树是一种特殊的图&#xff09;的算法。它从起始顶点开始&#xff0c;沿着一条路径尽可能深地探索下去&#xff0c;直到无法继续&#xff0c;然后回溯到前一步&#xff0c;继续探索其…

11篇--图像边缘检测

图像梯度 要学习图像边缘检测&#xff0c;要先了解图像梯度的概念&#xff0c;我们正是通过梯度值来区分边缘像素点的 处于边缘附近的像素点与周围像素点的差距很大&#xff08;不然不会有边缘呈现&#xff09;&#xff0c;所以给边缘附近的的梯度之变化很快&#xff0c;通过…

git pull 和 git pull --rebase 区别

git pull 和 git pull --rebase 的主要区别在于如何合并远程分支的更新到当前分支。具体来说&#xff1a; 1. git pull 默认情况下&#xff0c;git pull 相当于执行 git fetch git merge。 它会将远程分支的最新提交拉取到本地&#xff0c;然后将这些提交通过**合并&#xff…

EyeSoothe荣登中国区“健康健美”类第32名! ✨

眼睛疲劳、视力变化、色盲检测、虚拟眼镜试戴……这些问题&#xff0c;EyeSoothe都能帮你解决&#xff01;作为一款全能眼健康应用&#xff0c;EyeSoothe集成了多个强大功能&#xff0c;旨在帮助你更好地保护视力&#xff0c;缓解眼部疲劳&#xff0c;随时关注眼健康。&#x1…

音频接口:PDM TDM128 TDM256

一、 PDM接口 在麦克风&#xff08;Mic&#xff09;接口中&#xff0c;PDM&#xff08;Pulse Density Modulation&#xff0c;脉冲密度调制&#xff09;和I2S&#xff08;Inter-IC Sound&#xff0c;集成电路内置音频总线&#xff09;是两种常见的数字输出接口。 1、工作原理…

预览和下载 (pc和微信小程序)

1.微信小程序 预览pdf 或者 图片等 //utils.js 文件//通过接口返回文件链接 打开文档 export default function previewFile({ downLinkUrl, tempFilePath }) {let url "https://" downLinkUrl.replace("http://", "").replace("https:…

apache应用(客户机地址限制、用户授权限制、日志分割、AWStats日志分析)

目录 一、 客户机地址限制 二、 用户授权限制 三、 日志分割 使用rotatelogs分割工具 使用第三方工具cronolog 四、 AWStats日志分析 具体的apache软件安装可以阅读我之前的文章apache安装https://blog.csdn.net/m0_68472908/article/details/139348739?spm1001.2014.300…

matlab的一些时间函数【转】

看到就记下来&#xff0c;感觉挺好玩的。 原文&#xff1a;MATLAB-一些时间函数 - 简书 (jianshu.com) 注明出处了&#xff0c;原文是公开的&#xff0c;应该不算侵权。若有侵权请告知删除谢谢。