当前位置: 首页 > article >正文

2024.9.12(k8s环境搭建2)

一、接9.11
19、部署calico的pod
4. 查看容器和节点状态

异常处理:

出现Init:0/3,查看node节点 /var/log/messages是否有除网络异常之外的报错信息

三台机器执行:(更新版本)

yum list kernel

yum update kernel

reboot

三台机器该目录下要有以下文件

reboot

kubectl get po -A 查看没有pending状态就等待

[root@k8s-master ~]# kubectl get node

NAME         STATUS   ROLES           AGE   VERSION
k8s-master   Ready    control-plane   18h   v1.28.2
k8s-node1    Ready    <none>          18h   v1.28.2
k8s-node2    Ready    <none>          18h   v1.28.2

[root@k8s-master ~]# kubectl run nginx --image=nginx:latest     //添加一个新的pod
pod/nginx created

[root@k8s-master ~]# kubectl run nginx0 --image=nginx
[root@k8s-master ~]# kubectl get po -Aowide | grep nginx 

default       nginx                                      1/1     Running   0             47m   172.16.169.130   k8s-node2    <none>           <none>
default       nginx1                                     1/1     Running   0             38m   172.16.169.129   k8s-node2    <none>           <none>

[root@k8s-master ~]# kubectl logs nginx   //查看日志

[root@k8s-master ~]# curl 172.16.169.130

[root@k8s-master ~]# kubectl delete pod nginx
[root@k8s-master ~]# kubectl delete pod nginx1

20、 资源监控Metrics 部署
1. 复制证书到所有节点

[root@k8s-master ~]# scp /etc/kubernetes/pki/front-proxy-ca.crt k8s-node1:/etc/kubernetes/pki/front-proxy-ca.crt 
[root@k8s-master ~]# scp /etc/kubernetes/pki/front-proxy-ca.crt k8s-node2:/etc/kubernetes/pki/front-proxy-ca.crt 

2. 上传components.yaml文件

[root@k8s-master ~]# mkdir pods
[root@k8s-master ~]# mv components.yaml pods/
[root@k8s-master ~]# cd pods/
[root@k8s-master pods]# ls
components.yaml

3. 根据yaml文件创建pod

[root@k8s-master pods]# kubectl create -f components.yaml

4. 查看pod列表状态

[root@k8s-master pods]# kubectl get pods -Aowide | grep metrics

kube-system   metrics-server-79776b6d54-rlw2j            1/1     Running   0             5m30s   172.16.36.65     k8s-node1    <none>           <none>
5. 查看节点资源监控

[root@k8s-master pods]# kubectl top nodes

NAME         CPU(cores)   CPU%   MEMORY(bytes)   MEMORY%   
k8s-master   143m         7%     1103Mi          64%       
k8s-node1    41m          2%     819Mi           47%       
k8s-node2    45m          2%     858Mi           49%     

[root@k8s-master pods]# kubectl top pods -n kube-system   //查看kube-system命名空间的所有节点

NAME                                       CPU(cores)   MEMORY(bytes)   
calico-kube-controllers-6d48795585-dnwc4   2m           31Mi            
calico-node-4dfpr                          22m          124Mi           
calico-node-64rzl                          24m          103Mi           
calico-node-t8l7f                          22m          92Mi            
coredns-6554b8b87f-4xzkp                   1m           16Mi            
coredns-6554b8b87f-ws7pj                   1m           28Mi            
etcd-k8s-master                            17m          65Mi            
kube-apiserver-k8s-master                  51m          315Mi           
kube-controller-manager-k8s-master         14m          86Mi            
kube-proxy-hgn9q                           1m           33Mi            
kube-proxy-tshb8                           1m           26Mi            
kube-proxy-ww7k4                           1m           36Mi            
kube-scheduler-k8s-master                  3m           43Mi            
metrics-server-79776b6d54-rlw2j            3m           17Mi            
21、Dashboard部署
1. 建⽴dashboard的pod资源

[root@k8s-master ~]# cd k8s-ha-install/
[root@k8s-master k8s-ha-install]# ls


[root@k8s-master k8s-ha-install]# cd dashboard/
[root@k8s-master dashboard]# ls
dashboard-user.yaml  dashboard.yaml

[root@k8s-master dashboard]# kubectl create -f .   //使用当前目录

[root@k8s-master dashboard]# kubectl get po -A| grep dashboard

2. 设置svc模式

[root@k8s-master dashboard]# kubectl edit svc kubernetes-dashboard -n kubernetes-dashboard

