consul icon indicating copy to clipboard operation
consul copied to clipboard

consul node can't be deregister

Open whc9527 opened this issue 1 year ago • 0 comments

Consul version: Consul v1.9.0 Consul Cluster Node Total: 2w+ Consul Server Total: 5

8.219.x.x This node is unhealthy on Consul console, and this machine has not been deleted by Consul for several days, then I plan to call consul api to delete it. But the curl command keeps sticking (calling other consul server nodes for deregister operations doesn't stick)

Image

deregister command curl --header X-Consul-Token:2a825e81-b249-433d-a22e-xxxxx --request PUT http://172.31.x.x:8500/v1/agent/service/deregister/tpn,tpn_adx_micro,fk_tpn_adx_micro,8.209.x.x,heartbeat

The node 8.219.x.x is currently registered on the node 172.31.x.x , i login the node 172.31.x.x and use grep command to view some data of 8.219.x.x, and find that 8.219.x.x displays "passing" in consul data, Is this a Bug?

Image

use this code to register to consul cluster

func register(agentConfig config.Config) error {
	consulId := fmt.Sprintf("%s,%s,%s,%s,heartbeat", agentConfig.Tagteam, agentConfig.Taggroup, agentConfig.Tagname, agentConfig.PublicIP)
	registration := new(consulapi.AgentServiceRegistration)
	registration.Name = "hawkeye"
	registration.ID = consulId
	registration.Port = agentConfig.Port
	registration.Address = agentConfig.PublicIP
	registration.Tags = []string{consulId}
	registration.Meta = map[string]string{
		"public_ip": agentConfig.PublicIP,
		"tagteam":   agentConfig.Tagteam,
		"taggroup":  agentConfig.Taggroup,
		"tagname":   agentConfig.Tagname,
	}
	registration.Check = &consulapi.AgentServiceCheck{
		HTTP:                           fmt.Sprintf("http://%s:%d/heartbeat/%s_%s_%s", registration.Address, agentConfig.Port, agentConfig.Tagteam, agentConfig.Taggroup, agentConfig.Tagname),
		Timeout:                        "10s",
		Interval:                       "20s",
		DeregisterCriticalServiceAfter: "10s",
		Status:                         "passing",
	}
	return consul_client.Agent().ServiceRegister(registration)
}

whc9527 avatar Jan 14 '25 09:01 whc9527