iT邦幫忙

第 11 屆 iThome 鐵人賽

DAY 13
0
DevOps

Cloud Native 開發維運一條龍系列 第 13

Day 13. Kubernetes POD 基本操作

Pod and A Group of Pods

in ~/.bashrc

alias kubewatch='watch -n 1 -d kubectl get ingress,svc,deploy,po'

create simple app

adhoc way

$ kubectl create deployment nginx --image=nginx
$ kubectl expose deployment/nginx --port=80
$ kubectl get svc,deploy,po -l app=nginx

how to inspect resource

$ kubectl edit <the resource>
$ kubectl get deployment nginx -o yaml

scale up

$ kubectl scale deployment nginx --replicas=3

set image

$ kubectl set image deploy nginx=nginx:1.9.1 --all
$ kubectl set image deploy nginx=nginx:1.12.1-alpine --all

rollout

$ kubectl rollout history deploy nginx
$ kubectl rollout history deploy nginx --revision=2
$ kubectl rollout undo deploy/nginx --revision=1

daemonset

先看一個乾淨的 deployment,快速得到的方式:

$ kubectl create deployment nginx --image=nginx --dry-run -o yaml > nginx-deploy.yaml

命名 nginx-deploy.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: nginx
  name: nginx
spec:
  replicas: 2
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - image: nginx
        name: nginx

然後改成 daemonset,命名 nginx-daemon.yaml

apiVersion: apps/v1
kind: DaemonSet
metadata:
  labels:
    app: nginx
  name: nginx
spec:
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - image: nginx
        name: nginx

查看兩個檔案的差異

$ diff nginx-deploy.yaml nginx-daemon.yaml 
2c2
< kind: Deployment
---
> kind: DaemonSet
8d7
<   replicas: 2

確認 daemonset 是否部署在每個 node 上


上一篇
Day 12. 使用 Kubeadm 安裝 Kubernetes
下一篇
Day 14. Kubernetes Network 基本操作
系列文
Cloud Native 開發維運一條龍18
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言