[root@k8s-master dashboard]# kubectl get svc kubernetes-dashboard -n kubernetes-dashboard  //获取端口

NAME                   TYPE       CLUSTER-IP     EXTERNAL-IP   PORT(S)         AGE
kubernetes-dashboard   NodePort   10.96.22.191   <none>        443:31282/TCP   8m48s
3. 获得token 

[root@k8s-master dashboard]# kubectl create token admin-user -n kube-system

eyJhbGciOiJSUzI1NiIsImtpZCI6IlhPdHNYNThidExFTHNMNmR4QkRuMGd1TWhqd3VYaW9rc2lHN3o1Y2RMdDQifQ.eyJhdWQiOlsiaHR0cHM6Ly9rdWJlcm5ldGVzLmRlZmF1bHQuc3ZjLmNsdXN0ZXIubG9jYWwiXSwiZXhwIjoxNzI2MTE1NTA4LCJpYXQiOjE3MjYxMTE5MDgsImlzcyI6Imh0dHBzOi8va3ViZXJuZXRlcy5kZWZhdWx0LnN2Yy5jbHVzdGVyLmxvY2FsIiwia3ViZXJuZXRlcy5pbyI6eyJuYW1lc3BhY2UiOiJrdWJlLXN5c3RlbSIsInNlcnZpY2VhY2NvdW50Ijp7Im5hbWUiOiJhZG1pbi11c2VyIiwidWlkIjoiYjRkZDAzZDMtNTk3Yy00YTEwLTg5MTUtMGJmYzJiOTBiODA1In19LCJuYmYiOjE3MjYxMTE5MDgsInN1YiI6InN5c3RlbTpzZXJ2aWNlYWNjb3VudDprdWJlLXN5c3RlbTphZG1pbi11c2VyIn0.cvypVYVBNb8CkvXZv1lZ8CXY7lIbzsvyFXK7ovke5uWpiBm8_3xNBwcxFUEA9nk2MuA36Ru2U9z6Qs2TJb06mPK308wu5GQIXAai3i5ABw5i5nkhDuKIoJpcyvnCALKPDDIg6oIp_BjnGzo8aTDiH6g53lGUKZHDBwfFehkVNucR2BvRny1yeBXWXpiyM4SHvyvCa0INtlDCSv4jkk8-ag_G8VRtxEE1LqO1I39dV8HUhBmC7_gKItrMaVmsGa3btkTuynGOqxHSP_DtHjVnQH8GiSyszqDceBVIqeWsULTZFUjBoR51Ef76Uxv2JqnYvgYOatbGU0bvu9k_BV0vvQ
22、设置proxy的模式为ipvs
1. 编辑pod 

[root@k8s-master ~]# kubectl edit cm kube-proxy -n kube-system 

2. 更新 Kube-Proxy 的 Pod

 [root@k8s-master ~]# kubectl patch daemonset kube-proxy -p "{\"spec\":{\"template\":{\"metadata\": {\"annotations\":{\"date\":\"`date +'%s'`\"}}}}}" -n kube-system
daemonset.apps/kube-proxy patched

3. 访问测试

[root@k8s-master ~]# curl 127.0.0.1:10249/proxyMode

ipvs

23、查看service pod 宿主机的网段

[root@k8s-master ~]# kubectl get svc
NAME         TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
kubernetes   ClusterIP   10.96.0.1    <none>        443/TCP   23h

[root@k8s-master ~]# kubectl get pods -Aowide

24、验证是否可正常创建参数 

[root@k8s-master ~]# kubectl create deploy cluster-test1 --image=registry.cn-beijing.aliyuncs.com/dotbalo/debug-tools -- sleep 3600

[root@k8s-master ~]# kubectl get po
[root@k8s-master ~]# kubectl get po -owidew

25、Pod 必须能够解析 Service
1. nslookup kubernetes

[root@k8s-master ~]# kubectl exec -it cluster-test1-54575cf56c-65tv4 -- bash
(07:39 cluster-test1-54575cf56c-65tv4:/) nslookup kubernetes
Server:        10.96.0.10
Address:    10.96.0.10#53

Name:    kubernetes.default.svc.cluster.local
Address: 10.96.0.1

2. nslookup kube-dns.kube-system

(07:39 cluster-test1-54575cf56c-65tv4:/) nslookup kube-dns.kube-system
Server:        10.96.0.10
Address:    10.96.0.10#53

