K8s重新加入节点

1.重置node节点环境在slave节点上执行

[root@node2 ~]# kubeadm reset

[reset] WARNING: changes made to this host by 'kubeadm init' or 'kubeadm join' will be reverted.
[reset] are you sure you want to proceed? [y/N]: y
[preflight] running pre-flight checks
[reset] stopping the kubelet service
[reset] unmounting mounted directories in "/var/lib/kubelet"
[reset] removing kubernetes-managed containers
[reset] cleaning up running containers using crictl with socket /var/run/dockershim.sock
[reset] failed to list running pods using crictl: exit status . Trying to use docker instead[reset] no etcd manifest found in "/etc/kubernetes/manifests/etcd.yaml". Assuming external etcd
[reset] deleting contents of stateful directories: [/var/lib/kubelet /etc/cni/net.d /var/lib/dockershim /var/run/kubernetes]
[reset] deleting contents of config directories: [/etc/kubernetes/manifests /etc/kubernetes/pki]
[reset] deleting files: [/etc/kubernetes/admin.conf /etc/kubernetes/kubelet.conf /etc/kubernetes/bootstrap-kubelet.conf /etc/kubernetes/controller-manager.conf /etc/kubernetes/scheduler.conf]

reset

2.关闭slave节点的交换分区

[root@node3 ~]# swapoff  -a

处理token和CA证书过期

1.在master上执行

[root@k8s-master ~]# openssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt | openssl rsa -pubin -outform der >/dev/null | openssl dgst -sha256 -hex | sed 's/^.* //'
5a949445e86e76a060f6c3a6c2f571df4361085387cde7068493b418d484bb14
[root@k8s-master ~]# kubeadm token create
lsv2rv.7q0or3flbjne8s0k

2.在slave上执行

[root@node2 ~]# kubeadm join 192.168.11.141: --token lsv2rv.7q0or3flbjne8s0k  --discovery-token-ca-cert-hash sha256:5a949445e86e76a060f6c3a6c2f571df4361085387cde7068493b418d484bb14

[preflight] running pre-flight checks
[WARNING RequiredIPVSKernelModulesAvailable]: the IPVS proxier will not be used, because the following required kernel modules are not loaded: [ip_vs ip_vs_rr ip_vs_wrr ip_vs_sh] or no builtin kernel ipvs support: map[ip_vs_wrr:{} ip_vs_sh:{} nf_conntrack_ipv4:{} ip_vs:{} ip_vs_rr:{}]
you can solve this problem with following methods:
. Run 'modprobe -- ' to load missing kernel modules;
. Provide the missing builtin kernel ipvs support I0517 ::53.384827 kernel_validator.go:] Validating kernel version
I0517 ::53.384903 kernel_validator.go:] Validating kernel config
[WARNING Hostname]: hostname "node2" could not be reached
[WARNING Hostname]: hostname "node2" lookup node2 on 192.168.11.2:: no such host
[discovery] Trying to connect to API Server "192.168.11.141:6443"
[discovery] Created cluster-info discovery client, requesting info from "https://192.168.11.141:6443"
[discovery] Requesting info from "https://192.168.11.141:6443" again to validate TLS against the pinned public key
[discovery] Cluster info signature and contents are valid and TLS certificate validates against pinned roots, will use API Server "192.168.11.141:6443"
[discovery] Successfully established connection with API Server "192.168.11.141:6443"
[kubelet] Downloading configuration for the kubelet from the "kubelet-config-1.11" ConfigMap in the kube-system namespace
[kubelet] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"
[kubelet] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"
[preflight] Activating the kubelet service
[tlsbootstrap] Waiting for the kubelet to perform the TLS Bootstrap...
[patchnode] Uploading the CRI Socket information "/var/run/dockershim.sock" to the Node API object "node2" as an annotation This node has joined the cluster:
* Certificate signing request was sent to master and a response
was received.
* The Kubelet was informed of the new secure connection details. Run 'kubectl get nodes' on the master to see this node join the cluster.

3.kubectl命令过期

#  rm -fr $HOME/.kube/config
   # cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
   # sudo chown $(id -u):$(id -g) $HOME/.kube/config

k8s命令实例

pod的创建和删除

[root@k8s-master ~]#kubectl run nginx-deploy --image=nginx:1.14-alpine --port= --replicas=

[root@k8s-master ~]# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE
nginx-deploy-5b595999-d7rpg / Running 226d 10.244.1.11 node2
nginx-deploy-5b595999-sdfcz / Running 226d 10.244.1.10 node2 [root@node2 ~]# curl 10.244.1.11
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style> [root@k8s-master ~]# kubectl delete pods nginx-deploy-5b595999-sdfcz
pod "nginx-deploy-5b595999-sdfcz" deleted
[root@k8s-master ~]# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE
nginx-deploy-5b595999-d7rpg / Running 226d 10.244.1.11 node2
nginx-deploy-5b595999-s4cjv / ContainerCreating 4s <none> node3
[root@k8s-master ~]# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE
nginx-deploy-5b595999-d7rpg / Running 226d 10.244.1.11 node2
nginx-deploy-5b595999-s4cjv / Running 25s 10.244.2.5 node3

