쿠버네티스 클러스터 안의 가상 클러스터
kubectl get namespaceskubectl get podskubectl get pods --namespace defaultkubectl get pods --namespace kube-system--namespace == -nkubectl get services -n kube-systmevi production-namespace.yamlapiVersion: v1
kind: Namespace
metadata:
name: production
kubectl apply -f production-namespace.yamlkubectl create namespace mynamespacekubectl get namespacesmynamespace Active 9s
production Active 39s
vi hostname-deploy-svc-ns.yamlapiVersion: 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.yamlkubectl get pods,svc --namespace productionkubectl get pods --all-namespaceskubectl get services --namespace productionNAME 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 -- bashcurl 10.110.139.176:8080curl hostname-svc-clusterip-ns:8080kubectl run -it --rm debug --image=alicek106/ubuntu:curl --restart=Never -- bashcurl hostname-svc-clusterip-ns:8080 # <= X 서비스 이름으로 접근 불가능curl 10.110.139.176:8080[서비스이름].[네임스페이스이름].svc 형태로 사용curl hostname-svc-clusterip-ns.production.svc:8080kubectl delete namespace mynamespacekubectl delete -f production-namespace.yamlkubectl api-resource --namespace=truekubectl api-resources --namespaced=false