Name:    kube-dns.kube-system.svc.cluster.local
Address: 10.96.0.10

可以解析到server的第⼗个ip,说明可以解析到kube-dns,说 明跨namespace也可解析

26、 确认各 Pod 之间是否可正常通信

[root@k8s-master ~]# kubectl exec -it cluster-test1-54575cf56c-65tv4 -- bash
(07:46 cluster-test1-54575cf56c-65tv4:/) ping 172.16.235.200 -c 3
PING 172.16.235.200 (172.16.235.200) 56(84) bytes of data.
64 bytes from 172.16.235.200: icmp_seq=1 ttl=62 time=0.553 ms
64 bytes from 172.16.235.200: icmp_seq=2 ttl=62 time=0.675 ms
64 bytes from 172.16.235.200: icmp_seq=3 ttl=62 time=0.631 ms

--- 172.16.235.200 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2002ms
rtt min/avg/max/mdev = 0.553/0.619/0.675/0.058 ms

二、 kubernetes常用命令

1、kubernetes自动补齐

[root@k8s-master ~]# yum -y install bash-completion

[root@k8s-master ~]# source <(kubectl completion bash)   //临时开启自动补齐功能
[root@k8s-master ~]# echo "source <(kubectl completion bash)" >> ~/.bashrc   //永久开启

2、基础命令
1. 创建

[root@k8s-master ~]# kubectl create namespace pes
namespace/pes created
[root@k8s-master ~]# kubectl get namespace

NAME                   STATUS   AGE
default                Active   24h
kube-node-lease        Active   24h
kube-public            Active   24h
kube-system            Active   24h
kubernetes-dashboard   Active   4h41m
pes                    Active   38s
2. 删除 
NAMESPACE              NAME                                         READY   STATUS             RESTARTS      AGE
default                cluster-test1-54575cf56c-65tv4               1/1     Running            0             24m
default                clustertest-58dbff6c48-xbpvj                 0/1     ErrImagePull       0             38m

[root@k8s-master ~]# kubectl delete deployment clustertest   //删除

3、编写yaml文件 

[root@k8s-master ~]# vim pods/abc.yaml

apiVersion: v1
kind: Pod
metadata:
        name: busybox-sleep
spec:
        containers:
        - name: busybox
          image: busybox:1.28
          args:
          - sleep
          - "1000"
4. kubectl create

[root@k8s-master pods]# kubectl create -f abc.yaml

[root@k8s-master pods]# kubectl get po -A | grep bus
default                busybox-sleep                                0/1     ImagePullBackOff   0               11m
[root@k8s-master pods]# kubectl delete pod busybox-sleep
pod "busybox-sleep" deleted
[root@k8s-master pods]# kubectl get po -A | grep bus


http://www.kler.cn/a/306555.html

相关文章:

  • 华为云前台用户可挂载数据盘和系统盘是怎么做到的?
  • 微服务各组件整合
  • AI大模型开发架构设计(18)——基于大模型构建企业知识库案例实战
  • 论文解析:边缘计算网络中资源共享的分布式协议(2区)
  • 力扣104 : 二叉树最大深度
  • 假期增设:福祉与负担并存,寻求生活经济平衡之道
  • WebSocket vs. Server-Sent Events:选择最适合你的实时数据流技术
  • VUE3中ref与reactive
  • Sentinel 安装
  • BSV区块链上的覆盖网络服务现已开放公测
  • 常回家看看之house_of_cat
  • 基于单片机的超声波液位检测系统(论文+源码)
  • STM32 HAL freertos零基础(二)-通过STM32CubeMX配置Freertos后在程序中进行任务创建,便于任务管理与识别。
  • 微服务保护之熔断降级
  • 【前端】ref引用的作用
  • 2----手机维修工具 集合解锁 修复参数 刷机支持高通 MTK 展讯等芯片 支持一些PDA设备
  • 【机器学习】--- 生成对抗网络 (GANs)
  • Linux-Swap分区使用与扩容
  • Java集合接口List
  • C Primer Plus 第5章习题
  • 【从问题中去学习k8s】k8s中的常见面试题(夯实理论基础)(三十一)
  • 如何进行IP清洗
  • 嵌入式开发必懂入门知识:认识嵌入式元件
  • Linux设备驱动开发:从基础理论到实战经验的全面解析
  • YoloV10改进策略:Block改进|PromptIR(NIPS‘2023)|轻量高效,即插即用|(适用于分类、分割、检测等多种场景)
  • c++206 友元类