IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 系统运维 -> Linux学习-kubernetes学习之kubectl命令(二) -> 正文阅读

[系统运维]Linux学习-kubernetes学习之kubectl命令(二)

kubernetes版本1.22.3

问题1:

Error from server: Get "https://192.168.88.103:10250/containerLogs/default/client/client": dial tcp 192.168.88.103:10250: connect: no route to host

解决方法

#经查看因为192.168.88.103上面firewalld服务处于开启状态,需关闭,并设置为开机不启动
[root@node2 ~]# systemctl stop firewalld
[root@node2 ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
kubectl 命令
#查看节点的详细信息
[root@master bak]# kubectl describe node node1
Name:               node1
Roles:              <none>
Labels:             beta.kubernetes.io/arch=amd64
                    beta.kubernetes.io/os=linux
                    kubernetes.io/arch=amd64
                    kubernetes.io/hostname=node1
                    kubernetes.io/os=linux
Annotations:        flannel.alpha.coreos.com/backend-data: {"VNI":1,"VtepMAC":"72:c5:c4:bc:31:ff"}
                    flannel.alpha.coreos.com/backend-type: vxlan
                    flannel.alpha.coreos.com/kube-subnet-manager: true
                    flannel.alpha.coreos.com/public-ip: 192.168.88.102
                    kubeadm.alpha.kubernetes.io/cri-socket: /var/run/dockershim.sock
                    node.alpha.kubernetes.io/ttl: 0
                    volumes.kubernetes.io/controller-managed-attach-detach: true
CreationTimestamp:  Wed, 03 Nov 2021 10:45:38 -0400
Taints:             <none>
Unschedulable:      false
Lease:
  HolderIdentity:  node1
  AcquireTime:     <unset>
  RenewTime:       Wed, 03 Nov 2021 11:12:26 -0400
Conditions:
  Type                 Status  LastHeartbeatTime                 LastTransitionTime                Reason                       Message
  ----                 ------  -----------------                 ------------------                ------                       -------
  NetworkUnavailable   False   Wed, 03 Nov 2021 10:45:46 -0400   Wed, 03 Nov 2021 10:45:46 -0400   FlannelIsUp                  Flannel is running on this node
  MemoryPressure       False   Wed, 03 Nov 2021 11:11:04 -0400   Wed, 03 Nov 2021 10:45:38 -0400   KubeletHasSufficientMemory   kubelet has sufficient memory available
  DiskPressure         False   Wed, 03 Nov 2021 11:11:04 -0400   Wed, 03 Nov 2021 10:45:38 -0400   KubeletHasNoDiskPressure     kubelet has no disk pressure
  PIDPressure          False   Wed, 03 Nov 2021 11:11:04 -0400   Wed, 03 Nov 2021 10:45:38 -0400   KubeletHasSufficientPID      kubelet has sufficient PID available
  Ready                True    Wed, 03 Nov 2021 11:11:04 -0400   Wed, 03 Nov 2021 10:45:48 -0400   KubeletReady                 kubelet is posting ready status
Addresses:
  InternalIP:  192.168.88.102
  Hostname:    node1
Capacity:
  cpu:                4
  ephemeral-storage:  38815216Ki
  hugepages-1Gi:      0
  hugepages-2Mi:      0
  memory:             7992344Ki
  pods:               110
Allocatable:
  cpu:                4
  ephemeral-storage:  35772103007
  hugepages-1Gi:      0
  hugepages-2Mi:      0
  memory:             7889944Ki
  pods:               110
System Info:
  Machine ID:                 53c69389ae554f4f83ed809bd51dddca
  System UUID:                BF9C4D56-0FE6-5083-0565-16792C78EDF6
  Boot ID:                    d4fd0a95-b88f-42af-8822-696d59b63542
  Kernel Version:             3.10.0-862.el7.x86_64
  OS Image:                   CentOS Linux 7 (Core)
  Operating System:           linux
  Architecture:               amd64
  Container Runtime Version:  docker://20.10.10
  Kubelet Version:            v1.22.3
  Kube-Proxy Version:         v1.22.3
PodCIDR:                      192.168.2.0/24
PodCIDRs:                     192.168.2.0/24
Non-terminated Pods:          (2 in total)
  Namespace                   Name                     CPU Requests  CPU Limits  Memory Requests  Memory Limits  Age
  ---------                   ----                     ------------  ----------  ---------------  -------------  ---
  kube-system                 kube-flannel-ds-dfvsb    100m (2%)     100m (2%)   50Mi (0%)        50Mi (0%)      35m
  kube-system                 kube-proxy-gn9nj         0 (0%)        0 (0%)      0 (0%)           0 (0%)         35m
Allocated resources:
  (Total limits may be over 100 percent, i.e., overcommitted.)
  Resource           Requests   Limits
  --------           --------   ------
  cpu                100m (2%)  100m (2%)
  memory             50Mi (0%)  50Mi (0%)
  ephemeral-storage  0 (0%)     0 (0%)
  hugepages-1Gi      0 (0%)     0 (0%)
  hugepages-2Mi      0 (0%)     0 (0%)
Events:
  Type    Reason                   Age                From        Message
  ----    ------                   ----               ----        -------
  Normal  Starting                 26m                kube-proxy  
  Normal  Starting                 34m                kube-proxy  
  Normal  NodeHasSufficientMemory  35m                kubelet     Node node1 status is now: NodeHasSufficientMemory
  Normal  NodeHasNoDiskPressure    35m                kubelet     Node node1 status is now: NodeHasNoDiskPressure
  Normal  NodeHasSufficientPID     35m                kubelet     Node node1 status is now: NodeHasSufficientPID
  Normal  NodeAllocatableEnforced  35m                kubelet     Updated Node Allocatable limit across pods
  Normal  Starting                 35m                kubelet     Starting kubelet.
  Normal  NodeReady                34m                kubelet     Node node1 status is now: NodeReady
  Normal  Starting                 26m                kubelet     Starting kubelet.
  Normal  NodeHasNoDiskPressure    26m (x2 over 26m)  kubelet     Node node1 status is now: NodeHasNoDiskPressure
  Normal  NodeHasSufficientPID     26m (x2 over 26m)  kubelet     Node node1 status is now: NodeHasSufficientPID
  Normal  NodeAllocatableEnforced  26m                kubelet     Updated Node Allocatable limit across pods
  Normal  NodeHasSufficientMemory  26m (x2 over 26m)  kubelet     Node node1 status is now: NodeHasSufficientMemory
  Normal  NodeReady                26m                kubelet     Node node1 status is now: NodeReady
#version查看kubectl版本信息
[root@master bak]# kubectl version
Client Version: version.Info{Major:"1", Minor:"22", GitVersion:"v1.22.3", GitCommit:"c92036820499fedefec0f847e2054d824aea6cd1", GitTreeState:"clean", BuildDate:"2021-10-27T18:41:28Z", GoVersion:"go1.16.9", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"22", GitVersion:"v1.22.3", GitCommit:"c92036820499fedefec0f847e2054d824aea6cd1", GitTreeState:"clean", BuildDate:"2021-10-27T18:35:25Z", GoVersion:"go1.16.9", Compiler:"gc", Platform:"linux/amd64"}
#cluster-info获得集群信息
[root@master bak]# kubectl cluster-info
Kubernetes control plane is running at https://192.168.88.101:6443
CoreDNS is running at https://192.168.88.101:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
#部署nginx应用
#--dry-run程序并没有真正执行
[root@master ~]# kubectl run nginx-deploy --image=nginx:1.14-alpine --port=80 --dry-run=true
W1103 11:25:31.051890  100284 helpers.go:569] --dry-run=true is deprecated (boolean value) and can be replaced with --dry-run=client.
pod/nginx-deploy created (dry run)
#创建deployment ,--replicas表示使用两个副本部署nginx
[root@master ~]# kubectl create deployment nginx-deploy --image=nginx:1.14-alpine --replicas=2
deployment.apps/nginx-deploy created
#通过service暴露资源
[root@master ~]# kubectl expose deployment nginx-deploy  --name=nginx --port=80 --target-port=80 --protocol=TCP
service/nginx exposed
#获取pod列表
[root@master ~]# kubectl get pods
NAME                            READY   STATUS    RESTARTS      AGE
nginx                           1/1     Running   1 (74m ago)   14h
nginx-deploy-7c948bcff4-jclqg   1/1     Running   0             26m
nginx-deploy-7c948bcff4-mczxp   1/1     Running   0             26m
#获取service列表,service创建后通过SELECTOR(标签选择器)关联至后端的Pod
[root@master ~]# kubectl get service -o wide
NAME         TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)   AGE   SELECTOR
kubernetes   ClusterIP   10.96.0.1       <none>        443/TCP   24h   <none>
nginx        ClusterIP   10.105.125.19   <none>        80/TCP    28m   app=nginx-deploy
#通过curl访问service的地址,可以查看nginx服务的页面
[root@master ~]# curl 10.105.125.19
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>
#查看kube的服务dns
[root@master ~]# kubectl get service -n kube-system
NAME       TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)                  AGE
kube-dns   ClusterIP   10.96.0.10   <none>        53/UDP,53/TCP,9153/TCP   23h
#创建一个client deployment
[root@master ~]# kubectl create deployment client --image=busybox --replicas=1
deployment.apps/client created
#运行名为client的deployment
[root@master ~]# kubectl run client -it --image=busybox --restart=Never
If you don't see a command prompt, try pressing enter.
/ # cat /etc/resolv.conf
#DNS地址
nameserver 10.96.0.10
#kubernetes本地的Pod资源,default指的名称空间的名字,search表示搜索域
search default.svc.cluster.local svc.cluster.local cluster.local
options ndots:5
#在pod中可以直接解析service
/ # wget -O - -q nginx
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

