Kubernetes 的命令管理

标签(空格分隔): kubernetes系列


  • 一: kubernetes 的命令介绍
  • 二: kubernetes 的 生命周期管理
  • 三: kubernetes 的远程连接处理

一: kubernetes的命令的介绍

image_1dbriuljtjvneo1s6fmf1pnd19.png-1011.5kB

kubectl get all

image_1dbrjis441cu61kb71714rs2186h9.png-263.2kB

kubectl get all -o wide 

image_1dbrjlh6tj2fqfqg6o2foaj71m.png-315kB

kubectl get all -o wide -n kube-system

image_1dbrjn0281kr11o4u1sgag45mds23.png-326.1kB

kubectl get pods,svc,nodes -o wide -n kube-system --all-namespaces

image_1dksecpqj13s31tmvutq14241vdf9.png-565.8kB


二: kubernetes 部署项目的 生命周期

kubectl 部署一个nginx 

1、创建
kubectl run nginx --replicas=3 --image=nginx:1.14 --port=80
kubectl get deploy,pods

2、发布
kubectl expose deployment nginx --port=80 --type=NodePort --target-port=80 --name=nginx-service
kubectl get service

3、更新
kubectl set image deployment/nginx nginx=nginx:1.15

4、回滚

kubectl rollout history deployment/nginx
kubectl rollout undo deployment/nginx

kubectl rollout undo deployment/nginx --to-revision=1

5、删除

kubectl delete deploy/nginx
kubectl delete svc/nginx-service

image_1dbrvefpcn2c1bk21ptdk6666hm.png-266.4kB

image_1dbrvdh8011gk16bg1ubgfm41l6o9.png-356.3kB

image_1dbrvofrq5lu1eq7bph1o4k14j9.png-370.3kB

image_1dbrvuia11g448g31qle1ekc1tp51m.png-123.5kB

image_1dbrvv4lq1s35c0q2af19pdr2i23.png-238.6kB

8.png-117.6kB

9.png-475.8kB

12.png-498.9kB


三: kubernetes 的 远程连接

3.1 生成config 文件

login:192.168.100.11 master 节点
cd /opt/kubernetes/ssl

vim config.sh
----
kubectl config set-cluster kubernetes \
  --certificate-authority=ca.pem \
  --embed-certs=true \
  --server=https://192.168.100.11:6443 \
  --kubeconfig=config

kubectl config set-credentials cluster-admin \
  --certificate-authority=ca.pem \
  --embed-certs=true \
  --client-key=admin-key.pem \
  --client-certificate=admin.pem \
  --kubeconfig=config

kubectl config set-context default --cluster=kubernetes --user=cluster-admin --kubeconfig=config
kubectl config use-context default --kubeconfig=config
----

./config.sh

生成config 文件

scp config root@192.168.100.13:/root
login : 192.168.100.13 node 节点

kubectl --kubeconfig=./config get pods 

image_1dksk79frmm1jfjdsv167qr9716.png-263.5kB

image_1dksk7usi2mg14j3gfhouj1rps1j.png-233.8kB

image_1dkskauk510ve67m8g018mu1e5u9.png-463.1kB

image_1dksm21mk1phnnc11cm310fg1r5r25.png-310.1kB

mv config /root/.kube/

kubectl get node

image_1dksm6e1faet13lijje1rk5dp72i.png-185.3kB