k8s基础操作命令
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基础操作命令的更多相关文章
- git的简单理解及基础操作命令
前端小白一枚,最近开始使用git,于是花了2天看了廖雪峰的git教程(偏实践,对于学习git的基础操作很有帮助哦),也在看<git版本控制管理>这本书(偏理论,内容完善,很不错),针对所学 ...
- MySQL基础操作命令
MySQL基础操作命令 1. 查看MySQL进程 ps -ef|grep mysql |grep -v grep 2. 查看MySQL端口 ss -lnt | grep 3306 3. MySQL的启 ...
- 《两地书》--Kubernetes(K8s)基础知识(docker容器技术)
大家都知道历史上有段佳话叫“司马相如和卓文君”.“皑如山上雪,皎若云间月”.卓文君这么美,却也抵不过多情女儿薄情郎. 司马相如因一首<子虚赋>得汉武帝赏识,飞黄腾达之后便要与卓文君“故来相 ...
- Git的常见基础操作命令
Git的常见基础操作命令 1安装初始化 1.1安装git本地安装Windows版本 下载地址: https://git-scm.com/downloads/ 1.2初始化Git用户信息配置 配置git ...
- ASP.NET Core on K8S深入学习(1)K8S基础知识与集群搭建
在上一个小系列文章<ASP.NET Core on K8S学习初探>中,通过在Windows上通过Docker for Windows搭建了一个单节点的K8S环境,并初步尝试将ASP.NE ...
- Kubeasz部署K8s基础测试环境简介
下面介绍使用Kubeasz部署K8s集群环境. https://github.com/easzlab/kubeasz在需要使用kubeeasz项目安装的k8s时,需要将所有需要它来部署的节点上,都安装 ...
- Kubernetes(K8s)基础知识(docker容器技术)
今天谈谈K8s基础知识关键词: 一个目标:容器操作:两地三中心:四层服务发现:五种Pod共享资源:六个CNI常用插件:七层负载均衡:八种隔离维度:九个网络模型原则:十类IP地址:百级产品线:千级物理机 ...
- docker+k8s基础篇五
Docker+K8s基础篇(五) service资源介绍 A:service资源的工作特性 service的使用 A:service字段介绍 B:ClusterIP的简单使用 C:NodePort的简 ...
- docker+k8s基础篇四
Docker+K8s基础篇(四) pod控制器 A:pod控制器类型 ReplicaSet控制器 A:ReplicaSet控制器介绍 B:ReplicaSet控制器的使用 Deployment控制器 ...
随机推荐
- springMVC:为MultipartFilte配置了上传文件解析器,报错或不能使用
一.问题描述为支持restful风格请求,并且应对可能上传文件的情况,需要在配置hiddenHttpMethodFilter过滤器之前配置MultipartFilter.目的是让MultipartFi ...
- Java数组移位和统计
package com.imooc.method; import java.util.InputMismatchException; import java.util.Scanner; public ...
- npm 加速之 yarn cnpm pnpm
npm 加速之 yarn cnpm pnpm 有没有感觉到使用 npm 的时候很慢? 安装速度 几Kb/s 不说, 还装着装着出错了, 奇奇怪怪的问题.这种情况大多数还是因为网络的原因, 很多时候虽然 ...
- Qt编写安防视频监控系统(界面很漂亮)
一.前言 视频监控系统在整个安防领域,已经做到了烂大街的程序,全国起码几百家公司做过类似的系统,当然这一方面的需求量也是非常旺盛的,各种定制化的需求越来越多,尤其是这几年借着人脸识别的东风,发展更加迅 ...
- 《绯雨骑士团》Demo,框架实现,寻路打怪
在家无事花几天做了个放置挂机demo,做着玩吧.和海拓的<凡人修仙传>类似吧,自动挂机刷怪打boss数值游戏,但是我比较喜欢二次元的,所以选了<绯雨骑士团>的资源. 参考了以下 ...
- linux默认的2.7升级到3.7版本
CentOS7中自带的python版本是python-2.7.5,由于新开的虚拟机需要使用python3,于是便升级一下版本. 安装Python3.7.3 官网下载地址:https://www.pyt ...
- 爬虫相关-scrapy框架介绍
性能相关-进程.线程.协程 在编写爬虫时,性能的消耗主要在IO请求中,当单进程单线程模式下请求URL时必然会引起等待,从而使得请求整体变慢. 串行执行 import requests def fetc ...
- SQL Server:时间范围查询重叠
常常碰到要校验数据范围是否存在重叠冲突的情况,典型的场景是房间预订. 假如房间A已经有9月1日-9月10日的预订记录,当其它客人再来预订时,系统必须判断,不能与这个日期范围产生重叠. 有四种情况会产生 ...
- 【loj6538】烷基计数 加强版 加强版 Burnside引理+多项式牛顿迭代
别问我为啥突然刷了道OI题,也别问我为啥花括号不换行了... 题目描述 求含 $n$ 个碳原子的本质不同的烷基数目模 $998244353$ 的结果.$1\le n\le 10^5$ . 题解 Bur ...
- WeQuant教程—1.4 实践教学:比特币量化定投
在wequant.io,为了让读者能直接体验量化系统的魅力,我们用前面的思路,实现了一套完整的量化系统和回测工具,这个系统非常简单,用户只需要把交易意志用策略表达出来,系统就可以自己完成交易效果的回 ...