Created
August 13, 2020 12:24
-
-
Save leoh0/70b4e27f438c3243c5847e4da56d76a4 to your computer and use it in GitHub Desktop.
Mix two different pods in one deployment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
kubectl apply -f test.yaml | |
kubectl wait --for=condition=available deploy/eggs | |
kubectl wait --for=condition=Ready pod/cuckoo-egg | |
# 적용하고 나면 3개의 pod이 보인다 2개는 알 pod과 1개의 뻐꾸기 알 pod | |
kubectl get pods | |
# 그리고 서비스는 노드포트로 구성되어 있다. | |
kubectl get svc | |
NODEIP=$(kubectl get nodes minikube -o jsonpath='{.status.addresses[?(@.type=="InternalIP")].address}') | |
NODEPORT=$(kubectl get svc eggs -o jsonpath='{.spec.ports[0].nodePort}') | |
# 해당 노드포트로 질의시 알 pod은 egg를 리턴하기 때문에 모든 리퀘스트는 egg를 리턴한다. | |
for i in $(seq 1 10); do | |
curl $NODEIP:$NODEPORT | |
sleep 1 | |
done | |
# 바꿔치기 위한 pod의 정보를 얻어온다. | |
HASH=$(kubectl get pods -l app=echo -o jsonpath='{.items[0].metadata.labels.pod-template-hash}') | |
NAME=$(kubectl get pods -l app=echo -o jsonpath='{.items[0].metadata.name}') | |
# 뻐꾸기 pod을 egg 디플로이먼트에서 인식시키고 이와 동시에 egg 팟 한개를 지운다. | |
kubectl label pods/cuckoo-egg app=echo pod-template-hash=$HASH | |
kubectl delete pods $NAME --force --grace-period=0 | |
kubectl wait --for=condition=available deploy/eggs | |
# egg 팟 한개가 바꿔치기 당했다. | |
kubectl get pods | |
# 질의시 뻐꾸기 알 과 알이 섞여서 나온다. | |
for i in $(seq 1 10); do | |
curl $NODEIP:$NODEPORT | |
sleep 1 | |
done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apiVersion: apps/v1 | |
kind: Deployment | |
metadata: | |
name: eggs | |
labels: | |
app: echo | |
spec: | |
replicas: 2 | |
selector: | |
matchLabels: | |
app: echo | |
template: | |
metadata: | |
labels: | |
app: echo | |
spec: | |
terminationGracePeriodSeconds: 3 | |
containers: | |
- name: echo | |
image: hashicorp/http-echo | |
ports: | |
- containerPort: 5678 | |
args: | |
- "-text=egg" | |
--- | |
apiVersion: v1 | |
kind: Service | |
metadata: | |
name: eggs | |
labels: | |
app: echo | |
spec: | |
type: NodePort | |
ports: | |
- port: 5678 | |
selector: | |
app: echo | |
--- | |
apiVersion: v1 | |
kind: Pod | |
metadata: | |
name: cuckoo-egg | |
namespace: default | |
spec: | |
terminationGracePeriodSeconds: 3 | |
containers: | |
- name: echo | |
image: hashicorp/http-echo | |
ports: | |
- containerPort: 5678 | |
args: | |
- "-text=cuckoo-egg" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment