kubernetes入门学习-四-基本命令学习-service ip了解-动态伸缩-回滚

------------------------------------------
kubectl命令:通过此命令对pod、service、replicaset、statefulet、daemonset、job、cronjob、node等完成增删查。
[root@master ~]# kubectl
kubectl controls the Kubernetes cluster manager. 

Find more information at: https://kubernetes.io/docs/reference/kubectl/overview/

Basic Commands (Beginner):
  create         Create a resource from a file or from stdin.
  expose         Take a replication controller, service, deployment or pod and expose it as a new Kubernetes Service
  run            Run a particular image on the cluster
  set            Set specific features on objects

Basic Commands (Intermediate):
  explain        Documentation of resources
  get            Display one or many resources
  edit           Edit a resource on the server
  delete         Delete resources by filenames, stdin, resources and names, or by resources and label selector

Deploy Commands:
  rollout        Manage the rollout of a resource
  scale          Set a new size for a Deployment, ReplicaSet, Replication Controller, or Job
  autoscale      Auto-scale a Deployment, ReplicaSet, or ReplicationController

Cluster Management Commands:
  certificate    Modify certificate resources.
  cluster-info   Display cluster info
  top            Display Resource (CPU/Memory/Storage) usage.
  cordon         Mark node as unschedulable
  uncordon       Mark node as schedulable
  drain          Drain node in preparation for maintenance
  taint          Update the taints on one or more nodes   污点

Troubleshooting and Debugging Commands:  解决问题的
  describe       Show details of a specific resource or group of resources
  logs           Print the logs for a container in a pod
  attach         Attach to a running container
  exec           Execute a command in a container
  port-forward   Forward one or more local ports to a pod
  proxy          Run a proxy to the Kubernetes API server
  cp             Copy files and directories to and from containers.
  auth           Inspect authorization

Advanced Commands:
  diff           Diff live version against would-be applied version
  apply          Apply a configuration to a resource by filename or stdin
  patch          Update field(s) of a resource using strategic merge patch
  replace        Replace a resource by filename or stdin
  wait           Experimental: Wait for a specific condition on one or many resources.
  convert        Convert config files between different API versions

Settings Commands:
  label          Update the labels on a resource
  annotate       Update the annotations on a resource
  completion     Output shell completion code for the specified shell (bash or zsh)

Other Commands:
  api-resources  Print the supported API resources on the server
  api-versions   Print the supported API versions on the server, in the form of "group/version"
  config         Modify kubeconfig files
  plugin         Provides utilities for interacting with plugins.
  version        Print the client and server version information

Usage:
  kubectl [flags] [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).
==========================================
查看版本信息
kubectl version
查看集群信息
kubectl cluster-info
查看节点详细信息
kubectl describe node master/node01/node02
kubectl describe svc nginx
查看pod
kubectl get pods/nodes
kubectl get pods -o wide
kubectl get deployments

删除pod
kubectl delete pod nginx-deploy-84cbfc56b6-9h9wm
kubectl delete pod nginx-5c7588df-9xvbn
kubectl delete svc nginx-deploy
kubectl delete deployment wolf

kubectl get pods -o yaml | kubectl delete -f -  删除全部
创建控制器
kubectl run --help
kubectl run nginx-deploy --image=nginx:1.14-alpine --port=80 --replicas=1 --dry-run=true
kubectl run nginx --image=nginx:1.14-alpine --port=80 --replicas=2

kubectl create deployment nginx --image=nginx
kubectl expose deployment nginx --port=80 --type=NodePort


kubectl run client --image=busybox --replicas=1 -it --restart=Never
kubectl run wolf --image=busybox --replicas=2

暴露端口
kubectl expose deployment nginx-deploy --name=nginx-deploy --port=80 --protocol=TCP

动态伸缩
kubectl scale --replicas=5 deployment nginx
kubectl scale --replicas=3 deployment nginx

滚动升级
kubectl set image deployment nginx nginx=nginx  这个环境没准备容器,感受一下过程
kubectl rollout status deployment nginx

默认回滚到上一个版本
kubectl rollout undo deployment nginx
-----------------------------------------
service_ip:service_pod---->pod_ip:port_port  
被集群内部访问
Type for this service: ClusterIP, NodePort, LoadBalancer, or ExternalName. Default is 'ClusterIP'
kubectl expose --help
kubectl expose deployment nginx-deploy --name=nginx-deploy --port=80 --protocol=TCP
kubectl get pod,svc