#解析nginx的A记录的service地址
[root@master ~]# dig -t A nginx.default.svc.cluster.local @10.96.0.10 

; <<>> DiG 9.11.4-P2-RedHat-9.11.4-26.P2.el7_9.7 <<>> -t A nginx.default.svc.cluster.local @10.96.0.10
;; global options: +cmd
;; Got answer:
;; WARNING: .local is reserved for Multicast DNS
;; You are currently testing what happens when an mDNS query is leaked to DNS
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 31486
;; flags: qr aa rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; WARNING: recursion requested but not available

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;nginx.default.svc.cluster.local. IN	A

;; ANSWER SECTION:
nginx.default.svc.cluster.local. 30 IN	A	10.105.125.19

;; Query time: 0 msec
;; SERVER: 10.96.0.10#53(10.96.0.10)
;; WHEN: Sun Nov 07 09:54:21 EST 2021
;; MSG SIZE  rcvd: 107

[root@master ~]# kubectl get services -o wide
NAME         TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)   AGE   SELECTOR
kubernetes   ClusterIP   10.96.0.1       <none>        443/TCP   23h   <none>
nginx        ClusterIP   10.105.125.19   <none>        80/TCP    24m   app=nginx-deploy
#查看service的信息
[root@master ~]# kubectl describe service nginx
Name:              nginx
Namespace:         default
Labels:            app=nginx-deploy
Annotations:       <none>
#选择器
Selector:          app=nginx-deploy
Type:              ClusterIP
IP Family Policy:  SingleStack
IP Families:       IPv4
IP:                10.105.125.19
IPs:               10.105.125.19
Port:              <unset>  80/TCP
TargetPort:        80/TCP
#对应的Pod的地址
Endpoints:         10.244.1.4:80,10.244.3.3:80
Session Affinity:  None
Events:            <none>
[root@master ~]# kubectl get pods --show-labels
NAME                            READY   STATUS             RESTARTS       AGE   LABELS
client                          1/1     Running            0              13m   run=client
client-7c75c79d7c-h9994         0/1     CrashLoopBackOff   8 (58s ago)    16m   app=client,pod-template-hash=7c75c79d7c
nginx                           1/1     Running            1 (103m ago)   14h   run=nginx
nginx-deploy-7c948bcff4-jclqg   1/1     Running            0              55m   app=nginx-deploy,pod-template-hash=7c948bcff4
nginx-deploy-7c948bcff4-mczxp   1/1     Running            0              55m   app=nginx-deploy,pod-template-hash=7c948bcff4
#动态扩展副本数量(增加/减少)
[root@master ~]# kubectl scale --replicas=3 deployment nginx-deploy
deployment.apps/nginx-deploy scaled
[root@master ~]# kubectl get pods
NAME                            READY   STATUS             RESTARTS       AGE
client                          1/1     Running            0              23m
client-7c75c79d7c-h9994         0/1     CrashLoopBackOff   10 (33s ago)   26m
nginx                           1/1     Running            1 (113m ago)   14h
nginx-deploy-7c948bcff4-jclqg   1/1     Running            0              65m
nginx-deploy-7c948bcff4-lhq2q   1/1     Running            0              7s
nginx-deploy-7c948bcff4-mczxp   1/1     Running            0              65m
[root@master ~]# kubectl scale --replicas=2 deployment nginx-deploy
deployment.apps/nginx-deploy scaled
[root@master ~]# kubectl get pods
NAME                            READY   STATUS             RESTARTS       AGE
client                          1/1     Running            0              24m
client-7c75c79d7c-h9994         0/1     CrashLoopBackOff   10 (84s ago)   27m
nginx                           1/1     Running            1 (114m ago)   14h
nginx-deploy-7c948bcff4-jclqg   1/1     Running            0              66m
nginx-deploy-7c948bcff4-mczxp   1/1     Running            0              66m
#修改service类型让其它机器可以访问Pod资源
[root@master ~]# kubectl edit service nginx
#修改  type: NodePort
[root@master ~]# kubectl get service
NAME         TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)        AGE
kubernetes   ClusterIP   10.96.0.1       <none>        443/TCP        24h
nginx        NodePort    10.105.125.19   <none>        80:31526/TCP   49m
  系统运维 最新文章
配置小型公司网络WLAN基本业务(AC通过三层
如何在交付运维过程中建立风险底线意识,提
快速传输大文件,怎么通过网络传大文件给对
从游戏服务端角度分析移动同步(状态同步)
MySQL使用MyCat实现分库分表
如何用DWDM射频光纤技术实现200公里外的站点
国内顺畅下载k8s.gcr.io的镜像
自动化测试appium
ctfshow ssrf
Linux操作系统学习之实用指令(Centos7/8均
上一篇文章      下一篇文章      查看所有文章
加:2021-11-09 20:02:38  更:2021-11-09 20:05:02 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/15 23:35:53-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码