k8s的配置

news2024/9/20 7:49:18

k8s的配置

拉取镜像,创建pod:从阿里云拉取

[root@k8s-master ~]# kubectl run nginx  --image=nginx:latest
[root@k8s-master ~]# kubectl get po -Aowide|grep nginx
default       nginx                                      0/1     ImagePullBackOff   0             4m48s   172.16.85.193    k8s-node01   <none>           <none>
[root@k8s-master ~]# kubectl logs nginx
Error from server (BadRequest): container "nginx" in pod "nginx" is waiting to start: trying and failing to pull image

[root@k8s-master ~]# kubectl run nginx0 --image=nginx
[root@k8s-master ~]# kubectl get po -Aowide|grep nginx
default       nginx                                      0/1     ImagePullBackOff   0             9m8s    172.16.85.193    k8s-node01   <none>           <none>
default       nginx0                                     1/1     Running            0             2m24s   172.16.85.194    k8s-node01   <none>           <none>
#删除nginx

[root@k8s-master ~]# kubectl delete pod nginx
pod "nginx" deleted
[root@k8s-master ~]# kubectl get po -Aowide|grep nginx
default       nginx0                                     1/1     Running   0             5m30s   172.16.85.194    k8s-node01   <none>           <none>

注意:nginx0部署在node01节点上,是由  kube-controller-manager-k8s-master 来确定的,它会根据那个节点空闲来分配

部署资源监控metries-server

--复制密钥文件到node01和node02节点

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

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

--根据yaml文件创建pod

[root@k8s-master ~]# ls
anaconda-ks.cfg  k8s-ha-install       new.yaml
components.yaml  kubeadm-config.yaml  token
[root@k8s-master ~]# mkdir pods
您在 /var/spool/mail/root 中有新邮件
[root@k8s-master ~]# mv components.yaml pods/
[root@k8s-master ~]# ls
anaconda-ks.cfg  k8s-ha-install  kubeadm-config.yaml  new.yaml  pods  token
[root@k8s-master ~]# cd pods/
[root@k8s-master pods]# ls
components.yaml

[root@k8s-master pods]# kubectl create -f components.yaml 
serviceaccount/metrics-server created

--查看pod列表状态
[root@k8s-master pods]# kubectl get po -A|grep metrics
kube-system   metrics-server-79776b6d54-5sgrk            1/1     Running   0             90s
--查看节点资源监控

看节点所在资源:

[root@k8s-master pods]# kubectl top nodes
NAME         CPU(cores)   CPU%   MEMORY(bytes)   MEMORY%   
k8s-master   119m         5%     1309Mi          33%       
k8s-node01   42m          2%     932Mi           50%       
k8s-node02   48m          2%     899Mi           48%      

看各个pod所在资源:

[root@k8s-master pods]# kubectl top pod -A

看某一pods所在资源:

[root@k8s-master pods]# kubectl top pods -n kube-system
NAME                                       CPU(cores)   MEMORY(bytes)   
calico-kube-controllers-6d48795585-7vjgk   2m           14Mi            
calico-node-qqds6                          18m          125Mi           
calico-node-rn2nb                          21m          132Mi           
calico-node-w5bnt                          22m          96Mi            
coredns-6554b8b87f-thzlw                   1m           14Mi            
coredns-6554b8b87f-zdhh9                   1m           14Mi            
etcd-k8s-master                            16m          79Mi            
kube-apiserver-k8s-master                  45m          309Mi           
kube-controller-manager-k8s-master         12m          51Mi            
kube-proxy-8jk8f                           1m           25Mi            
kube-proxy-dvfx4                           1m           31Mi            
kube-proxy-g226c                           1m           18Mi            
kube-scheduler-k8s-master                  3m           23Mi            
metrics-server-79776b6d54-5sgrk            3m           17Mi      

搭建dashboard

面板:dashboard

--安装dashboard

