0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

CKA試験、Service(命令語のみ)

Last updated at Posted at 2023-04-24

Create deployment

kubectl create deployment (deployment name) --image=nginx

ClusterIP

kubectl expose deployment -n (namespace name) (deployments name) --type=ClusterIP --port=80 --target-port=80 --name=(service name)  

NodePort

kubectl expose deployment -n (namespace name) (deployments name) --type=NodePort --port80 --target-port=80 --name=(service name) --dry-run=client -o yaml > testNodePort.yaml
(修正前) testNodePort.yaml
apiVersion: v1
kind: Service
metadata:
  creationTimestamp: null
  labels:
    app: front-end
  name: front-end-nodesvc
spec:
  ports:
  - port: 80
    protocol: TCP
    targetPort: 80
  selector:
    app: front-end
  type: NodePort
status:
  loadBalancer: {}
(修正後) testNodePort.yaml
apiVersion: v1
kind: Service
metadata:
  labels:
    app: front-end
  name: front-end-nodesvc
spec:
  ports:
  - port: 80
    protocol: TCP
    targetPort: 80
    nodePort: 32000
  selector:
    app: front-end
  type: NodePort
(修正後 複数のポートを指定する場合) testNodePort.yaml
apiVersion: v1
kind: Service
metadata:
  labels:
    app: front-end
  name: front-end-nodesvc
spec:
  ports:
  - port: 80
    protocol: TCP
    targetPort: 80
    nodePort: 32000
  - port: 443
    protocol: TCP
    targetPort: 443
    nodePort: 30300
  selector:
    app: front-end
  type: NodePort
kubectl apply -f ./testNodePort.yaml
kubectl get svc

# NAME                TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGE
# front-end-nodesvc   NodePort    10.104.26.176    <none>        80:30200/TCP   5s
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?