------------------------------------------
修改镜像站
kubeadm config images pull --config image.yaml
------------------------------------------
测试
[root@master ingress-nginx]# kubectl version
Client Version: version.Info{Major:"1", Minor:"13", GitVersion:"v1.13.3", GitCommit:"721bfa751924da8d1680787490c54b9179b1fed0", GitTreeState:"clean", BuildDate:"2019-02-01T20:08:12Z", GoVersion:"go1.11.5", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"13", GitVersion:"v1.13.3", GitCommit:"721bfa751924da8d1680787490c54b9179b1fed0", GitTreeState:"clean", BuildDate:"2019-02-01T20:00:57Z", GoVersion:"go1.11.5", Compiler:"gc", Platform:"linux/amd64"}
[root@master ingress-nginx]# kubectl cluster-info
Kubernetes master is running at https://10.249.6.100:6443
KubeDNS is running at https://10.249.6.100:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
[root@master ingress-nginx]# kubectl describe node master
Name:               master
Roles:              master
Labels:             beta.kubernetes.io/arch=amd64
                    beta.kubernetes.io/os=linux
                    kubernetes.io/hostname=master
                    node-role.kubernetes.io/master=
Annotations:        flannel.alpha.coreos.com/backend-data: {"VtepMAC":"6a:63:a1:96:b6:66"}
                    flannel.alpha.coreos.com/backend-type: vxlan
                    flannel.alpha.coreos.com/kube-subnet-manager: true
                    flannel.alpha.coreos.com/public-ip: 10.249.6.100
                    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:  Thu, 28 Feb 2019 06:23:41 -0500
Taints:             node-role.kubernetes.io/master:NoSchedule
Unschedulable:      false
Conditions:
  Type             Status  LastHeartbeatTime                 LastTransitionTime                Reason                       Message
  ----             ------  -----------------                 ------------------                ------                       -------
  MemoryPressure   False   Thu, 28 Feb 2019 09:29:34 -0500   Thu, 28 Feb 2019 06:23:33 -0500   KubeletHasSufficientMemory   kubelet has sufficient memory available
  DiskPressure     False   Thu, 28 Feb 2019 09:29:34 -0500   Thu, 28 Feb 2019 06:23:33 -0500   KubeletHasNoDiskPressure     kubelet has no disk pressure
  PIDPressure      False   Thu, 28 Feb 2019 09:29:34 -0500   Thu, 28 Feb 2019 06:23:33 -0500   KubeletHasSufficientPID      kubelet has sufficient PID available
  Ready            True    Thu, 28 Feb 2019 09:29:34 -0500   Thu, 28 Feb 2019 06:41:02 -0500   KubeletReady                 kubelet is posting ready status
Addresses:
  InternalIP:  10.249.6.100
  Hostname:    master
Capacity:
 cpu:                40
 ephemeral-storage:  266110Mi
 hugepages-1Gi:      0
 hugepages-2Mi:      0
 memory:             32612544Ki
 pods:               110
Allocatable:
 cpu:                40
 ephemeral-storage:  251132903009
 hugepages-1Gi:      0
 hugepages-2Mi:      0
 memory:             32510144Ki
 pods:               110
System Info:
 Machine ID:                 904f126630e44103b404c0adc7b66d6f
 System UUID:                4C023761-E90B-E611-9DB5-7CD30AB13074
 Boot ID:                    e316bea7-ec44-4d1e-b9b6-e46e0cd74087
 Kernel Version:             3.10.0-693.el7.x86_64
 OS Image:                   CentOS Linux 7 (Core)
 Operating System:           linux
 Architecture:               amd64
 Container Runtime Version:  docker://18.9.2
 Kubelet Version:            v1.13.3
 Kube-Proxy Version:         v1.13.3
PodCIDR:                     10.244.0.0/24
Non-terminated Pods:         (8 in total)
  Namespace                  Name                              CPU Requests  CPU Limits  Memory Requests  Memory Limits  AGE
  ---------                  ----                              ------------  ----------  ---------------  -------------  ---
  kube-system                coredns-86c58d9df4-fltl9          100m (0%)     0 (0%)      70Mi (0%)        170Mi (0%)     3h5m
  kube-system                coredns-86c58d9df4-kdm2h          100m (0%)     0 (0%)      70Mi (0%)        170Mi (0%)     3h5m
  kube-system                etcd-master                       0 (0%)        0 (0%)      0 (0%)           0 (0%)         3h4m
  kube-system                kube-apiserver-master             250m (0%)     0 (0%)      0 (0%)           0 (0%)         3h4m
  kube-system                kube-controller-manager-master    200m (0%)     0 (0%)      0 (0%)           0 (0%)         3h4m
  kube-system                kube-flannel-ds-amd64-px2rk       100m (0%)     100m (0%)   50Mi (0%)        50Mi (0%)      168m
  kube-system                kube-proxy-zndjb                  0 (0%)        0 (0%)      0 (0%)           0 (0%)         3h5m
  kube-system                kube-scheduler-master             100m (0%)     0 (0%)      0 (0%)           0 (0%)         3h4m
