- 定义pod配置文件pod_nginx.yml,这里以一个nginx为例演示
apiVersion: v1
kind: Pod
metadata:
name: nginx
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
- 创建pod
kubectl create -f pod_nginx.yml
- 查看pod
kubectl get pods
- 查看详情pod信息
kubectl get pods -o wide
- 删除pod
kubectl delete -f pod_nginx.yml
- 进入到nginx容器中,默认进入第一个容器,如果有多个,-c可以指定进入哪个
kubectl exec -it nginx sh
- 容器的详情
kubectl describe pods nginx
- 端口转发,把pod nginx的80端口转发到本地8080
kubectl port-forward nginx 8080:80