Kubernetes:修订间差异

来自Gea-Suan Lin's Wiki
跳到导航 跳到搜索
此页面具有访问限制。如果您看见此消息,则说明您没有权限访问此页面。
第51行: 第51行:
kubectl label nodes ip-172-31-1-1 instancetype=c5
kubectl label nodes ip-172-31-1-1 instancetype=c5
kubectl label nodes ip-172-31-1-2 ip-172-31-1-3 ip-172-31-1-4 ip-172-31-1-5 ip-172-31-1-6 instancetype=r5
kubectl label nodes ip-172-31-1-2 ip-172-31-1-3 ip-172-31-1-4 ip-172-31-1-5 ip-172-31-1-6 instancetype=r5
</syntaxhighlight>
== 範例 ==
<syntaxhighlight lang="yaml">
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: example-r5
spec:
  replicas: 5
  serviceName: example-r5
  selector:
   matchLabels:
    app: example-r5
  template:
   metadata:
    labels:
     app: example-r5
   spec:
    containers:
    - name: example-r5
     image: ubuntu:18.04
     command: ["/bin/sh", "-c"]
     args:
      - export DEBIAN_FRONTEND=noninteractive;
       sed -i 's/archive.ubuntu.com/us.archive.ubuntu.com/' /etc/apt/sources.list;
       apt update;
       apt install -y iproute2 iputils-ping locales mtr-tiny net-tools tzdata wget;
       sleep 3153600000
     resources:
      requests:
       memory: "15Gi"
    nodeSelector:
     instancetype: r5
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: example-c5
spec:
  replicas: 1
  serviceName: example-c5
  selector:
   matchLabels:
    app: example-c5
  template:
   metadata:
    labels:
     app: example-c5
   spec:
    containers:
    - name: example-c5
     image: ubuntu:18.04
     command: ["/bin/sh", "-c"]
     args:
      - export DEBIAN_FRONTEND=noninteractive;
       sed -i 's/archive.ubuntu.com/us.archive.ubuntu.com/' /etc/apt/sources.list;
       apt update;
       apt install -y iproute2 iputils-ping locales mtr-tiny net-tools tzdata wget;
       sleep 3153600000
     resources:
      requests:
       cpu: "7000m"
    nodeSelector:
     instancetype: c5
</syntaxhighlight>
</syntaxhighlight>



2018年12月31日 (一) 18:05的版本

Kubernetes是一套由Google所發展出來的佈署系統。

安裝

先安裝Docker,然後安裝Kubernetes的套件:

curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -; echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list; sudo apt update; sudo apt install -y kubelet kubeadm kubectl

設定

這邊使用Calico當作網路層:

sudo kubeadm init --pod-network-cidr=192.168.0.0/16

把上面執行結果輸出的命令拿到別台用sudo跑。

接著回到當初跑kubeadm init的機器上,把設定檔放到自己目錄下:

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

接下來啟用Calico設定:

kubectl apply -f https://docs.projectcalico.org/v3.3/getting-started/kubernetes/installation/hosted/rbac-kdd.yaml
kubectl apply -f https://docs.projectcalico.org/v3.3/getting-started/kubernetes/installation/hosted/kubernetes-datastore/calico-networking/1.7/calico.yaml

設定好之後不會馬上通,可以用kubectl get nodes --watch可以看到機器會因為retry從NotReady變成Ready

使用所有主機

一開始的主機(master)不會被分配到需求(因為安全因素),透過以下的指令讓master可以分配到需求:

kubectl taint nodes --all node-role.kubernetes.io/master-

標籤

可以針對主機進行標籤,供之後使用:

kubectl label nodes ip-172-31-1-1 instancetype=c5
kubectl label nodes ip-172-31-1-2 ip-172-31-1-3 ip-172-31-1-4 ip-172-31-1-5 ip-172-31-1-6 instancetype=r5

範例

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: example-r5
spec:
  replicas: 5
  serviceName: example-r5
  selector:
    matchLabels:
      app: example-r5
  template:
    metadata:
      labels:
        app: example-r5
    spec:
      containers:
      - name: example-r5
        image: ubuntu:18.04
        command: ["/bin/sh", "-c"]
        args:
          - export DEBIAN_FRONTEND=noninteractive;
            sed -i 's/archive.ubuntu.com/us.archive.ubuntu.com/' /etc/apt/sources.list;
            apt update;
            apt install -y iproute2 iputils-ping locales mtr-tiny net-tools tzdata wget;
            sleep 3153600000
        resources:
          requests:
            memory: "15Gi"
      nodeSelector:
        instancetype: r5
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: example-c5
spec:
  replicas: 1
  serviceName: example-c5
  selector:
    matchLabels:
      app: example-c5
  template:
    metadata:
      labels:
        app: example-c5
    spec:
      containers:
      - name: example-c5
        image: ubuntu:18.04
        command: ["/bin/sh", "-c"]
        args:
          - export DEBIAN_FRONTEND=noninteractive;
            sed -i 's/archive.ubuntu.com/us.archive.ubuntu.com/' /etc/apt/sources.list;
            apt update;
            apt install -y iproute2 iputils-ping locales mtr-tiny net-tools tzdata wget;
            sleep 3153600000
        resources:
          requests:
            cpu: "7000m"
      nodeSelector:
        instancetype: c5

外部連結