1. 程式人生 > >kubernetes應用入門

kubernetes應用入門

指定 let 對象 mes 8.0 ast res svc names

一、kubernetes資源對象

  • pod
  • serivce
  • replicaset
  • deployment
  • statefulet
  • daemonset
  • job
  • cronjob
  • node

二、kubectl命令

  • Basic Commands
  • Deploy Commands
  • Cluster Management Commands
  • Troubleshooting and Debugging Commands
  • Advanced Commands
  • Settings Commands
  • Other Commands

1、常用命令

# kubectl describe node master.k8s.com  #獲取節點的詳細信息
# kubectl version  #獲取版本信息
# kubectl cluster-info  #獲取集群信息

2、創建pod

# kubectl run nginx-deploy --image=nginx:1.14-alpine --port=80 --replicas=1
# kubectl get deployment
# kubectl get pods -o wide
# 
# kubectl run client --image=busybox --replicas=1 -it --restart=Never

--image=nginx:1.14-alpine 指定鏡像

--port=80 暴露端口

--replicas=1 創建1個副本

3、刪除pod

# kubectl delete pods nginx-deploy-86bf78c77-h594c

4、創建service

# kubectl expose deployment nginx-deploy --name=nginx --port=80 --target-port=80 --protocol=TCP
# kubectl get svc
# kubectl describe svc nginx
# kubectl get svc -n kube-system  #查看DNS
# kubectl get svc --all-namespaces

5、編輯對象

# kubectl edit svc nginx

6、刪除service

# kubectl delete svc nginx

7、擴展/縮減pod規模

# kubectl scale --replicas=5 deployment myapp

8、滾動/回滾pod版本

# kubectl set image deployment myapp myapp=ikubernetes/myapp:v2
# kubectl rollout status deployment myapp  #查看更新過程
# kubectl rollout undo deployment myapp
# kubectl describe pods myapp-xxx

9、外部訪問

# kubectl edit svc nginx  #將type修改為NodePort
  type: NodePort
# kubectl get svc
訪問:http://192.168.0.9:30155/

kubernetes應用入門