4. Kubernetes: Create and Configure Basic Pods

Опубликовано: 25 Октябрь 2024
на канале: iMustLearn
80
2

** Example:1 **
vi my-first-pod.yaml

apiVersion: v1
kind: Pod
metadata:
name: my-nginx-pod
spec:
containers:
name: my-nginx-container
image: nginx
ports:
containerPort: 80


kubectl create -f my-first-pod.yaml

kubectl get pods

kubectl exec -it my-nginx-pod /bin/bash

** Example:2 **

vi my-busybox.yml

apiVersion: v1
kind: Pod
metadata:
name: my-busybox-pod
spec:
containers:
name: my-busybox-container
image: radial/busyboxplus:curl
args:
sleep
"3600"

kubectl create -f my-busybox.yml

kubectl get pods

kubectl get pods -o wide

kubectl exec my-busybox-pod -- curl [pod ip]

kubectl edit pod my-nginx-pod

kubectl get pods my-nginx-pod -o yaml

kubectl get namespaces

kubectl get pods -n default

kubectl get po -n kube-system

kubectl create ns myns

kubectl get namespaces

** Example:3 - Namespaces**
vi my-ns.yml

apiVersion: v1
kind: Pod
metadata:
name: my-busybox-ns-pod
namespace: myns
labels:
env: dev
spec:
containers:
name: my-busybox-ns-container
image: busybox
command: ['sh', '-c', 'echo "Hello, Kubernetes!" && sleep 3600']

kubectl create -f my-ns.yml

kubectl get pods

kubectl get pods -n myns

kubectl delete pod my-nginx-pod