Kubectl是管理k8s集群的命令行工具,通过生成的json格式传递给apiserver进行创建、查看、管理的操作。
[root@localhost ~]# kubectl --help
kubectl controls the Kubernetes cluster manager. (kubectl控制Kubernetes集群管理器)
Find more information at(更多信息请访问): https://kubernetes.io/docs/reference/kubectl/overview/
Basic Commands (Beginner):“基本命令(初级)”
create Create a resource from a file or from stdin.(从文件或stdin创建资源)
expose 使用 replication controller, service, deployment 或者 pod并暴露它作为一个 新的 Kubernetes Service
run 在集群中运行一个指定的镜像
set 为 objects 设置一个指定的特征
Basic Commands (Intermediate):“基本命令(中级)”
explain 查看资源的文档
get 显示一个或更多 resources
edit 在服务器上编辑一个资源
delete Delete resources by filenames, stdin, resources and names, or by resources and label selector(按文件名、stdin、资源和名称删除资源,或按资源和标签选择器删除资源)
Deploy Commands:“部署命令”
rollout Manage the rollout of a resource(管理资源的推出)
scale 为 Deployment, ReplicaSet, Replication Controller 或者 Job设置一个新的副本数量
autoscale 自动调整一个 Deployment, ReplicaSet, 或者ReplicationController 的副本数量
Cluster Management Commands:“集群管理命令”
certificate 修改 certificate 资源.
cluster-info 显示集群信息
top Display Resource (CPU/Memory/Storage) usage.(显示资源(CPU/内存/存储)使用情况)
cordon 标记 node 为 unschedulable
uncordon 标记 node 为 schedulable
drain Drain node in preparation for maintenance(排水节点,准备维护)
taint 更新一个或者多个 node 上的 taints
Troubleshooting and Debugging Commands:“故障排除和调试命令”
describe 显示一个指定 resource 或者 group 的 resources 详情
logs 输出容器在 pod 中的日志
attach Attach 到一个运行中的 container
exec 在一个 container 中执行一个命令
port-forward Forward one or more local ports to a pod(将一个或多个本地端口转发到一个pod)
proxy 运行一个 proxy 到 Kubernetes API server
cp 复制 files 和 directories 到 containers和从容器中复制 files 和 directories.
auth Inspect authorization(检查授权)
Advanced Commands:“先进的命令”
apply 通过文件名或标准输入流(stdin)对资源进行配置
patch 使用 strategic merge patch 更新一个资源的 field(s)
replace 通过 filename 或者 stdin替换一个资源
wait Experimental: Wait for a specific condition on one or many resources.(实验性:等待一个或多个资源上的特定条件)
convert 在不同的 API versions 转换配置文件
Settings Commands:“设置命令”
label 更新在这个资源上的 labels
annotate 更新一个资源的注解
completion Output shell completion code for the specified shell (bash or zsh)(指定shell的输出shell完成代码(bash或zsh))
Other Commands:“其他命令”
alpha Commands for features in alpha(alpha中的特性命令)
api-resources Print the supported API resources on the server(在服务器上打印支持的API资源)
api-versions Print the supported API versions on the server, in the form of "group/version"(在服务器上以“组/版本”的形式打印支持的API版本)
config 修改 kubeconfig 文件
plugin Provides utilities for interacting with plugins.(提供与插件交互的实用程序)
version 输出 client 和 server 的版本信息
kubectl run命令
语法:
kubectl run NAME --image=image(镜像) [--env="key=value"] [--port=port(端口)] [--replicas=replicas(副本)] [--dry-run=bool(测试状态)] [--overrides=inline-json(重写)] [--command(命令)] --[COMMAND] [args...] [options]
创建nginx:
(1)创建nginx镜像,副本集数量为3个
[root@localhost ~]# kubectl run nginx --image=nginx:latest --port=80 --replicas=3
kubectl run --generator=deployment/apps.v1beta1 is DEPRECATED and will be removed in a future version. Use kubectl create instead.
deployment.apps/nginx created
(2)查看创建的镜像,控制器,副本集
[root@localhost ~]# kubectl get pods,deployment,replicaset
NAME READY STATUS RESTARTS AGE
pod/nginx-7697996758-d6l5w 1/1 Running 0 4m44s
pod/nginx-7697996758-rtl66 1/1 Running 0 4m44s
pod/nginx-7697996758-zghwr 1/1 Running 0 4m44sNAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
deployment.extensions/nginx 3 3 3 3 4m44sNAME DESIRED CURRENT READY AGE
replicaset.extensions/nginx-7697996758 3 3 3 4m44s
kubectl expose命令
语法:
kubectl expose (-f FILENAME | TYPE NAME) [--port=port(端口:群集之间内部通讯的端口)] [--protocol=TCP|UDP|SCTP] [--target-port=number-or-name(端口:暴露在外部的端口)] [--name=name(名称)] [--external-ip=external-ip-of-service] [--type=type(类型)] [options(选项)]
发布nginx:
(1)发布nginx,类型为deployment,对内的端口号为80,对外暴露的端口也是80,并且deployment的名称为nginx-service,其类型为NodePort
[root@localhost ~]# kubectl expose deployment nginx --port=80 --target-port=80 --name=nginx-service --type=NodePort
service/nginx-service exposed
(2)查看查看资源对象,查看所有Pod列表,以及查看services服务
[root@localhost ~]# kubectl get pods,svc
NAME READY STATUS RESTARTS AGE
pod/nginx-7697996758-d6l5w 1/1 Running 0 124m
pod/nginx-7697996758-rtl66 1/1 Running 0 124m
pod/nginx-7697996758-zghwr 1/1 Running 0 124mNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kubernetes ClusterIP 10.0.0.1443/TCP 3d9h
service/nginx-service NodePort 10.0.0.12180:37434/TCP 98m
(3)查看资源对象简写
[root@localhost ~]# kubectl api-resources
NAME SHORTNAMES APIGROUP NAMESPACED KIND
bindings true Binding
componentstatuses cs false ComponentStatus
configmaps cm true ConfigMap
endpoints ep true Endpoints
events ev true Event
limitranges limits true LimitRange
namespaces ns false Namespace
nodes no false Node
persistentvolumeclaims pvc true PersistentVolumeClaim
persistentvolumes pv false PersistentVolume
pods po true Pod
podtemplates true PodTemplate
replicationcontrollers rc true ReplicationController
resourcequotas quota true ResourceQuota
secrets true Secret
serviceaccounts sa true ServiceAccount
services svc true Service
mutatingwebhookconfigurations admissionregistration.k8s.io false MutatingWebhookConfiguration
validatingwebhookconfigurations admissionregistration.k8s.io false ValidatingWebhookConfiguration
customresourcedefinitions crd,crds apiextensions.k8s.io false CustomResourceDefinition
apiservices apiregistration.k8s.io false APIService
controllerrevisions apps true ControllerRevision
daemonsets ds apps true DaemonSet
deployments deploy apps true Deployment
replicasets rs apps true ReplicaSet
statefulsets sts apps true StatefulSet
tokenreviews authentication.k8s.io false TokenReview
localsubjectaccessreviews authorization.k8s.io true LocalSubjectAccessReview
selfsubjectaccessreviews authorization.k8s.io false SelfSubjectAccessReview
selfsubjectrulesreviews authorization.k8s.io false SelfSubjectRulesReview
subjectaccessreviews authorization.k8s.io false SubjectAccessReview
horizontalpodautoscalers hpa autoscaling true HorizontalPodAutoscaler
cronjobs cj batch true CronJob
jobs batch true Job
certificatesigningrequests csr certificates.k8s.io false CertificateSigningRequest
leases coordination.k8s.io true Lease
events ev events.k8s.io true Event
daemonsets ds extensions true DaemonSet
deployments deploy extensions true Deployment
ingresses ing extensions true Ingress
networkpolicies netpol extensions true NetworkPolicy
podsecuritypolicies psp extensions false PodSecurityPolicy
replicasets rs extensions true ReplicaSet
networkpolicies netpol networking.k8s.io true NetworkPolicy
poddisruptionbudgets pdb policy true PodDisruptionBudget
podsecuritypolicies psp policy false PodSecurityPolicy
clusterrolebindings rbac.authorization.k8s.io false ClusterRoleBinding
clusterroles rbac.authorization.k8s.io false ClusterRole
rolebindings rbac.authorization.k8s.io true RoleBinding
roles rbac.authorization.k8s.io true Role
priorityclasses pc scheduling.k8s.io false PriorityClass
storageclasses sc storage.k8s.io false StorageClass
volumeattachments storage.k8s.io false VolumeAttachment
(4)查看关联后端的节点
[root@localhost ~]# kubectl get endpoints
NAME ENDPOINTS AGE
kubernetes 192.168.35.100:6443,192.168.35.103:6443 3d9h
nginx-service 172.17.45.2:80,172.17.68.2:80,172.17.68.3:80 105m
(5)网络状态详细信息
[root@localhost ~]# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE
nginx-7697996758-d6l5w 1/1 Running 0 132m 172.17.68.3 192.168.35.102
nginx-7697996758-rtl66 1/1 Running 0 132m 172.17.68.2 192.168.35.102
nginx-7697996758-zghwr 1/1 Running 0 132m 172.17.45.2 192.168.35.101
(6)查看服务暴露的端口
[root@localhost ~]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.0.0.1443/TCP 3d9h
nginx-service NodePort 10.0.0.12180:37434/TCP 108m
在node01操作,查看负载均衡端口37434
注意:kubernetes里kube-proxy支持三种模式,在v1.8之前我们使用的是iptables 以及 userspace两种模式,在kubernetes 1.8之后引入了ipvs模式,所以我们要实现安装一个 ipvsadm的软件包
[root@localhost ~]# yum install ipvsadm -y
[root@localhost ~]# ipvsadm -L -n
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 127.0.0.1:30001 rr
-> 172.17.45.3:8443 Masq 1 0 0
TCP 172.17.45.0:30001 rr
-> 172.17.45.3:8443 Masq 1 0 0
TCP 172.17.45.0:37434 rr
-> 172.17.45.2:80 Masq 1 0 0
-> 172.17.68.2:80 Masq 1 0 0
-> 172.17.68.3:80 Masq 1 0 0
TCP 172.17.45.1:30001 rr
-> 172.17.45.3:8443 Masq 1 0 0
TCP 192.168.35.101:30001 rr
-> 172.17.45.3:8443 Masq 1 0 0
TCP 192.168.35.101:37434 rr
-> 172.17.45.2:80 Masq 1 0 0
-> 172.17.68.2:80 Masq 1 0 0
-> 172.17.68.3:80 Masq 1 0 0
TCP 192.168.122.1:30001 rr
-> 172.17.45.3:8443 Masq 1 0 0
TCP 192.168.122.1:37434 rr
-> 172.17.45.2:80 Masq 1 0 0
-> 172.17.68.2:80 Masq 1 0 0
-> 172.17.68.3:80 Masq 1 0 0
TCP 10.0.0.1:443 rr
-> 192.168.35.100:6443 Masq 1 0 0
-> 192.168.35.103:6443 Masq 1 1 0
TCP 10.0.0.26:443 rr
-> 172.17.45.3:8443 Masq 1 0 0
TCP 10.0.0.121:80 rr
-> 172.17.45.2:80 Masq 1 0 0
-> 172.17.68.2:80 Masq 1 0 0
-> 172.17.68.3:80 Masq 1 0 0
TCP 127.0.0.1:37434 rr
-> 172.17.45.2:80 Masq 1 0 0
-> 172.17.68.2:80 Masq 1 0 0
-> 172.17.68.3:80 Masq 1 0 0
TCP 172.17.45.1:37434 rr
-> 172.17.45.2:80 Masq 1 0 0
-> 172.17.68.2:80 Masq 1 0 0
-> 172.17.68.3:80 Masq 1 0 0
在node02操作,同样安装ipvsadmin工具查看
[root@localhost ~]# yum install ipvsadm -y
[root@localhost ~]# ipvsadm -L -n
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 127.0.0.1:30001 rr
-> 172.17.45.3:8443 Masq 1 0 0
TCP 127.0.0.1:37434 rr
-> 172.17.45.2:80 Masq 1 0 0
-> 172.17.68.2:80 Masq 1 0 0
-> 172.17.68.3:80 Masq 1 0 0
TCP 172.17.68.0:30001 rr
-> 172.17.45.3:8443 Masq 1 0 0
TCP 172.17.68.0:37434 rr
-> 172.17.45.2:80 Masq 1 0 0
-> 172.17.68.2:80 Masq 1 0 0
-> 172.17.68.3:80 Masq 1 0 0
TCP 172.17.68.1:30001 rr
-> 172.17.45.3:8443 Masq 1 0 0
TCP 172.17.68.1:37434 rr
-> 172.17.45.2:80 Masq 1 0 0
-> 172.17.68.2:80 Masq 1 0 0
-> 172.17.68.3:80 Masq 1 0 0
TCP 192.168.35.102:30001 rr
-> 172.17.45.3:8443 Masq 1 0 0
TCP 192.168.35.102:37434 rr
-> 172.17.45.2:80 Masq 1 0 0
-> 172.17.68.2:80 Masq 1 0 0
-> 172.17.68.3:80 Masq 1 0 0
TCP 192.168.122.1:30001 rr
-> 172.17.45.3:8443 Masq 1 0 0
TCP 192.168.122.1:37434 rr
-> 172.17.45.2:80 Masq 1 0 0
-> 172.17.68.2:80 Masq 1 0 0
-> 172.17.68.3:80 Masq 1 0 0
TCP 10.0.0.1:443 rr
-> 192.168.35.100:6443 Masq 1 0 0
-> 192.168.35.103:6443 Masq 1 0 0
TCP 10.0.0.26:443 rr
-> 172.17.45.3:8443 Masq 1 0 0
TCP 10.0.0.121:80 rr
-> 172.17.45.2:80 Masq 1 0 0
-> 172.17.68.2:80 Masq 1 0 0
-> 172.17.68.3:80 Masq 1 0 0
在master1操作 查看访问日志(注意:如果访问其他node无法访问检查proxy组件)
[root@localhost ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-7697996758-d6l5w 1/1 Running 0 149m
nginx-7697996758-rtl66 1/1 Running 0 149m
nginx-7697996758-zghwr 1/1 Running 0 149m
在没有访问的情况下,是没有日志的
[root@localhost ~]# kubectl logs nginx-7697996758-d6l5w
[root@localhost ~]# kubectl logs nginx-7697996758-rtl66
[root@localhost ~]# kubectl logs nginx-7697996758-zghwr
去浏览器进行访问后,再去进行日志的查看
《1》输入:http://192.168.35.101:37434/
《2》输入:http://192.168.35.102:37434/
[root@localhost ~]# kubectl logs nginx-7697996758-d6l5w
172.17.68.1 - - [11/Feb/2020:15:15:20 +0000] "\x16\x03\x01\x02\x00\x01\x00\x01\xFC\x03\x03\xA6\xE8\x81T\x00\xA4}\xF2u\xFB\x7F\x5C\x91\x06\xEB^g\xA0$\x14\x9E6\xF9\x94k\xD9\x95\xD7\xD5\x16\xA1N 8\xEA\xC9!\xA2\xA3\xC6\x95\xD4m=\xDD\xA0W\xCD\xABb{\x1Bf>riOib\xD1\x06\x9E \x9F\xF2\x00\x22\xAA\xAA\x13\x01\x13\x02\x13\x03\xC0+\xC0/\xC0,\xC00\xCC\xA9\xCC\xA8\xC0\x13\xC0\x14\x00\x9C\x00\x9D\x00/\x005\x00" 400 157 "-" "-" "-"
172.17.68.1 - - [11/Feb/2020:15:15:20 +0000] "\x16\x03\x01\x00\xB6\x01\x00\x00\xB2\x03\x03\x8E\x9F.\x8B\xD7\xF3\xACF_y\xF5\x0F\x0Ea\x89\x866(g\xE2\xC1\xF5\x10Q\xC0Z/q~\xFC\x0F<\x00\x00\x1C\x8A\x8A\xC0+\xC0/\xC0,\xC00\xCC\xA9\xCC\xA8\xC0\x13\xC0\x14\x00\x9C\x00\x9D\x00/\x005\x00" 400 157 "-" "-" "-"
172.17.68.1 - - [11/Feb/2020:15:18:05 +0000] "GET / HTTP/1.1" 200 612 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36" "-"
2020/02/11 15:18:06 [error] 6#6: *3 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: 172.17.68.1, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "192.168.35.102:37434", referrer: "http://192.168.35.102:37434/"
172.17.68.1 - - [11/Feb/2020:15:18:06 +0000] "GET /favicon.ico HTTP/1.1" 404 555 "http://192.168.35.102:37434/" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36" "-"
[root@localhost ~]# kubectl logs nginx-7697996758-rtl66
172.17.68.1 - - [11/Feb/2020:15:15:20 +0000] "\x16\x03\x01\x02\x00\x01\x00\x01\xFC\x03\x03\xBB4f2\x22n\xC9b\xA4\xD9\x93\x8F\xFD\xBF\xF6\xE0}\xBF\x90\x17ev\xDDV\x8E\x08\x82\xA9\xD3}\xDD\xD7 \xB9\x0B\xD9Cf\xC7v\xCA\xC2P\xE50W\x0F#_\xEA\xB3\x03\xC7\x03\xDC\xB4\xC7/\xC4,C\x84\x8E\xAA\x00\x22\xBA\xBA\x13\x01\x13\x02\x13\x03\xC0+\xC0/\xC0,\xC00\xCC\xA9\xCC\xA8\xC0\x13\xC0\x14\x00\x9C\x00\x9D\x00/\x005\x00" 400 157 "-" "-" "-"
172.17.68.1 - - [11/Feb/2020:15:15:24 +0000] "\x16\x03\x01\x00\xB6\x01\x00\x00\xB2\x03\x031<\x22\x05Sc\xF8L\xA4e&\xE8$\xA9cj\xF0\xCBZ,\xCE\xDD\xFC\xA8>\x1F\xAF\xD4{\x03b\xF2\x00\x00\x1C::\xC0+\xC0/\xC0,\xC00\xCC\xA9\xCC\xA8\xC0\x13\xC0\x14\x00\x9C\x00\x9D\x00/\x005\x00" 400 157 "-" "-" "-"
[root@localhost ~]# kubectl logs nginx-7697996758-zghwr
172.17.45.1 - - [11/Feb/2020:15:12:38 +0000] "\x16\x03\x01\x02\x00\x01\x00\x01\xFC\x03\x03IG\x10\xC2\xE0[Pn\xF3j'D\xB9o\x09\x81\xBF!\xDCMg\xB5\x1B>\x15\xD6q\xD3H\xE3i< \x7F.\xBA\xF5\xD2\x16\xD4-m\x90`\x9D\xE9\xAC\xBE\x93\xF3\xEA4\xFEm#\xE3Tp{\xC1T\x82\x8D\xC4\x88\x00\x22JJ\x13\x01\x13\x02\x13\x03\xC0+\xC0/\xC0,\xC00\xCC\xA9\xCC\xA8\xC0\x13\xC0\x14\x00\x9C\x00\x9D\x00/\x005\x00" 400 157 "-" "-" "-"
172.17.45.1 - - [11/Feb/2020:15:13:05 +0000] "\x16\x03\x01\x02\x00\x01\x00\x01\xFC\x03\x03\x03`p\x1569A\x13\xF3\xCE\xAF\xA0'mO\xC2\xA2\xD4g" 400 157 "-" "-" "-"
172.17.45.1 - - [11/Feb/2020:15:13:26 +0000] "\x16\x03\x01\x02\x00\x01\x00\x01\xFC\x03\x03/\xF6\xF2=\xEF2rn\x07\x7F\x91\xC8V\x1BA\xE5\xCCyy\x5C\x8A*\xD6/[0\x5C\xC7\x0F\xE4*\xE1 '\xE1Y\x89\xF3\x5CZ<<0\xB3T\xFD5\xB1\xAE6\xD8A\xBCf\xEE\xAB;Ki\x0C\xB7\x9FX\x95'\x00\x22**\x13\x01\x13\x02\x13\x03\xC0+\xC0/\xC0,\xC00\xCC\xA9\xCC\xA8\xC0\x13\xC0\x14\x00\x9C\x00\x9D\x00/\x005\x00" 400 157 "-" "-" "-"
172.17.45.1 - - [11/Feb/2020:15:13:31 +0000] "\x16\x03\x01\x00\xB6\x01\x00\x00\xB2\x03\x03\x81\x13\xBA\xEB8\xF1i!\xDE.\x1Cx\xF3\x83w`>w\xE2\x07MOc\xE1K\xF6\x9A\xD8,\x1A" 400 157 "-" "-" "-"
172.17.45.1 - - [11/Feb/2020:15:13:38 +0000] "\x16\x03\x01\x02\x00\x01\x00\x01\xFC\x03\x03\xA31q\xCD\x89I\x80\xE2\x9E\xA5\xC7\xD0\xE3\xED\x0B\x88\xB5\x17\xA6\xCB\x22\x16\xDEMnmg`B\xC0\x9C8 \xB8\xFC\xDF\xED" 400 157 "-" "-" "-"
172.17.45.1 - - [11/Feb/2020:15:13:38 +0000] "\x16\x03\x01\x02\x00\x01\x00\x01\xFC\x03\x03\x10\xAA\x15\x86S\xE7\xAE\xFCZ\x86\x0B=\xA3\x9F\x06\x0E\xF6\x03\xFE\xA9\xD0\x8B\x84K\xA6t6q\xEA\x0B\xA9\xC0 \x9F\x5C\x148\x0F\x1A\x12\xD0\xC9\x05\xDF\x83g.\xA1}\xE9\x11\x9D\xDD\xBD\xA3\xED\x8D\x91U\xB2\xDBP\x10\xF6\x19\x00\x22\x1A\x1A\x13\x01\x13\x02\x13\x03\xC0+\xC0/\xC0,\xC00\xCC\xA9\xCC\xA8\xC0\x13\xC0\x14\x00\x9C\x00\x9D\x00/\x005\x00" 400 157 "-" "-" "-"
172.17.45.1 - - [11/Feb/2020:15:13:38 +0000] "\x16\x03\x01\x00\xB6\x01\x00\x00\xB2\x03\x03;\xBC6\x22\x91\x1D8\xC3_\xC2|DR\xCA\x02)\xD1|z\xFEU\x8B\x02\xDA\xADsa\xBF\x91\x03\xA5\xDA\x00\x00\x1C::\xC0+\xC0/\xC0,\xC00\xCC\xA9\xCC\xA8\xC0\x13\xC0\x14\x00\x9C\x00\x9D\x00/\x005\x00" 400 157 "-" "-" "-"
172.17.45.1 - - [11/Feb/2020:15:13:40 +0000] "\x16\x03\x01\x02\x00\x01\x00\x01\xFC\x03\x03 j\xEBO\x8C\xBBh\xF1\x8C\xAD{Bl\x16\xB0`<7\xD6\xD8\xE3{d\xC8\xF15U\x87\x81\x84\xB4, \x0Bh}\x7FG\xCB\xEBq\x96\x8Dd^\x95\x8B\x92\x87N\x5CQ\xB7\x1E\x8A\xE1Ja,N?j\xEA\xEBA\x00\x22**\x13\x01\x13\x02\x13\x03\xC0+\xC0/\xC0,\xC00\xCC\xA9\xCC\xA8\xC0\x13\xC0\x14\x00\x9C\x00\x9D\x00/\x005\x00" 400 157 "-" "-" "-"
172.17.45.1 - - [11/Feb/2020:15:14:17 +0000] "\x16\x03\x01\x02\x00\x01\x00\x01\xFC\x03\x03x\xCF\x99H\x1C\xCB\xA0\xB9\x974\x0C\xCE\xCDpG\x9B\xFF\xD9s\xF6\x11$i\xD9 \x1D\x86\xBD\xE5F\xEE\xC5 \xD5D\xBFu\xF60\xE4\xD0\x0BF\xF5a\xEDD\x1F\x97\xA1DmK\xF23|J\x07\xB7K\xB9\xF3\x87?\x1F\x00\x22zz\x13\x01\x13\x02\x13\x03\xC0+\xC0/\xC0,\xC00\xCC\xA9\xCC\xA8\xC0\x13\xC0\x14\x00\x9C\x00\x9D\x00/\x005\x00" 400 157 "-" "-" "-"
172.17.45.1 - - [11/Feb/2020:15:14:17 +0000] "\x16\x03\x01\x02\x00\x01\x00\x01\xFC\x03\x03\xEF\xAB<\x07\xF3\xE7\xC9\xAD\xBCg\xC73w\x12\xB5\xA1" 400 157 "-" "-" "-"
172.17.45.1 - - [11/Feb/2020:15:17:43 +0000] "GET / HTTP/1.1" 200 612 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36" "-"
2020/02/11 15:17:43 [error] 6#6: *11 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: 172.17.45.1, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "192.168.35.101:37434", referrer: "http://192.168.35.101:37434/"
172.17.45.1 - - [11/Feb/2020:15:17:43 +0000] "GET /favicon.ico HTTP/1.1" 404 555 "http://192.168.35.101:37434/" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36" "-"
更新nginx 为1.14版本
(1)谷歌浏览器重新加载刷新页面查看nginx版本信息
kubecl set命令
[root@localhost ~]# kubectl set --help
Configure application resourcesThese commands help you make changes to existing application resources.
Available Commands:
env Update environment variables on a pod template
image 更新一个 pod template 的镜像
resources 在对象的 pod templates 上更新资源的 requests/limits
selector 设置 resource 的 selector
serviceaccount Update ServiceAccount of a resource
subject Update User, Group or ServiceAccount in a
RoleBinding/ClusterRoleBindingUsage:
kubectl set SUBCOMMAND [options]Use "kubectl
--help" for more information about a given command.
Use "kubectl options" for a list of global command-line options (applies to all
commands).
(2)获取修改模板
[root@localhost ~]# kubectl set image --help
Examples:
# Set a deployment's nginx container image to 'nginx:1.9.1', and its busybox
container image to 'busybox'.
kubectl set image deployment/nginx busybox=busybox nginx=nginx:1.9.1
(3)更新
[root@localhost bin]# kubectl set image deployment/nginx nginx=nginx:1.14
deployment.extensions/nginx image updated
[root@localhost ~]# kubectl get pods -w
NAME READY STATUS RESTARTS AGE
nginx-6ff7c89c7c-cbrth 0/1 ContainerCreating 0 14s
nginx-7697996758-d6l5w 1/1 Running 0 179m
nginx-7697996758-rtl66 1/1 Running 0 179m
nginx-7697996758-zghwr 1/1 Running 0 179m
nginx-6ff7c89c7c-cbrth 1/1 Running 0 39s
nginx-7697996758-d6l5w 1/1 Terminating 0 179m
nginx-6ff7c89c7c-fdfdv 0/1 Pending 0 0s
nginx-6ff7c89c7c-fdfdv 0/1 Pending 0 0s
nginx-6ff7c89c7c-fdfdv 0/1 ContainerCreating 0 0s
nginx-7697996758-d6l5w 0/1 Terminating 0 179m
nginx-7697996758-d6l5w 0/1 Terminating 0 179m
nginx-7697996758-d6l5w 0/1 Terminating 0 179m
nginx-6ff7c89c7c-fdfdv 1/1 Running 0 27s
nginx-7697996758-rtl66 1/1 Terminating 0 179m
nginx-6ff7c89c7c-2bfhh 0/1 Pending 0 0s
nginx-6ff7c89c7c-2bfhh 0/1 Pending 0 0s
nginx-6ff7c89c7c-2bfhh 0/1 ContainerCreating 0 0s
nginx-7697996758-rtl66 0/1 Terminating 0 179m
nginx-7697996758-rtl66 0/1 Terminating 0 3h
nginx-7697996758-rtl66 0/1 Terminating 0 3h
nginx-6ff7c89c7c-2bfhh 1/1 Running 0 17s
nginx-7697996758-zghwr 1/1 Terminating 0 3h
nginx-7697996758-zghwr 0/1 Terminating 0 3h
nginx-7697996758-zghwr 0/1 Terminating 0 3h
nginx-7697996758-zghwr 0/1 Terminating 0 3h
(4)Ctrl+c中断监听,更新速度快
[root@localhost ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-6ff7c89c7c-2bfhh 1/1 Running 0 117s
nginx-6ff7c89c7c-cbrth 1/1 Running 0 3m3s
nginx-6ff7c89c7c-fdfdv 1/1 Running 0 2m24s
(5)再回到浏览器界面,重新加载,查看版本号
kubectl rollout命令
[root@localhost ~]# kubectl rollout --help
Manage the rollout of a resource.
Valid resource types include:* deployments
* daemonsets
* statefulsetsExamples:
# Rollback to the previous deployment
kubectl rollout undo deployment/abc
# Check the rollout status of a daemonset
kubectl rollout status daemonset/fooAvailable Commands:
history 显示 rollout 历史
pause 标记提供的 resource 为中止状态
resume 继续一个停止的 resource
status 显示 rollout 的状态
undo 撤销上一次的 rolloutUsage:
kubectl rollout SUBCOMMAND [options]Use "kubectl
--help" for more information about a given command.
Use "kubectl options" for a list of global command-line options (applies to all commands).
(1)查看历史版本
[root@localhost ~]# kubectl rollout history deployment/nginx
deployment.extensions/nginx
REVISION CHANGE-CAUSE
1
2
(2)执行回滚
[root@localhost ~]# kubectl rollout undo deployment/nginx
deployment.extensions/nginx
(3)检查回滚状态
[root@localhost ~]# kubectl rollout status deployment/nginx
Waiting for deployment "nginx" rollout to finish: 1 old replicas are pending termination...
Waiting for deployment "nginx" rollout to finish: 1 old replicas are pending termination...
deployment "nginx" successfully rolled out
(4)回到浏览器界面,重新加载,查看版本号
kubectl delete命令
(1)删除nginx
[root@localhost ~]# kubectl get deploy #查看deployment
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
nginx 3 3 3 3 3h18m[root@localhost ~]# kubectl delete deployment/nginx
deployment.extensions "nginx" deleted[root@localhost ~]# kubectl get deploy #再查看,删除成功
No resources found.
(2)删除服务svc
[root@localhost ~]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.0.0.1443/TCP 3d10h
nginx-service NodePort 10.0.0.12180:37434/TCP 177m
[root@localhost ~]# kubectl delete svc/nginx-service
service "nginx-service" deleted
[root@localhost ~]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.0.0.1443/TCP 3d10h