쿠버네티스 클러스터 안의 가상 클러스터
kubectl get namespaces
kubectl get pods
kubectl get pods --namespace default
kubectl get pods --namespace kube-system
--namespace
== -n
kubectl get services -n kube-systme
vi production-namespace.yaml
apiVersion: v1
kind: Namespace
metadata:
name: production
kubectl apply -f production-namespace.yaml
kubectl create namespace mynamespace
kubectl get namespaces
mynamespace Active 9s
production Active 39s
vi hostname-deploy-svc-ns.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: hostname-deployment-ns
namespace: production
spec:
replicas: 3
selector:
matchLabels:
app: webserver
template:
metadata:
name: my-webserver
labels:
app: webserver
spec:
containers:
- name: my-webserver
image: alicek106/rr-test:echo-hostname
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: hostname-svc-clusterip-ns
namespace: production
spec:
ports:
- name: web-port
port: 8080
targetPort: 80
selector:
app: webserver
type: ClusterIP
kubectl apply -f hostname-deploy-svc-ns.yaml
kubectl get pods,svc --namespace production
kubectl get pods --all-namespaces
kubectl get services --namespace production
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
hostname-svc-clusterip-ns ClusterIP 10.110.139.176 <none> 8080/TCP 3m29s
kubectl run -it --rm debug --image=alicek106/ubuntu:curl --restart=Never --namespace=production -- bash
curl 10.110.139.176:8080
curl hostname-svc-clusterip-ns:8080
kubectl run -it --rm debug --image=alicek106/ubuntu:curl --restart=Never -- bash
curl hostname-svc-clusterip-ns:8080
# <= X 서비스 이름으로 접근 불가능curl 10.110.139.176:8080
[서비스이름].[네임스페이스이름].svc
형태로 사용curl hostname-svc-clusterip-ns.production.svc:8080
kubectl delete namespace mynamespace
kubectl delete -f production-namespace.yaml
kubectl api-resource --namespace=true
kubectl api-resources --namespaced=false