|
| 1 | +--- |
| 2 | +title: Atribuindo Pods aos nós usando afinidade de nó |
| 3 | +min-kubernetes-server-version: v1.10 |
| 4 | +content_type: task |
| 5 | +weight: 160 |
| 6 | +--- |
| 7 | + |
| 8 | +<!-- overview --> |
| 9 | +Esta página mostra como atribuir um Pod kubernetes a um nó particular em um |
| 10 | +cluster Kubernetes utilizando afinidade de nó. |
| 11 | + |
| 12 | + |
| 13 | +## {{% heading "prerequisites" %}} |
| 14 | + |
| 15 | + |
| 16 | +{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}} |
| 17 | + |
| 18 | + |
| 19 | + |
| 20 | +<!-- steps --> |
| 21 | + |
| 22 | +## Adicione um label a um nó |
| 23 | + |
| 24 | +1. Liste os nós em seu cluster, juntamente com seus labels: |
| 25 | + |
| 26 | + ```shell |
| 27 | + kubectl get nodes --show-labels |
| 28 | + ``` |
| 29 | + A saída é semelhante a esta: |
| 30 | + |
| 31 | + ```shell |
| 32 | + NAME STATUS ROLES AGE VERSION LABELS |
| 33 | + worker0 Ready <none> 1d v1.13.0 ...,kubernetes.io/hostname=worker0 |
| 34 | + worker1 Ready <none> 1d v1.13.0 ...,kubernetes.io/hostname=worker1 |
| 35 | + worker2 Ready <none> 1d v1.13.0 ...,kubernetes.io/hostname=worker2 |
| 36 | + ``` |
| 37 | +2. Escolha um de seus nós e adicione um label a ele: |
| 38 | + |
| 39 | + ```shell |
| 40 | + kubectl label nodes <your-node-name> disktype=ssd |
| 41 | + ``` |
| 42 | + onde `<your-node-name>` é o nome do seu nó escolhido. |
| 43 | + |
| 44 | +3. Verifique se seu nó escolhido tem o label `disktype=ssd`: |
| 45 | + |
| 46 | + ```shell |
| 47 | + kubectl get nodes --show-labels |
| 48 | + ``` |
| 49 | + |
| 50 | + A saída é semelhante a esta: |
| 51 | + |
| 52 | + ``` |
| 53 | + NAME STATUS ROLES AGE VERSION LABELS |
| 54 | + worker0 Ready <none> 1d v1.13.0 ...,disktype=ssd,kubernetes.io/hostname=worker0 |
| 55 | + worker1 Ready <none> 1d v1.13.0 ...,kubernetes.io/hostname=worker1 |
| 56 | + worker2 Ready <none> 1d v1.13.0 ...,kubernetes.io/hostname=worker2 |
| 57 | + ``` |
| 58 | + |
| 59 | + Na saída anterior, você pode ver que o nó `worker0` tem o label |
| 60 | + `disktype=ssd`. |
| 61 | + |
| 62 | +## Alocar um Pod usando afinidade de nó obrigatória |
| 63 | + |
| 64 | +Este manifesto descreve um Pod que possui uma afinidade de nó `requiredDuringSchedulingIgnoredDuringExecution` com o label `disktype: ssd`. |
| 65 | +Isso significa que o Pod será alocado apenas em um nó que tenha o label `disktype=ssd`. |
| 66 | + |
| 67 | +{{% code_sample file="pods/pod-nginx-required-affinity.yaml" %}} |
| 68 | + |
| 69 | +1. Aplique o manifesto para criar um Pod que será alocado no nó escolhido: |
| 70 | + |
| 71 | + ```shell |
| 72 | + kubectl apply -f https://k8s.io/examples/pods/pod-nginx-required-affinity.yaml |
| 73 | + ``` |
| 74 | + |
| 75 | +2. Verifique se o Pod está executando no nó escolhido: |
| 76 | + |
| 77 | + ```shell |
| 78 | + kubectl get pods --output=wide |
| 79 | + ``` |
| 80 | + |
| 81 | + A saída é semelhante a esta: |
| 82 | + |
| 83 | + ``` |
| 84 | + NAME READY STATUS RESTARTS AGE IP NODE |
| 85 | + nginx 1/1 Running 0 13s 10.200.0.4 worker0 |
| 86 | + ``` |
| 87 | + |
| 88 | +## Alocar um Pod usando afinidade de nó preferencial |
| 89 | + |
| 90 | +Este manifesto descreve um Pod que possui uma afinidade de nó `requiredDuringSchedulingIgnoredDuringExecution` com o label `disktype: ssd`. |
| 91 | +Isso significa que o Pod será alocado de preferência em um nó com o label `disktype=ssd`. |
| 92 | + |
| 93 | +{{% code_sample file="pods/pod-nginx-preferred-affinity.yaml" %}} |
| 94 | + |
| 95 | +1. Aplique o manifesto para criar um Pod que será alocado no nó escolhido: |
| 96 | + |
| 97 | + ```shell |
| 98 | + kubectl apply -f https://k8s.io/examples/pods/pod-nginx-preferred-affinity.yaml |
| 99 | + ``` |
| 100 | + |
| 101 | +2. Verifique se o Pod está executando no nó escolhido: |
| 102 | + |
| 103 | + ```shell |
| 104 | + kubectl get pods --output=wide |
| 105 | + ``` |
| 106 | + |
| 107 | + A saída é semelhante a esta: |
| 108 | + |
| 109 | + ``` |
| 110 | + NAME READY STATUS RESTARTS AGE IP NODE |
| 111 | + nginx 1/1 Running 0 13s 10.200.0.4 worker0 |
| 112 | + ``` |
| 113 | + |
| 114 | + |
| 115 | + |
| 116 | +## {{% heading "whatsnext" %}} |
| 117 | + |
| 118 | +Saiba mais sobre |
| 119 | +[Afinidade de nó](/docs/concepts/scheduling-eviction/assign-pod-node/#node-affinity). |
0 commit comments