how to refer ReplicaSet in deployment?

6/1/2021

I am new to kubernetes and trying to create a deployment. So first I created a replicaset named rs.yml shown below.

apiVersion: apps/v1 
kind: ReplicaSet 
metadata:    
  name: web   
  labels: 	
    env: dev 	
    role: web 
spec:   
  replicas: 4   
  selector: 	 
    matchLabels:
  	  role: web   
  template: 	
    metadata:
  	  labels:
    	role: web 	
    spec:
  	  containers:
  	    - name: nginx
    	  image: nginx

and applied it using

kubectl apply -f rs.yml

now Instead rewriting all this in deployment. I just want to refer this 'rs.yml' file or service inside my deployment.yml file.

  
-- Krissh
deployment
devops
kubernetes
minikube

1 Answer

6/1/2021

You can create single YAMl file and add both thing deployment service inside it.

apiVersion: apps/v1 
kind: ReplicaSet 
metadata:    
  name: web   
  labels:   
    env: dev    
    role: web 
spec:   
  replicas: 4   
  selector:      
    matchLabels:
      role: web   
  template:     
    metadata:
      labels:
        role: web   
    spec:
      containers:
        - name: nginx
          image: nginx
---
apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  selector:
    app: MyApp
  ports:
    - protocol: TCP
      port: 80
      targetPort: 9376

you can divide the things using the --- make the single YAML file.

also, another suggestion don't use the Replicasets by default Deployment create the Replicaset in the background.

You can use the kind: deployment can check kubectl get rc still replica set will be there. Deployment creates it in the background and manage it.

-- Harsh Manvar
Source: StackOverflow