service的管理

service是用来为pod提供固定访问端点的
   service地址是通过iptables或者ipvs规则来实现的 不能直接ping通      但是却可以通过地址访问到对应的服务

[root@k8s-master ~]# kubectl run myapp --image=ikubernetes/myapp:v1 --replicas=
deployment.apps/myapp created
[root@k8s-master ~]# kubectl get deployment
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
myapp 14s
nginx-deploy 226d
[root@k8s-master ~]# kubectl get deployment -w
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
myapp 23s
nginx-deploy 226d
myapp 55s
myapp 1m
^C[root@k8s-master ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
myapp-848b5b879b-9kd6s / Running 1m
myapp-848b5b879b-dvtgn / Running 1m
nginx-deploy-5b595999-d7rpg / Running 226d
nginx-deploy-5b595999-s4cjv / Running 56m
[root@k8s-master ~]# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE
myapp-848b5b879b-9kd6s / Running 1m 10.244.2.6 node3
myapp-848b5b879b-dvtgn / Running 1m 10.244.1.12 node2
nginx-deploy-5b595999-d7rpg / Running 226d 10.244.1.11 node2
nginx-deploy-5b595999-s4cjv / Running 57m 10.244.2.5 node3
[root@k8s-master ~]# wget -O - -q 10.244.2.6
Hello MyApp | Version: v1 | <a href="hostname.html">Pod Name</a>
[root@k8s-master ~]# kubectl expose deployment myapp --name=myapp --port=
service/myapp exposed
[root@k8s-master ~]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> /TCP 226d
myapp ClusterIP 10.101.171.64 <none> /TCP 8s
nginx ClusterIP 10.106.232.252 <none> /TCP 6m
[root@k8s-master ~]# kubectl scale --replicas= deployment=myapp
error: resource(s) were provided, but no name, label selector, or --all flag specified
[root@k8s-master ~]# kubectl scale --replicas= deployment myapp
deployment.extensions/myapp scaled
[root@k8s-master ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
client / Running 5m
myapp-848b5b879b-5vqx5 / ContainerCreating 12s
myapp-848b5b879b-98pht / ContainerCreating 12s
myapp-848b5b879b-9kd6s / Running 10m
myapp-848b5b879b-dvtgn / Running 10m
myapp-848b5b879b-s6bjh / ContainerCreating 12s
nginx-deploy-5b595999-d7rpg / Running 226d
nginx-deploy-5b595999-s4cjv / Running 1h
[root@k8s-master ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
client / Running 5m
myapp-848b5b879b-5vqx5 / Running 15s
myapp-848b5b879b-98pht / Running 15s
myapp-848b5b879b-9kd6s / Running 10m
myapp-848b5b879b-dvtgn / Running 10m
myapp-848b5b879b-s6bjh / Running 15s
nginx-deploy-5b595999-d7rpg / Running 226d
nginx-deploy-5b595999-s4cjv / Running 1h
[root@k8s-master ~]# kubectl scale --replicas= deployment myapp
deployment.extensions/myapp scaled
[root@k8s-master ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
client / Running 5m
myapp-848b5b879b-5vqx5 / Running 30s
myapp-848b5b879b-9kd6s / Running 10m
myapp-848b5b879b-dvtgn / Running 10m
nginx-deploy-5b595999-d7rpg / Running 226d
nginx-deploy-5b595999-s4cjv / Running 1h
[root@k8s-master ~]# kubectl set image deployment myapp myapp=ikubernetes/myapp:v2
deployment.extensions/myapp image updated
[root@k8s-master ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
client / Running 9m
myapp-74c94dcb8c-mjjpw / ContainerCreating 14s
myapp-848b5b879b-5vqx5 / Running 4m
myapp-848b5b879b-9kd6s / Running 14m
myapp-848b5b879b-dvtgn / Running 14m
nginx-deploy-5b595999-d7rpg / Running 226d
nginx-deploy-5b595999-s4cjv / Running 1h
[root@k8s-master ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
client / Running 10m
myapp-74c94dcb8c-l2j8v / ContainerCreating 32s
myapp-74c94dcb8c-mjjpw / Running 1m
myapp-848b5b879b-9kd6s / Running 15m
myapp-848b5b879b-dvtgn / Running 15m
nginx-deploy-5b595999-d7rpg / Running 226d
nginx-deploy-5b595999-s4cjv / Running 1h
[root@k8s-master ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
client / Running 11m
myapp-74c94dcb8c-dhhln / Running 1m
myapp-74c94dcb8c-l2j8v / Running 1m
myapp-74c94dcb8c-mjjpw / Running 2m
nginx-deploy-5b595999-d7rpg / Running 226d
nginx-deploy-5b595999-s4cjv / Running 1h
[root@k8s-master ~]# kubectl edit svc myapp
修改service的type ClusterType 改成NodePort service/myapp edited
[root@k8s-master ~]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> /TCP 226d
myapp NodePort 10.101.171.64 <none> :/TCP 19m
nginx ClusterIP 10.106.232.252 <none> /TCP 25m

通过service可以把服务映射到集群中的任何一个节点上

k8s基础操作命令的更多相关文章

  1. git的简单理解及基础操作命令

    前端小白一枚,最近开始使用git,于是花了2天看了廖雪峰的git教程(偏实践,对于学习git的基础操作很有帮助哦),也在看<git版本控制管理>这本书(偏理论,内容完善,很不错),针对所学 ...

  2. MySQL基础操作命令

    MySQL基础操作命令 1. 查看MySQL进程 ps -ef|grep mysql |grep -v grep 2. 查看MySQL端口 ss -lnt | grep 3306 3. MySQL的启 ...

  3. 《两地书》--Kubernetes(K8s)基础知识(docker容器技术)

    大家都知道历史上有段佳话叫“司马相如和卓文君”.“皑如山上雪,皎若云间月”.卓文君这么美,却也抵不过多情女儿薄情郎. 司马相如因一首<子虚赋>得汉武帝赏识,飞黄腾达之后便要与卓文君“故来相 ...

  4. Git的常见基础操作命令

    Git的常见基础操作命令 1安装初始化 1.1安装git本地安装Windows版本 下载地址: https://git-scm.com/downloads/ 1.2初始化Git用户信息配置 配置git ...

  5. ASP.NET Core on K8S深入学习(1)K8S基础知识与集群搭建

    在上一个小系列文章<ASP.NET Core on K8S学习初探>中,通过在Windows上通过Docker for Windows搭建了一个单节点的K8S环境,并初步尝试将ASP.NE ...

  6. Kubeasz部署K8s基础测试环境简介

    下面介绍使用Kubeasz部署K8s集群环境. https://github.com/easzlab/kubeasz在需要使用kubeeasz项目安装的k8s时,需要将所有需要它来部署的节点上,都安装 ...

  7. Kubernetes(K8s)基础知识(docker容器技术)

    今天谈谈K8s基础知识关键词: 一个目标:容器操作:两地三中心:四层服务发现:五种Pod共享资源:六个CNI常用插件:七层负载均衡:八种隔离维度:九个网络模型原则:十类IP地址:百级产品线:千级物理机 ...

  8. docker+k8s基础篇五

    Docker+K8s基础篇(五) service资源介绍 A:service资源的工作特性 service的使用 A:service字段介绍 B:ClusterIP的简单使用 C:NodePort的简 ...

  9. docker+k8s基础篇四

    Docker+K8s基础篇(四) pod控制器 A:pod控制器类型 ReplicaSet控制器 A:ReplicaSet控制器介绍 B:ReplicaSet控制器的使用 Deployment控制器 ...

随机推荐

  1. [转]docx4j实现动态表格(模板式)

    原文地址:https://chendd.cn/information/viewInformation/other/257.a 除了前篇文章中讲到的编程式创建表格外,基于模板实现的列表表格也是非常常用或 ...

  2. MYSQL定时任务-定时清除备份数据

    背景 由于项目需要,每个月的历史存量数据需要进行一个归档和备份操作,以及一些日志表需要进行一个明细字段清除,让mysql数据库磁盘节省空间.则需要一些定时任务来定时清理这些数据. 技术选型 Java ...

  3. Elasticsearch6.2.1安装elasticsearch-sq插件

    参考 https://github.com/NLPchina/elasticsearch-sql 1.下载插件 wget https://github.com/NLPchina/elasticsear ...

  4. Xcode中opengl的配置

    1. GLUT + GLTools + SDL2 Frameworks Search Paths :Framework + Library ( $(PROJECT_DIR)/build ) Searc ...

  5. TCP/IP和OSI4层、7层协议介绍

    1.TCP/IP全称:Transmission Control Protocol / Internet Protocol 中文翻译:传输控制协议 / 互联网协议 2.OSI4层.7层模型:

  6. python中空列表判断方法总结,欢迎补充

    --代码-- if __name__ == '__main__': l = [] print(l.__len__() == 0) print(l.__sizeof__() == 40) print(l ...

  7. Pycharm新建文件css文件无后缀,html中无法正确引入

    使用pycharm新建了一个文件mycss,然后选择文件类型是css,显示也正常,但是在页面中使用link引入始终无法生效.后来加了后缀名.css,发现可以正常显示样式了,所以新建文件时最好就加上后缀 ...

  8. [IOT] - 使用 .Net Core 操作 GPIO 引脚点亮 LED 灯泡

    1. 在 VS 2019 中创建 .Net Core 控制台应用程序,使用 Nuget 安装程序包: System.Device.GpioIot.Device.Bindings 2. 更新 Main ...

  9. DELPHI6中DSGNINTF.DCU找不到时的解决方法

    https://www.cnblogs.com/gaodu2003/archive/2009/06/04/1495789.html 1.添加 lib\designide.dcp到控件的dpk文件的re ...

  10. pytest_函数传参和firture传参数request

    前言为了提高代码的复用性,我们在写用例的时候,会用到函数,然后不同的用例去调用这个函数. 比如登录操作,大部分的用例都会先登录,那就需要把登录单独抽出来写个函数,其它用例全部的调用这个登陆函数就行. ...