Allocated resources:
  (Total limits may be over 100 percent, i.e., overcommitted.)
  Resource           Requests    Limits
  --------           --------    ------
  cpu                850m (2%)   100m (0%)
  memory             190Mi (0%)  390Mi (1%)
  ephemeral-storage  0 (0%)      0 (0%)
Events:              

查看系统内部组件信息
[root@master ingress-nginx]# kubectl get pods -n kube-system -o wide
NAME                             READY   STATUS    RESTARTS   AGE     IP             NODE     NOMINATED NODE   READINESS GATES
coredns-86c58d9df4-fltl9         1/1     Running   0          4h      10.244.0.3     master            
coredns-86c58d9df4-kdm2h         1/1     Running   0          4h      10.244.0.2     master            
etcd-master                      1/1     Running   0          3h59m   10.249.6.100   master            
kube-apiserver-master            1/1     Running   0          3h59m   10.249.6.100   master            
kube-controller-manager-master   1/1     Running   0          3h59m   10.249.6.100   master            
kube-flannel-ds-amd64-78tgg      1/1     Running   0          3h43m   10.249.6.102   node02            
kube-flannel-ds-amd64-px2rk      1/1     Running   1          3h43m   10.249.6.100   master            
kube-flannel-ds-amd64-qdbzq      1/1     Running   1          3h43m   10.249.6.101   node01            
kube-proxy-6fp6m                 1/1     Running   0          3h50m   10.249.6.102   node02            
kube-proxy-wv6gg                 1/1     Running   0          3h50m   10.249.6.101   node01            
kube-proxy-zndjb                 1/1     Running   0          4h      10.249.6.100   master            
kube-scheduler-master            1/1     Running   0          3h59m   10.249.6.100   master            
[root@master ingress-nginx]# kubectl get svc -n kube-system
NAME       TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)         AGE
kube-dns   ClusterIP   10.96.0.10          53/UDP,53/TCP   4h4m
------------------------------------------
创建控制器
[root@master ingress-nginx]#kubectl run --help
[root@master ingress-nginx]#kubectl run nginx-deploy --image=nginx:1.14-alpine --port=80 --replicas=1 --dry-run=true
[root@master ingress-nginx]#kubectl run nginx-deploy --image=nginx:1.14-alpine --port=80 --replicas=1
[root@master ingress-nginx]# kubectl get pods
NAME                            READY   STATUS    RESTARTS   AGE
nginx-5c7588df-9xvbn            1/1     Running   0          44m
nginx-deploy-84cbfc56b6-9h9wm   1/1     Running   0          59s

[root@master ingress-nginx]# kubectl get pods -o wide
NAME                            READY   STATUS    RESTARTS   AGE     IP           NODE     NOMINATED NODE   READINESS GATES
nginx-5c7588df-9xvbn            1/1     Running   0          46m     10.244.2.2   node02            
nginx-deploy-84cbfc56b6-9h9wm   1/1     Running   0          2m40s   10.244.2.3   node02            

[root@node01 ~]# curl 10.244.2.2



Welcome to nginx!



Welcome to nginx!


If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.

For online documentation and support please refer to
nginx.org.

Commercial support is available at
nginx.com.

pods名称全部改变
[root@master ~]# kubectl get pods
NAME                            READY   STATUS    RESTARTS   AGE
nginx-775ff75bc8-lzrts          1/1     Running   0          2m58s
nginx-775ff75bc8-nj2m6          1/1     Running   0          2m56s
nginx-775ff75bc8-q857h          1/1     Running   0          3m
nginx-deploy-84cbfc56b6-mjcw5   1/1     Running   0          74m

默认回滚到上一个版本
kubectl rollout undo deployment nginx
[root@master ~]# kubectl rollout undo deployment nginx
deployment.extensions/nginx rolled back

 

群名称:k8s学习群   群   号:153144292

你可能感兴趣的:(devops,kubenetes)