[root@k8s-master ~]# ls
anaconda-ks.cfg  k8s-ha-install  kubeadm-config.yaml  new.yaml  pods  token
[root@k8s-master ~]# cd k8s-ha-install/
[root@k8s-master k8s-ha-install]# ls
bootstrap  CoreDNS       dashboard               metrics-server  README.md
calico     csi-hostpath  kubeadm-metrics-server  pki             snapshotter
[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
kubernetes-dashboard   dashboard-metrics-scraper-7b554c884f-dvdpz   1/1     Running   0              2m22s
kubernetes-dashboard   kubernetes-dashboard-54b699784c-5dxxj        1/1     Running   0              2m22s
 

--设置svc模式

SVC对外提供一个接口

kubectl edit svc 服务名称 -n 命名空间

[root@k8s-master dashboard]# kubectl edit svc kubernetes-dashboard -n kubernetes-dashboard
Edit cancelled, no changes made.

注意:type=NodePort


[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.94.243   <none>        443:32052/TCP   8m18s

在浏览器上访问:https://192.168.118.66:32052,高级访问,获得登录的token

--获得token

[root@k8s-master dashboard]# kubectl create token admin-user -n kube-system
eyJhbGciOiJSUzI1NiIsImtpZCI6Ijh0Zm9pU0t5S3puV3ZLWHpwVkRGUXM4aFViRjdVZFBLdHpYeTU1NVJrX1kifQ.eyJhdWQiOlsiaHR0cHM6Ly9rdWJlcm5ldGVzLmRlZmF1bHQuc3ZjLmNsdXN0ZXIubG9jYWwiXSwiZXhwIjoxNzI2MTE1NTEyLCJpYXQiOjE3MjYxMTE5MTIsImlzcyI6Imh0dHBzOi8va3ViZXJuZXRlcy5kZWZhdWx0LnN2Yy5jbHVzdGVyLmxvY2FsIiwia3ViZXJuZXRlcy5pbyI6eyJuYW1lc3BhY2UiOiJrdWJlLXN5c3RlbSIsInNlcnZpY2VhY2NvdW50Ijp7Im5hbWUiOiJhZG1pbi11c2VyIiwidWlkIjoiNWQwMjBkOWUtMDliMi00MGUwLThiMTUtNDViYmI3NGZhMGUyIn19LCJuYmYiOjE3MjYxMTE5MTIsInN1YiI6InN5c3RlbTpzZXJ2aWNlYWNjb3VudDprdWJlLXN5c3RlbTphZG1pbi11c2VyIn0.EmwSF8lVccF59bVCYZ7ncZAQ26tfi-Y0Zk5kgqEw3pKqMcXrEwxLIp8Hg84hyDvS-NsaXF7NH-6MIm9bjroLmoazUIFTV0e8-CLQyuvqel_u1V0xeXJIRsb_F0q7lylWoF-aNBIZtsY6J_pc_IrAFYiiU-mKiZ2FVz0s6vm5P0ljjo_dsbC9AHeok-qEIlXEgZxiguUfLLeRK95l-lL93-tI7eVzHFesuf1SuD29fNBwprSVIitgVom6nvbE-0nCwMC3894ILualgLAt2JRwsEHjJmgWvVulx2gsD9zRye1UcFkIJXhdIgO1KL6GihmuSmo1zKunrPZkPR_2tPrDUw

[root@k8s-master dashboard]# kubectl run nginx0 --image=nginx

kube-proxy

--改为ipvs模式

[root@k8s-master ~]# kubectl get pods -A|grep proxy
kube-system            kube-proxy-8jk8f                             1/1     Running            1 (4h57m ago)   22h
kube-system            kube-proxy-dvfx4                             1/1     Running            1 (4h58m ago)   22h
kube-system            kube-proxy-g226c                             1/1     Running            1 (4h58m ago)   23h
[root@k8s-master ~]# kubectl edit cm kube-proxy -n kube-system


configmap/kube-proxy edited

--更新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

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

测试创建参数

[root@k8s-master ~]# kubectl create deploy cluster-test5 --image=registry.cn-beijing.aliyuncs.com/dotbalo/debug-tools -- sleep 3600
deployment.apps/cluster-test5 created
[root@k8s-master ~]# kubectl get po -A|grep clu

default                cluster-test1-6bbcc6fc8b-h7b9j               0/1     CrashLoopBackOff    10 (90s ago)    27m

default                cluster-test5-6597c95b6c-28tkj               1/1     Running             0               2s
 

带有哈希值的删除时,要使用deployment,如果使用pod时,不会删除

[root@k8s-master ~]# kubectl delete deployment cluster-test1
--进到创建的节点中

[root@k8s-master ~]# kubectl exec -it cluster-test5-6597c95b6c-28tkj -- bash
(07:36 cluster-test5-6597c95b6c-28tkj:/) ifconfig
eth0      Link encap:Ethernet  HWaddr aa:7a:8a:e0:3e:93  
          inet addr:172.16.58.203  Bcast:0.0.0.0  Mask:255.255.255.255
          inet6 addr: fe80::a87a:8aff:fee0:3e93/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1480  Metric:1
          RX packets:5 errors:0 dropped:0 overruns:0 frame:0
          TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:446 (446.0 B)  TX bytes:656 (656.0 B)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)


(1 07:36 cluster-test5-6597c95b6c-28tkj:/) nslookup kubernetes
Server:		10.96.0.10
Address:	10.96.0.10#53

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

(07:37 cluster-test5-6597c95b6c-28tkj:/) 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

(07:37 cluster-test5-6597c95b6c-28tkj:/) exit
exit
您在 /var/spool/mail/root 中有新邮件
[root@k8s-master ~]# curl -k https://10.96.0.1:443
{
  "kind": "Status",
  "apiVersion": "v1",
  "metadata": {},
  "status": "Failure",
  "message": "forbidden: User \"system:anonymous\" cannot get path \"/\"",
  "reason": "Forbidden",
  "details": {},
  "code": 403
}[root@k8s-master ~]# curl  http://10.96.0.1:53
curl: (7) Failed connect to 10.96.0.1:53; 拒绝连接

1.kubernetes自动补齐

--安装工具

yum -y install bash-completion
source <(kubectl completion bash)

-- 设置开机自启动
echo "source <(kubectl completion bash)" >> ~/.bashrc   

2.节点的删除

  # 删除节点
  [root@k8s-master ~]# kubectl delete pod cluster-test-64b7b9cbf-jjmmh
  pod "cluster-test-64b7b9cbf-jjmmh" deleted
  ​
  # 节点还在
  [root@k8s-master ~]# kubectl get po -A|grep cluster-test
  default                cluster-test-64b7b9cbf-dnn2m                 0/1     ContainerCreating   0               20s
  default                cluster-test0-58689d5d5d-qr4mv               1/1     Running             0               34m
  ​
  # 使用deployment删除
  [root@k8s-master ~]# kubectl delete deployment cluster-test
  deployment.apps "cluster-test" deleted
  ​
  # 已删除
  [root@k8s-master ~]# kubectl get po -A|grep cluster-test

注意:带用哈希值的要使用deployment删除

3.编写yaml文件,创建节点

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

  [root@k8s-master ~]# cd pods/
  [root@k8s-master pods]# ls
  abc.yaml  components.yaml
  [root@k8s-master pods]# kubectl create -f abc.yaml 
  [root@k8s-master pods]# kubectl create -f abc.yaml 
  pod/busybox-sleep created
  [root@k8s-master pods]# kubectl get po -A|grep busybox-sleep
  default                busybox-sleep                                1/1     Running   0               3s
  [root@k8s-master pods]# kubectl delete pod busybox-sleep
  pod "busybox-sleep" deleted
  [root@k8s-master pods]# kubectl get po -A|grep busy

4.编写json文件

  [root@k8s-master ~]# vim pods/abc.json
  {
      "apiVersion":"v1",
      "kind":"Pod",
      "metadata":{
          "name":"busybox-sleep000"
      },
      "spec":{
          "containers":[
              {
                  "name":"busybox000",
                  "image":"busybox:1.28",
                  "args":[
                      "sleep",
                      "1000"
                  ]
              }
          ]
      }
  }

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2129371.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

【Linux取经之路】用户权限管理

目录 shell命令以及运行原理 Linux权限的概念 1、用户的概念 2、切换用户 Linux权限管理 1、文件访问者的分类 2、文件类型和访问权限 3、文件访问权限的修改 4、文件所有权的修改 5、设置权限掩码 6、用户提权 7、目录的权限 8、粘滞位 shell命令以及运行原理 Linu…

D - 88888888

设N有K位 则&#xff1a; p998244353&#xff0c;是质数&#xff0c;vn%p只需要求一下分母的逆元即可。 分母于p互质&#xff0c;满足飞马小定理&#xff0c;故可以用其求逆元。 再用一下这个结论就OK了 #include<bits/stdc.h> using namespace std; #define int long…

《JavaEE进阶》----16.<Mybatis简介、操作步骤、相关配置>

本篇博客讲记录&#xff1a; 1.回顾MySQL的JDBC操作 2..Mybatis简介、Mybatis操作数据库的步骤 3.Mybatis 相关日志的配置&#xff08;日志的配置、驼峰自动转换的配置&#xff09; 前言 之前学习应用分层时我们知道Web应用程序一般分为三层&#xff0c;Controller、Service、D…

使用Python从头开始创建PowerPoint演示文稿

目录 一、环境搭建与基础知识 1.1 环境搭建 1.2 基础知识 二、创建演示文稿对象 三、添加幻灯片 3.1 选择幻灯片布局 3.2 设置幻灯片内容 3.2.1 设置标题和副标题 3.2.2 添加文本内容 3.2.3 插入图片 3.2.4 插入图表 四、高级应用&#xff1a;批量生成演示文稿 4.…

太惨了!许家印前妻每个月只能花18万

文&#xff5c;琥珀食酒社 作者 | 积溪 许家印前妻被判了 我跟你说啊她真是太惨了 一个月只能取18万啊 你说这日子怎么过啊 买个包包都不够啊&#xff01; 大家都知道许皮带爆雷&#xff08;BL&#xff09;后 丁玉梅虽然和许皮带战略性离婚&#xff0c;逃到了英国 还把…

【计算机组成原理】浮点数的表示及IEEE 754规格化

&#x1f4e2;博客主页&#xff1a;https://blog.csdn.net/2301_779549673 &#x1f4e2;欢迎点赞 &#x1f44d; 收藏 ⭐留言 &#x1f4dd; 如有错误敬请指正&#xff01; &#x1f4e2;本文由 JohnKi 原创&#xff0c;首发于 CSDN&#x1f649; &#x1f4e2;未来很长&#…

软件工程测试

1. 软件测试概述 通俗地说&#xff0c;软件测试是为了发现错误而执行程序的过程。 软件测试&#xff1a;根据软件开发各阶段的规格说明和程序的内部结构而精心设计一批测试用例&#xff08;即输入数据及其预期的输出结果&#xff09;&#xff0c;并利用这些测试用例去运行程序…

深度学习:基础知识

深度学习是机器学习的一个领域 神经网络构造 一个神经元有n个输入&#xff0c;每一个输入对应一个权值w&#xff0c;神经元内会对输入与权重做乘法后求和。 感知器 由两层神经元组成的神经网络--“感知器”&#xff08;Perceptron&#xff09;,感知器只能线性划分数据。 公式…

Netty笔记03-组件Channel

文章目录 Channel概述Channel 的概念Channel 的主要功能Channel 的生命周期Channel 的状态Channel 的类型channel 的主要方法 ChannelFutureCloseFuture&#x1f4a1; netty异步提升的是什么要点总结 Channel概述 Channel 的概念 在 Netty 中&#xff0c;Channel 是一个非常重…

c++题目_洛谷 / 题目详情 P1012 [NOIP1998 提高组] 拼数

# [NOIP1998 提高组] 拼数 ## 题目描述 设有 $n$ 个正整数 $a_1 \dots a_n$&#xff0c;将它们联接成一排&#xff0c;相邻数字首尾相接&#xff0c;组成一个最大的整数。 ## 输入格式 第一行有一个整数&#xff0c;表示数字个数 $n$。 第二行有 $n$ 个整数&#xff0c;表…

Linux学习笔记(黑马程序员,前四章节)

第一章 快照 虚拟机快照&#xff1a; 通俗来说&#xff0c;在学习阶段我们无法避免的可能损坏Linux操作系统&#xff0c;如果损坏的话&#xff0c;重新安装一个Linux操作系统就会十分麻烦。VMware虚拟机支持为虚拟机制作快照。通过快照将当前虚拟机的状态保存下来&#xff0c;…

Leetcode 移动零

要求将数组中的所有 0 移动到数组的末尾&#xff0c;同时保持非零元素的相对顺序。下面是该题的 C 解决方案&#xff1a; class Solution { public:void moveZeroes(vector<int>& nums) {int nonZeroPos 0; // 记录非零元素应该放置的位置// 遍历数组&#xff0c;…

镭速如何高效使用SQLite数据库高速传输结构化数据文件传输

SQLite数据库因其小巧、跨平台和无需配置的特性&#xff0c;在众多关系型数据库中独树一帜。与传统的服务器/客户端架构数据库&#xff0c;例如MySQL不同&#xff0c;SQLite通常被嵌入到应用程序中作为一个库。它不仅支持创建索引&#xff0c;还严格遵循ACID原则&#xff0c;非…

先攒一波硬件,过几年再给电脑升级,靠谱吗?想啥呢?

前言 最近有小伙伴发来消息&#xff1a;我可以今年先买电脑的部分硬件&#xff0c;明年再买电脑的另一部分硬件&#xff0c;再组装起来不就是一台电脑了吗&#xff1f; 这确实是一个很好的办法。 我还记得大学有个室友&#xff0c;从大一每个月省吃俭用&#xff0c;攒下的钱…

全球AI应用市场洞察:市场快速崛起,“陪伴式AI”、“图像AI”应用爆款频出!

自2023年 GPT4 的问世以来&#xff0c;得益于这股新的技术变量&#xff0c;各类 AI 应用在市场上遍地开花。在这轮热潮之下&#xff0c;不同市场和细分赛道有何机遇和挑战&#xff1f;以下根据 Sensor Tower 最新报告分析&#xff0c;帮助移动开发者、广告主洞察全球AI应用市场…

Linux系统:chgrp命令

1、命令详解&#xff1a; chgrp命令是Linux操作系统中用于修改文件或目录的所属组的命令。chgrp命令还可以修改链接文件的所属组&#xff0c;而不是链接所指向的文件的所属组。默认情况下&#xff0c;只有文件的所有者和超级用户才能修改文件的所属组&#xff0c;但如果用户是一…

JavaWeb【day08】--(MySQL-Mybatis入门)

数据库开发-MySQL 1. 多表查询 1.1 概述 1.1.1 数据准备 SQL脚本&#xff1a; #建议&#xff1a;创建新的数据库 create database db04; use db04; ​ -- 部门表 create table tb_dept (id int unsigned primary key auto_increment comment 主键ID,name v…

Win32编程:创建属于你的第一个窗口

目录 一、Win32程序的运行过程 二、创建Windows窗口 1、分析 2、完整代码 一、Win32程序的运行过程 Win32编程&#xff0c;也称为Windows编程。运行步骤主要包含&#xff1a;加载程序&#xff08;操作系统加载程序的可执行文件&#xff08;exe格式&#xff09;到内存中,创建…

代码随想录刷题day30丨452. 用最少数量的箭引爆气球, 435. 无重叠区间,763.划分字母区间

代码随想录刷题day30丨452. 用最少数量的箭引爆气球&#xff0c; 435. 无重叠区间&#xff0c;763.划分字母区间 1.题目 1.1用最少数量的箭引爆气球 题目链接&#xff1a;452. 用最少数量的箭引爆气球 - 力扣&#xff08;LeetCode&#xff09; 视频讲解&#xff1a;贪心算法…

ColorThief的介绍与使用

概述 colorThief是一个 Javascript 插件&#xff0c;支持在浏览器端或 Node 环境中使用。Thief的中文意思是偷窃、小偷。colorThief的作用就是通过算法去获取图片的色源。 API 介绍与示例 colorThief提供两个方法&#xff0c;getColor和getPalette&#xff0c;这两个方法在 …