---
title: "k8s常用命令"
author: "java_my_life"
date: "2020-09-18T11:15:47Z"
tags: []
categories: ["开源软件"]
slug: "k8s"
draft: false
lastmod: "2021-10-19T17:04:53Z"
id: 2516819
url: "https://java-my-life.iteye.com/blog/2516819"
---

1.服务查询

```
kubectl get pods -o wide |grep xxx
```

   
2.查看服务对应的nodePort端口

```
kubectl get svc -o wide |grep xxx
```

   
3.查看 endpoint 列表

```
kubectl get endpoints | grep xxx
```

   
4.进入容器

```
kubectl exec -it nginx-56b8c64cb4-t97vb -- /bin/bash
```

   
5.查看命名空间

```
kubectl get namespace
```

   
6.查看pods资源使用情况，default为命名空间

```
kubectl top pod -n default
```

   
7.宿主机拷贝文件到pod

```
kubectl cp ./aa.txt default/sip-bpm-6554f88d89-2lt8d:/root
```